--- archive_util.orig.py Thu Dec 6 14:51:36 2001 +++ archive_util.py Fri Nov 15 14:24:03 2002 @@ -58,53 +58,54 @@ def make_zipfile (base_name, base_dir, verbose=0, dry_run=0): """Create a zip file from all the files under 'base_dir'. The output - zip file will be named 'base_dir' + ".zip". Uses either the InfoZIP - "zip" utility (if installed and found on the default search path) or - the "zipfile" Python module (if available). If neither tool is - available, raises DistutilsExecError. Returns the name of the output - zip file. + zip file will be named 'base_dir' + ".zip". Uses either the "zipfile" + Python module (if available) or the InfoZIP "zip" utility (if installed + and found on the default search path). If neither tool is available, + raises DistutilsExecError. Returns the name of the output zip file. """ - # This initially assumed the Unix 'zip' utility -- but - # apparently InfoZIP's zip.exe works the same under Windows, so - # no changes needed! zip_filename = base_name + ".zip" mkpath(os.path.dirname(zip_filename), verbose=verbose, dry_run=dry_run) - try: - spawn(["zip", "-rq", zip_filename, base_dir], - verbose=verbose, dry_run=dry_run) - except DistutilsExecError: - - # XXX really should distinguish between "couldn't find - # external 'zip' command" and "zip failed" -- shouldn't try - # again in the latter case. (I think fixing this will - # require some cooperation from the spawn module -- perhaps - # a utility function to search the path, so we can fallback - # on zipfile.py without the failed spawn.) - try: - import zipfile - except ImportError: - raise DistutilsExecError, \ - ("unable to create zip file '%s': " + - "could neither find a standalone zip utility nor " + - "import the 'zipfile' module") % zip_filename + # Try to use zipfile.py module first... Failing that, then try + # spawning an external 'zip' command. + + try: + import zipfile if verbose: print "creating '%s' and adding '%s' to it" % \ (zip_filename, base_dir) - def visit (z, dirname, names): + def visit (tup, dirname, names): + z = tup[0] + verbose = tup[1] for name in names: path = os.path.normpath(os.path.join(dirname, name)) if os.path.isfile(path): z.write(path, path) + if verbose: + print "adding '%s'" % path if not dry_run: z = zipfile.ZipFile(zip_filename, "w", compression=zipfile.ZIP_DEFLATED) - os.path.walk(base_dir, visit, z) + os.path.walk(base_dir, visit, (z, verbose)) z.close() + except ImportError: + try: + if verbose: + zipoptions = "-r" + else: + zipoptions = "-rq" + spawn(["zip", zipoptions, zip_filename, base_dir], + verbose=verbose, dry_run=dry_run) + except DistutilsExecError: + + raise DistutilsExecError, \ + ("unable to create zip file '%s': " + + "could neither import the 'zipfile' module nor " + + "find a standalone zip utility") % zip_filename return zip_filename