MCPcopy Index your code
hub / github.com/python/cpython / _make_zipfile

Function _make_zipfile

Lib/shutil.py:1064–1119  ·  view source on GitHub ↗

Create a zip file from all the files under 'base_dir'. The output zip file will be named 'base_name' + ".zip". Returns the name of the output zip file.

(base_name, base_dir, verbose=0, dry_run=0,
                  logger=None, owner=None, group=None, root_dir=None)

Source from the content-addressed store, hash-verified

1062 return archive_name
1063
1064def _make_zipfile(base_name, base_dir, verbose=0, dry_run=0,
1065 logger=None, owner=None, group=None, root_dir=None):
1066 """Create a zip file from all the files under 'base_dir'.
1067
1068 The output zip file will be named 'base_name' + ".zip". Returns the
1069 name of the output zip file.
1070 """
1071 import zipfile # late import for breaking circular dependency
1072
1073 zip_filename = base_name + ".zip"
1074 archive_dir = os.path.dirname(base_name)
1075
1076 if archive_dir and not os.path.exists(archive_dir):
1077 if logger is not None:
1078 logger.info("creating %s", archive_dir)
1079 if not dry_run:
1080 os.makedirs(archive_dir)
1081
1082 if logger is not None:
1083 logger.info("creating '%s' and adding '%s' to it",
1084 zip_filename, base_dir)
1085
1086 if not dry_run:
1087 with zipfile.ZipFile(zip_filename, "w",
1088 compression=zipfile.ZIP_DEFLATED) as zf:
1089 arcname = os.path.normpath(base_dir)
1090 if root_dir is not None:
1091 base_dir = os.path.join(root_dir, base_dir)
1092 base_dir = os.path.normpath(base_dir)
1093 if arcname != os.curdir:
1094 zf.write(base_dir, arcname)
1095 if logger is not None:
1096 logger.info("adding '%s'", base_dir)
1097 for dirpath, dirnames, filenames in os.walk(base_dir):
1098 arcdirpath = dirpath
1099 if root_dir is not None:
1100 arcdirpath = os.path.relpath(arcdirpath, root_dir)
1101 arcdirpath = os.path.normpath(arcdirpath)
1102 for name in sorted(dirnames):
1103 path = os.path.join(dirpath, name)
1104 arcname = os.path.join(arcdirpath, name)
1105 zf.write(path, arcname)
1106 if logger is not None:
1107 logger.info("adding '%s'", path)
1108 for name in filenames:
1109 path = os.path.join(dirpath, name)
1110 path = os.path.normpath(path)
1111 if os.path.isfile(path):
1112 arcname = os.path.join(arcdirpath, name)
1113 zf.write(path, arcname)
1114 if logger is not None:
1115 logger.info("adding '%s'", path)
1116
1117 if root_dir is not None:
1118 zip_filename = os.path.abspath(zip_filename)
1119 return zip_filename
1120
1121_make_tarball.supports_root_dir = True

Callers

nothing calls this directly

Calls 8

dirnameMethod · 0.45
existsMethod · 0.45
infoMethod · 0.45
joinMethod · 0.45
writeMethod · 0.45
walkMethod · 0.45
isfileMethod · 0.45
abspathMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…