summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Ward <gward@python.net>2000-04-22 03:09:56 (GMT)
committerGreg Ward <gward@python.net>2000-04-22 03:09:56 (GMT)
commitdb80754abcc49b8331a6da9d30c04dfcde815bc2 (patch)
tree2a3217e7d7b25600cf47d418618cdb703959773e
parent4982f98bc919d2a6377e3e0e82c186bc5b1d70ff (diff)
downloadcpython-db80754abcc49b8331a6da9d30c04dfcde815bc2.zip
cpython-db80754abcc49b8331a6da9d30c04dfcde815bc2.tar.gz
cpython-db80754abcc49b8331a6da9d30c04dfcde815bc2.tar.bz2
Extracted the "what-do-I-do-for-this-format" logic from code in
'make_archive()' to a global static dictionary, ARCHIVE_FORMATS. Added 'check_archive_formats()', which obviously makes good use of this dictionary.
-rw-r--r--Lib/distutils/archive_util.py32
1 files changed, 21 insertions, 11 deletions
diff --git a/Lib/distutils/archive_util.py b/Lib/distutils/archive_util.py
index a28eed1..bae425b 100644
--- a/Lib/distutils/archive_util.py
+++ b/Lib/distutils/archive_util.py
@@ -102,6 +102,20 @@ def make_zipfile (base_name, base_dir, verbose=0, dry_run=0):
# make_zipfile ()
+ARCHIVE_FORMATS = {
+ 'gztar': (make_tarball, [('compress', 'gzip')]),
+ 'ztar': (make_tarball, [('compress', 'compress')]),
+ 'tar': (make_tarball, [('compress', None)]),
+ 'zip': (make_zipfile, [])
+ }
+
+def check_archive_formats (formats):
+ for format in formats:
+ if not ARCHIVE_FORMATS.has_key(format):
+ return format
+ else:
+ return None
+
def make_archive (base_name, format,
root_dir=None, base_dir=None,
verbose=0, dry_run=0):
@@ -130,18 +144,14 @@ def make_archive (base_name, format,
kwargs = { 'verbose': verbose,
'dry_run': dry_run }
- if format == 'gztar':
- func = make_tarball
- kwargs['compress'] = 'gzip'
- elif format == 'ztar':
- func = make_tarball
- kwargs['compress'] = 'compress'
- elif format == 'tar':
- func = make_tarball
- kwargs['compress'] = None
- elif format == 'zip':
- func = make_zipfile
+ try:
+ format_info = ARCHIVE_FORMATS[format]
+ except KeyError:
+ raise ValueError, "unknown archive format '%s'" % format
+ func = format_info[0]
+ for (arg,val) in format_info[1]:
+ kwargs[arg] = val
apply (func, (base_name, base_dir), kwargs)
if root_dir is not None: