From: Serhiy Storchaka Date: Tue, 8 Sep 2015 02:51:00 +0000 (+0300) Subject: Issue #24982: shutil.make_archive() with the "zip" format now adds entries X-Git-Tag: v3.5.1rc1~423 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d941d7a586c8ea2f8253d7b238b3a56522b77a83;p=python Issue #24982: shutil.make_archive() with the "zip" format now adds entries for directories (including empty directories) in ZIP file. Added test for comparing shutil.make_archive() with the "zip" command. --- d941d7a586c8ea2f8253d7b238b3a56522b77a83 diff --cc Lib/shutil.py index a5da58790e,d767a0c945..3f4b6bf663 --- a/Lib/shutil.py +++ b/Lib/shutil.py @@@ -672,17 -670,30 +672,26 @@@ def _make_zipfile(base_name, base_dir, 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: - path = os.path.normpath(base_dir) - zf.write(path, path) - if logger is not None: - logger.info("adding '%s'", path) - for dirpath, dirnames, filenames in os.walk(base_dir): - for name in sorted(dirnames): - path = os.path.normpath(os.path.join(dirpath, name)) + if not dry_run: + with zipfile.ZipFile(zip_filename, "w", + compression=zipfile.ZIP_DEFLATED) as zf: ++ path = os.path.normpath(base_dir) ++ zf.write(path, path) ++ if logger is not None: ++ logger.info("adding '%s'", path) + for dirpath, dirnames, filenames in os.walk(base_dir): ++ for name in sorted(dirnames): ++ path = os.path.normpath(os.path.join(dirpath, name)) ++ zf.write(path, path) ++ if logger is not None: ++ logger.info("adding '%s'", path) + 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) diff --cc Lib/test/test_shutil.py index 869aa2cf93,04738d365b..bb073c9098 --- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@@ -1187,15 -1208,11 +1214,13 @@@ class TestShutil(unittest.TestCase) formats = ['tar', 'gztar', 'zip'] if BZ2_SUPPORTED: formats.append('bztar') + if LZMA_SUPPORTED: + formats.append('xztar') root_dir, base_dir = self._create_files() + expected = rlistdir(root_dir) + expected.remove('outer') for format in formats: - expected = rlistdir(root_dir) - expected.remove('outer') - if format == 'zip': - expected.remove('dist/sub2/') base_name = os.path.join(self.mkdtemp(), 'archive') filename = make_archive(base_name, format, root_dir, base_dir) diff --cc Misc/NEWS index 8b4c8594d7,79faea9710..31acc9fc7a --- a/Misc/NEWS +++ b/Misc/NEWS @@@ -11,15 -10,6 +11,18 @@@ Release date: TB Core and Builtins ----------------- +Library +------- + ++- Issue #24982: shutil.make_archive() with the "zip" format now adds entries ++ for directories (including empty directories) in ZIP file. ++ +- Issue #25019: Fixed a crash caused by setting non-string key of expat parser. + Based on patch by John Leitch. + +- Issue #16180: Exit pdb if file has syntax error, instead of trapping user + in an infinite loop. Patch by Xavier de Gaye. + - Issue #24891: Fix a race condition at Python startup if the file descriptor of stdin (0), stdout (1) or stderr (2) is closed while Python is creating sys.stdin, sys.stdout and sys.stderr objects. These attributes are now set