mirror of
https://github.com/python/cpython.git
synced 2025-07-24 19:54:21 +00:00
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.
This commit is contained in:
parent
4982f98bc9
commit
db80754abc
1 changed files with 21 additions and 11 deletions
|
@ -102,6 +102,20 @@ def make_zipfile (base_name, base_dir, verbose=0, dry_run=0):
|
||||||
# make_zipfile ()
|
# 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,
|
def make_archive (base_name, format,
|
||||||
root_dir=None, base_dir=None,
|
root_dir=None, base_dir=None,
|
||||||
verbose=0, dry_run=0):
|
verbose=0, dry_run=0):
|
||||||
|
@ -130,18 +144,14 @@ def make_archive (base_name, format,
|
||||||
kwargs = { 'verbose': verbose,
|
kwargs = { 'verbose': verbose,
|
||||||
'dry_run': dry_run }
|
'dry_run': dry_run }
|
||||||
|
|
||||||
if format == 'gztar':
|
try:
|
||||||
func = make_tarball
|
format_info = ARCHIVE_FORMATS[format]
|
||||||
kwargs['compress'] = 'gzip'
|
except KeyError:
|
||||||
elif format == 'ztar':
|
raise ValueError, "unknown archive format '%s'" % format
|
||||||
func = make_tarball
|
|
||||||
kwargs['compress'] = 'compress'
|
|
||||||
elif format == 'tar':
|
|
||||||
func = make_tarball
|
|
||||||
kwargs['compress'] = None
|
|
||||||
elif format == 'zip':
|
|
||||||
func = make_zipfile
|
|
||||||
|
|
||||||
|
func = format_info[0]
|
||||||
|
for (arg,val) in format_info[1]:
|
||||||
|
kwargs[arg] = val
|
||||||
apply (func, (base_name, base_dir), kwargs)
|
apply (func, (base_name, base_dir), kwargs)
|
||||||
|
|
||||||
if root_dir is not None:
|
if root_dir is not None:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue