MCPcopy Index your code
hub / github.com/RustPython/RustPython / make_archive

Function make_archive

Lib/shutil.py:1184–1245  ·  view source on GitHub ↗

Create an archive file (eg. zip or tar). 'base_name' is the name of the file to create, minus any format-specific extension; 'format' is the archive format: one of "zip", "tar", "gztar", "bztar", "xztar", or "zstdtar". Or any other registered format. 'root_dir' is a directory that

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

Source from the content-addressed store, hash-verified

1182 del _ARCHIVE_FORMATS[name]
1183
1184def make_archive(base_name, format, root_dir=None, base_dir=None, verbose=0,
1185 dry_run=0, owner=None, group=None, logger=None):
1186 """Create an archive file (eg. zip or tar).
1187
1188 'base_name' is the name of the file to create, minus any format-specific
1189 extension; 'format' is the archive format: one of "zip", "tar", "gztar",
1190 "bztar", "xztar", or "zstdtar". Or any other registered format.
1191
1192 'root_dir' is a directory that will be the root directory of the
1193 archive; ie. we typically chdir into 'root_dir' before creating the
1194 archive. 'base_dir' is the directory where we start archiving from;
1195 ie. 'base_dir' will be the common prefix of all files and
1196 directories in the archive. 'root_dir' and 'base_dir' both default
1197 to the current directory. Returns the name of the archive file.
1198
1199 'owner' and 'group' are used when creating a tar archive. By default,
1200 uses the current owner and group.
1201 """
1202 sys.audit("shutil.make_archive", base_name, format, root_dir, base_dir)
1203 try:
1204 format_info = _ARCHIVE_FORMATS[format]
1205 except KeyError:
1206 raise ValueError("unknown archive format '%s'" % format) from None
1207
1208 kwargs = {'dry_run': dry_run, 'logger': logger,
1209 'owner': owner, 'group': group}
1210
1211 func = format_info[0]
1212 for arg, val in format_info[1]:
1213 kwargs[arg] = val
1214
1215 if base_dir is None:
1216 base_dir = os.curdir
1217
1218 supports_root_dir = getattr(func, 'supports_root_dir', False)
1219 save_cwd = None
1220 if root_dir is not None:
1221 stmd = os.stat(root_dir).st_mode
1222 if not stat.S_ISDIR(stmd):
1223 raise NotADirectoryError(errno.ENOTDIR, 'Not a directory', root_dir)
1224
1225 if supports_root_dir:
1226 # Support path-like base_name here for backwards-compatibility.
1227 base_name = os.fspath(base_name)
1228 kwargs['root_dir'] = root_dir
1229 else:
1230 save_cwd = os.getcwd()
1231 if logger is not None:
1232 logger.debug("changing into '%s'", root_dir)
1233 base_name = os.path.abspath(base_name)
1234 if not dry_run:
1235 os.chdir(root_dir)
1236
1237 try:
1238 filename = func(base_name, base_dir, **kwargs)
1239 finally:
1240 if save_cwd is not None:
1241 if logger is not None:

Calls 4

getattrFunction · 0.85
funcFunction · 0.50
statMethod · 0.45
debugMethod · 0.45