[Python-checkins] CVS: distutils/distutils archive_util.py,1.1,1.2
Greg Ward
python-dev@python.org
Fri, 21 Apr 2000 23:10:00 -0400 (EDT)
Update of /projects/cvsroot/distutils/distutils
In directory newcnri:/tmp/cvs-serv24599
Modified Files:
archive_util.py
Log Message:
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.
Index: archive_util.py
===================================================================
RCS file: /projects/cvsroot/distutils/distutils/archive_util.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** archive_util.py 2000/04/04 02:05:59 1.1
--- archive_util.py 2000/04/22 03:09:56 1.2
***************
*** 6,10 ****
# created 2000/04/03, Greg Ward (extracted from util.py)
! __revision__ = "$Id: archive_util.py,v 1.1 2000/04/04 02:05:59 gward Exp $"
import os
--- 6,10 ----
# created 2000/04/03, Greg Ward (extracted from util.py)
! __revision__ = "$Id: archive_util.py,v 1.2 2000/04/22 03:09:56 gward Exp $"
import os
***************
*** 103,106 ****
--- 103,120 ----
+ 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,
***************
*** 131,146 ****
'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
!
apply (func, (base_name, base_dir), kwargs)
--- 145,156 ----
'dry_run': dry_run }
! 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)