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
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)))