예제 #1
0
파일: __init__.py 프로젝트: shlomif/patool
def list_formats ():
    """Print information about available archive formats to stdout."""
    for format in ArchiveFormats:
        print format, "files:"
        for command in ArchiveCommands:
            programs = ArchivePrograms[format]
            if command not in programs and None not in programs:
                print "   %8s: - (not supported)" % command
                continue
            try:
                program = find_archive_program(format, command)
                print "   %8s: %s" % (command, program),
                if format == 'tar':
                    encs = [x for x in ArchiveCompressions if util.find_program(x)]
                    if encs:
                        print "(supported compressions: %s)" % ", ".join(encs),
                elif format == '7z':
                    if util.p7zip_supports_rar():
                        print "(rar archives supported)",
                    else:
                        print "(rar archives not supported)",
                print
            except util.PatoolError:
                handlers = programs.get(None, programs.get(command))
                print "   %8s: - (no program found; install %s)" % \
                      (command, util.strlist_with_or(handlers))
    return 0
예제 #2
0
 def _check_program(self, format):
     '''
     Returns whether program to archive / unarchive exists
     '''
     self.logger_obj.info("Check if program exists for : {}".format(format))
     if util.find_program(format) is None:
         self.logger_obj.info("Unable to find relative programe")
         return False
     return True
예제 #3
0
파일: __init__.py 프로젝트: shlomif/patool
def find_compression_program (program, compression):
    """Find suitable compression program and return it. Returns None if
    no compression program could be found"""
    if program in ('tar', 'star'):
        for enc_program in CompressionPrograms[compression]:
            found = util.find_program(enc_program)
            if found:
                return found
    elif program == 'py_tarfile':
        return compression in ('gzip', 'bzip2')
    return None
예제 #4
0
파일: rpm2cpio.py 프로젝트: shlomif/patool
def extract_rpm (archive, compression, cmd, **kwargs):
    """Extract a RPM archive."""
    # also check cpio
    cpio = util.find_program("cpio")
    if not cpio:
        raise util.PatoolError("cpio(1) is required for rpm2cpio extraction; please install it")
    path = util.shell_quote(os.path.abspath(archive))
    cmdlist = [util.shell_quote(cmd), path, "|", util.shell_quote(cpio),
        '--extract', '--make-directories', '--preserve-modification-time',
        '--no-absolute-filenames', '--force-local', '--nonmatching',
        r'"*\.\.*"']
    if kwargs['verbose']:
        cmdlist.append('-v')
    return (cmdlist, {'cwd': kwargs['outdir'], 'shell': True})
예제 #5
0
파일: __init__.py 프로젝트: shlomif/patool
def _diff_archives (archive1, archive2, **kwargs):
    """Show differences between two archives."""
    if util.is_same_file(archive1, archive2):
        msg = "no differences found: archive `%s' and `%s' are the same files"
        print msg % (archive1, archive2)
        return 0
    diff = util.find_program("diff")
    if not diff:
        msg = "The diff(1) program is required for showing archive differences, please install it."
        raise util.PatoolError(msg)
    tmpdir1 = util.tmpdir()
    try:
        path1 = _handle_archive(archive1, 'extract', outdir=tmpdir1, **kwargs)
        tmpdir2 = util.tmpdir()
        try:
            path2 = _handle_archive(archive2, 'extract', outdir=tmpdir2, **kwargs)
            return util.run([diff, "-urN", path1, path2])
        finally:
            shutil.rmtree(tmpdir2, onerror=rmtree_log_error)
    finally:
        shutil.rmtree(tmpdir1, onerror=rmtree_log_error)
예제 #6
0
파일: __init__.py 프로젝트: shlomif/patool
def find_archive_program (format, command):
    """Find suitable archive program for given format and mode."""
    commands = ArchivePrograms[format]
    programs = []
    # first try the universal programs with key None
    for key in (None, command):
        if key in commands:
            programs.extend(commands[key])
    if not programs:
        raise util.PatoolError("%s archive format `%s' is not supported" % (command, format))
    # return the first existing program
    for program in programs:
        if program.startswith('py_'):
            # it's a Python module and therefore always supported
            return program
        exe = util.find_program(program)
        if exe:
            if program == '7z' and format == 'rar' and not util.p7zip_supports_rar():
                continue
            return exe
    # no programs found
    raise util.PatoolError("could not find an executable program to %s format %s; candidates are (%s)," % (command, format, ",".join(programs)))
예제 #7
0
파일: __init__.py 프로젝트: shlomif/patool
def parse_config (archive, format, compression, command, **kwargs):
    """The configuration determines which program to use for which
    archive format for the given command.
    @raises: PatoolError if command for given format and compression
       is not supported.
    """
    config = {
        'verbose': False,
    }
    config['program'] = find_archive_program(format, command)
    for key, value in kwargs.items():
        if value is not None:
            if key == 'program':
                program = util.find_program(value)
                if program:
                    value = program
            config[key] = value
    program = os.path.basename(config['program'])
    if compression and not find_compression_program(program, compression):
        msg = "cannot %s archive `%s': compression `%s' not supported by %s" % \
              (command, archive, compression, program)
        raise util.PatoolError(msg)
    return config