cpython: eb02db65e148 (original) (raw)

Mercurial > cpython

changeset 105677:eb02db65e148 2.7

Issue #14061: Misc fixes and cleanups in archiving code in shutil. Improved the documentation and tests for make_archive(). Improved error handling when corresponding compress module is not available. External zip executable is now used if the zlib module is not available. [#14061]

Serhiy Storchaka storchaka@gmail.com
date Fri, 16 Dec 2016 19:04:17 +0200
parents eb830f1511ef
children 6daa88e02392 287d4290b1b4
files Doc/library/shutil.rst Lib/shutil.py Lib/test/test_shutil.py
diffstat 3 files changed, 49 insertions(+), 23 deletions(-)[+] [-] Doc/library/shutil.rst 13 Lib/shutil.py 54 Lib/test/test_shutil.py 5

line wrap: on

line diff

--- a/Doc/library/shutil.rst +++ b/Doc/library/shutil.rst @@ -267,7 +267,9 @@ provided. They rely on the :mod:`zipfil base_name is the name of the file to create, including the path, minus any format-specific extension. format is the archive format: one of

--- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -13,6 +13,20 @@ import collections import errno try:

+except ImportError:

+ +try:

+except ImportError:

+ +try: from pwd import getpwnam except ImportError: getpwnam = None @@ -351,15 +365,18 @@ def _make_tarball(base_name, base_dir, c Returns the output filename. """

-

if not dry_run:

@@ -435,6 +452,7 @@ def _make_zipfile(base_name, base_dir, v # If zipfile module is not available, try spawning an external 'zip' # command. try:

@@ -470,11 +488,17 @@ def _make_zipfile(base_name, base_dir, v return zip_filename _ARCHIVE_FORMATS = {

+} + +if _ZLIB_SUPPORTED:

+ +if _BZ2_SUPPORTED:

def get_archive_formats(): """Returns a list of supported formats for archiving and unarchiving. @@ -515,8 +539,8 @@ def make_archive(base_name, format, root """Create an archive file (eg. zip or tar). 'base_name' is the name of the file to create, minus any format-specific

'root_dir' is a directory that will be the root directory of the archive; ie. we typically chdir into 'root_dir' before creating the

--- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -35,6 +35,7 @@ except ImportError: try: import zipfile

@@ -485,6 +485,7 @@ class TestShutil(unittest.TestCase): ['dist/', 'dist/file1', 'dist/file2', 'dist/sub/', 'dist/sub/file3', 'dist/sub2/', 'outer'])

with support.change_cwd(work_dir): base_name = os.path.abspath(rel_base_name) @@ -498,7 +499,6 @@ class TestShutil(unittest.TestCase): ['dist/', 'dist/file1', 'dist/file2', 'dist/sub/', 'dist/sub/file3', 'dist/sub2/'])

@@ -524,7 +524,6 @@ class TestShutil(unittest.TestCase): names2 = zf.namelist() self.assertEqual(sorted(names), sorted(names2))