Add ability to pass format and encoding as arguments to the archive handler function.

This commit is contained in:
Bastian Kleineidam 2010-03-03 17:35:17 +01:00
parent 92eb057bcd
commit 8f33b01cbf
1 changed files with 16 additions and 3 deletions

View File

@ -243,6 +243,17 @@ def list_formats ():
return 0 return 0
AllowedConfigKeys = ("verbose", "force", "program")
def clean_config_keys (kwargs):
"""Remove invalid configuration keys from arguments."""
config_kwargs = dict(kwargs)
for key in kwargs:
if key not in AllowedConfigKeys:
del config_kwargs[key]
return config_kwargs
def parse_config (archive, format, encoding, command, **kwargs): def parse_config (archive, format, encoding, command, **kwargs):
"""The configuration determines which program to use for which """The configuration determines which program to use for which
archive format for the given command. archive format for the given command.
@ -341,11 +352,13 @@ def _handle_archive (archive, command, *args, **kwargs):
if command != 'create': if command != 'create':
# check that archive is a regular file # check that archive is a regular file
util.check_filename(archive) util.check_filename(archive)
encoding = None format, encoding = kwargs.get("format"), kwargs.get("encoding")
format, encoding = get_archive_format(archive) if format is None:
format, encoding = get_archive_format(archive)
check_archive_format(format, encoding) check_archive_format(format, encoding)
check_archive_command(command) check_archive_command(command)
config = parse_config(archive, format, encoding, command, **kwargs) config_kwargs = clean_config_keys(kwargs)
config = parse_config(archive, format, encoding, command, **config_kwargs)
if command == 'create': if command == 'create':
# check if archive already exists # check if archive already exists
if os.path.exists(archive) and not config['force']: if os.path.exists(archive) and not config['force']: