summaryrefslogtreecommitdiffstats
path: root/Lib/shutil.py
diff options
context:
space:
mode:
authorAndrew Kuchling <amk@amk.ca>2014-03-20 20:11:16 (GMT)
committerAndrew Kuchling <amk@amk.ca>2014-03-20 20:11:16 (GMT)
commita0934b2c1b939fdebee8dc18d49a0f6c52324773 (patch)
tree284f4f468757f082bc5f809ad52c8064728f434f /Lib/shutil.py
parent8efe3df6642a1d29c6e8bafe18c038ed64b398c3 (diff)
downloadcpython-a0934b2c1b939fdebee8dc18d49a0f6c52324773.zip
cpython-a0934b2c1b939fdebee8dc18d49a0f6c52324773.tar.gz
cpython-a0934b2c1b939fdebee8dc18d49a0f6c52324773.tar.bz2
#20744: don't try running an external 'zip' in shutil.make_archive()
Instead we'll just use the stdlib zipfile module. Patch by Derek Chiang
Diffstat (limited to 'Lib/shutil.py')
-rw-r--r--Lib/shutil.py55
1 files changed, 15 insertions, 40 deletions
diff --git a/Lib/shutil.py b/Lib/shutil.py
index 0cd6ec4..508a368 100644
--- a/Lib/shutil.py
+++ b/Lib/shutil.py
@@ -630,23 +630,6 @@ def _make_tarball(base_name, base_dir, compress="gzip", verbose=0, dry_run=0,
return archive_name
-def _call_external_zip(base_dir, zip_filename, verbose=False, dry_run=False):
- # XXX see if we want to keep an external call here
- if verbose:
- zipoptions = "-r"
- else:
- zipoptions = "-rq"
- from distutils.errors import DistutilsExecError
- from distutils.spawn import spawn
- try:
- spawn(["zip", zipoptions, zip_filename, base_dir], dry_run=dry_run)
- except DistutilsExecError:
- # XXX really should distinguish between "couldn't find
- # external 'zip' command" and "zip failed".
- raise ExecError("unable to create zip file '%s': "
- "could neither import the 'zipfile' module nor "
- "find a standalone zip utility") % zip_filename
-
def _make_zipfile(base_name, base_dir, verbose=0, dry_run=0, logger=None):
"""Create a zip file from all the files under 'base_dir'.
@@ -656,6 +639,8 @@ def _make_zipfile(base_name, base_dir, verbose=0, dry_run=0, logger=None):
available, raises ExecError. Returns the name of the output zip
file.
"""
+ import zipfile
+
zip_filename = base_name + ".zip"
archive_dir = os.path.dirname(base_name)
@@ -665,30 +650,20 @@ def _make_zipfile(base_name, base_dir, verbose=0, dry_run=0, logger=None):
if not dry_run:
os.makedirs(archive_dir)
- # If zipfile module is not available, try spawning an external 'zip'
- # command.
- try:
- import zipfile
- except ImportError:
- zipfile = None
-
- if zipfile is None:
- _call_external_zip(base_dir, zip_filename, verbose, dry_run)
- else:
- if logger is not None:
- logger.info("creating '%s' and adding '%s' to it",
- zip_filename, base_dir)
+ if logger is not None:
+ logger.info("creating '%s' and adding '%s' to it",
+ zip_filename, base_dir)
- if not dry_run:
- with zipfile.ZipFile(zip_filename, "w",
- compression=zipfile.ZIP_DEFLATED) as zf:
- for dirpath, dirnames, filenames in os.walk(base_dir):
- for name in filenames:
- path = os.path.normpath(os.path.join(dirpath, name))
- if os.path.isfile(path):
- zf.write(path, path)
- if logger is not None:
- logger.info("adding '%s'", path)
+ if not dry_run:
+ with zipfile.ZipFile(zip_filename, "w",
+ compression=zipfile.ZIP_DEFLATED) as zf:
+ for dirpath, dirnames, filenames in os.walk(base_dir):
+ for name in filenames:
+ path = os.path.normpath(os.path.join(dirpath, name))
+ if os.path.isfile(path):
+ zf.write(path, path)
+ if logger is not None:
+ logger.info("adding '%s'", path)
return zip_filename