On Sat, 2010-03-27 at 10:34 +0800, Amos Kong wrote:
> On Fri, Mar 26, 2010 at 12:59:02PM -0300, Lucas Meneghel Rodrigues wrote:
> > On Fri, Mar 26, 2010 at 10:18 AM, Jean Parpaillon
> > <[email protected]> wrote:
> > > ?Add a function to get file mimetype
> > > ?Use mimetype to check if a file is to be cat|zcat|bzcat (instead of 
> > > suffix)
> > 
> > Actually, we could use the standard lib module mimetypes to do this
> > task. the patch could be rewritten as:
> > 
> > -    if file.endswith('.bz2'):
> > +    if mimetypes.guess_type(file) == ('application/x-tar', 'bzip2'):
> >         cat = 'bzcat'
> > -    elif (file.endswith('.gz') or file.endswith('.tgz')):
> > +    if mimetypes.guess_type(file) == ('application/x-tar', 'gzip'):
> 
>        elif mimetypes.guess_type(file) == ('application/x-tar', 'gzip'):
> 
> hello lucas, it should be 'elif'. Otherwise, when file mime-type is bzip2, 
> the below 'else' block will also execute.
> I'll send this patch by another mail.

Yes, I just made some crude editing to explain the idea :) Thanks for
the updated patch!

> 
> >         cat = 'zcat'
> >     else:
> >         cat = 'cat'
> > 
> > Provided the mimetypes module is also imported. Since the module
> > interacts with libmagic and the mimetypes database files directly,
> > it's a better solution.


_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to