示例#1
0
文件: utils.py 项目: zhouhui321/lpts
def cat_file_to_cmd(file, command, ignore_status=False, return_output=False):
    """
    equivalent to 'cat file | command' but knows to use
    zcat or bzcat if appropriate
    """
    if not os.path.isfile(file):
        raise NameError("invalid file %s to cat to command %s" % (file, command))

    if return_output:
        run_cmd_to = system_output
    else:
        run_cmd_to = system

    if magic.guess_type(file) == "application/x-bzip2":
        cat = "bzcat"
    elif magic.guess_type(file) == "application/x-gzip":
        cat = "zcat"
    else:
        cat = "cat"
    return run_cmd_to("%s %s | %s" % (cat, file, command), ignore_status=ignore_status)
示例#2
0
文件: utils.py 项目: zhyh329/lpts
def cat_file_to_cmd(file, command, ignore_status=False, return_output=False):
    """
    equivalent to 'cat file | command' but knows to use
    zcat or bzcat if appropriate
    """
    if not os.path.isfile(file):
        raise NameError('invalid file %s to cat to command %s'
                        % (file, command))

    if return_output:
        run_cmd_to = system_output
    else:
        run_cmd_to = system

    if magic.guess_type(file) == 'application/x-bzip2':
        cat = 'bzcat'
    elif magic.guess_type(file) == 'application/x-gzip':
        cat = 'zcat'
    else:
        cat = 'cat'
    return run_cmd_to('%s %s | %s' % (cat, file, command), ignore_status=ignore_status)
def guess(path):
    fp = file(path,'rb')
    try:
        return magic.guess_type(fp.read(256))
    finally:
        fp.close()
 def test_partial_mask_match1(self):
     self.assertEqual(magic.guess_type('\x00123456789'), None)
 def test_partial_mask_match0(self):
     self.assertEqual(magic.guess_type('\x00'), None)
 def test_empty_file(self):
     self.assertEqual(magic.guess_type(''), None)