From 9275d6ca473d62f913a9f35c58d5ce34b298641f Mon Sep 17 00:00:00 2001 From: Bastian Kleineidam Date: Tue, 23 Feb 2010 07:32:45 +0100 Subject: [PATCH] Ensure archive program supports a given encoding before trying to handle archive commands. --- doc/todo.txt | 2 -- patoolib/__init__.py | 10 ++++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/doc/todo.txt b/doc/todo.txt index aae296a..e69de29 100644 --- a/doc/todo.txt +++ b/doc/todo.txt @@ -1,2 +0,0 @@ -- Check and list the supported encoding options for tar files - in the "formats" command. diff --git a/patoolib/__init__.py b/patoolib/__init__.py index de18a52..2ec56ef 100644 --- a/patoolib/__init__.py +++ b/patoolib/__init__.py @@ -216,9 +216,11 @@ def list_formats (): return 0 -def parse_config (format, command, **kwargs): +def parse_config (format, encoding, 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 encoding + is not supported. """ config = { 'verbose': False, @@ -236,6 +238,10 @@ def parse_config (format, command, **kwargs): for key, value in kwargs.items(): if value is not None: config[key] = value + if encoding: + program = os.path.basename(config['program']) + if program in ('tar', 'star') and not find_executable(encoding): + raise util.PatoolError("cannot %s archive because program `%s' was not found" % (command, encoding)) return config @@ -308,7 +314,7 @@ def _handle_archive (archive, command, *args, **kwargs): format, encoding = get_archive_format(archive) check_archive_format(format, encoding) check_archive_command(command) - config = parse_config(format, command, **kwargs) + config = parse_config(format, encoding, command, **kwargs) if command == 'create': # check if archive already exists if os.path.exists(archive) and not config['force']: