Commit 091d386f authored by Benjamin Peterson's avatar Benjamin Peterson

use with statement to ensure zipfile is always closed (closes #20102)

parent c8d9e0e9
...@@ -680,17 +680,15 @@ def _make_zipfile(base_name, base_dir, verbose=0, dry_run=0, logger=None): ...@@ -680,17 +680,15 @@ def _make_zipfile(base_name, base_dir, verbose=0, dry_run=0, logger=None):
zip_filename, base_dir) zip_filename, base_dir)
if not dry_run: if not dry_run:
zip = zipfile.ZipFile(zip_filename, "w", with zipfile.ZipFile(zip_filename, "w",
compression=zipfile.ZIP_DEFLATED) compression=zipfile.ZIP_DEFLATED) as zf:
for dirpath, dirnames, filenames in os.walk(base_dir):
for dirpath, dirnames, filenames in os.walk(base_dir): for name in filenames:
for name in filenames: path = os.path.normpath(os.path.join(dirpath, name))
path = os.path.normpath(os.path.join(dirpath, name)) if os.path.isfile(path):
if os.path.isfile(path): zf.write(path, path)
zip.write(path, path) if logger is not None:
if logger is not None: logger.info("adding '%s'", path)
logger.info("adding '%s'", path)
zip.close()
return zip_filename return zip_filename
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment