On Fri, Mar 26, 2010 at 02:18:08PM +0100, Jean Parpaillon wrote:
> Add a function to get file mimetype
> Use mimetype to check if a file is to be cat|zcat|bzcat (instead of suffix)
>
> ---
> client/bin/base_utils.py | 4 ++--
> client/common_lib/utils.py | 6 ++++++
> 2 files changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/client/bin/base_utils.py b/client/bin/base_utils.py
> index b4f5646..0a96efb 100644
> --- a/client/bin/base_utils.py
> +++ b/client/bin/base_utils.py
> @@ -47,9 +47,9 @@ def cat_file_to_cmd(file, command, ignore_status=0,
> return_output=False):
> else:
> run_cmd = utils.system
>
> - if file.endswith('.bz2'):
> + if utils.get_file_mime(file) == 'application/x-bzip2':
> cat = 'bzcat'
> - elif (file.endswith('.gz') or file.endswith('.tgz')):
> + elif utils.get_file_mime(file) == 'application/x-gzip':
> cat = 'zcat'
> else:
> cat = 'cat'
> diff --git a/client/common_lib/utils.py b/client/common_lib/utils.py
> index ddbb34b..7d5413f 100644
> --- a/client/common_lib/utils.py
> +++ b/client/common_lib/utils.py
> @@ -1191,3 +1191,9 @@ def sh_escape(command):
> command = command.replace('"', r'\"')
> command = command.replace('`', r'\`')
> return command
> +
> +
> +def get_file_mime(path):
> + """ Return path mime type
> + """
> + return system_output("file --mime --brief %s" % path).strip()
return system_output("file --mime-type --brief %s" % path).strip()
It should be '--mime-type'
# file --mime --brief a.tar
application/x-tar; charset=binary
# file --mime-type --brief a.tar
application/x-tar
Amos
> --
> 1.7.0
>
> _______________________________________________
> Autotest mailing list
> [email protected]
> http://test.kernel.org/cgi-bin/mailman/listinfo/autotest
_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest