Unpack an archive. `filename` is the name of the archive. `extract_dir` is the name of the target directory, where the archive is unpacked. If not provided, the current working directory is used. `format` is the archive format: one of "zip", "tar", "gztar", "bztar", "xztar", o
(filename, extract_dir=None, format=None, *, filter=None)
| 1384 | return None |
| 1385 | |
| 1386 | def unpack_archive(filename, extract_dir=None, format=None, *, filter=None): |
| 1387 | """Unpack an archive. |
| 1388 | |
| 1389 | `filename` is the name of the archive. |
| 1390 | |
| 1391 | `extract_dir` is the name of the target directory, where the archive |
| 1392 | is unpacked. If not provided, the current working directory is used. |
| 1393 | |
| 1394 | `format` is the archive format: one of "zip", "tar", "gztar", "bztar", |
| 1395 | "xztar", or "zstdtar". Or any other registered format. If not provided, |
| 1396 | unpack_archive will use the filename extension and see if an unpacker |
| 1397 | was registered for that extension. |
| 1398 | |
| 1399 | In case none is found, a ValueError is raised. |
| 1400 | |
| 1401 | If `filter` is given, it is passed to the underlying |
| 1402 | extraction function. |
| 1403 | """ |
| 1404 | sys.audit("shutil.unpack_archive", filename, extract_dir, format) |
| 1405 | |
| 1406 | if extract_dir is None: |
| 1407 | extract_dir = os.getcwd() |
| 1408 | |
| 1409 | extract_dir = os.fspath(extract_dir) |
| 1410 | filename = os.fspath(filename) |
| 1411 | |
| 1412 | if filter is None: |
| 1413 | filter_kwargs = {} |
| 1414 | else: |
| 1415 | filter_kwargs = {'filter': filter} |
| 1416 | if format is not None: |
| 1417 | try: |
| 1418 | format_info = _UNPACK_FORMATS[format] |
| 1419 | except KeyError: |
| 1420 | raise ValueError("Unknown unpack format '{0}'".format(format)) from None |
| 1421 | |
| 1422 | func = format_info[1] |
| 1423 | func(filename, extract_dir, **dict(format_info[2]), **filter_kwargs) |
| 1424 | else: |
| 1425 | # we need to look at the registered unpackers supported extensions |
| 1426 | format = _find_unpack_format(filename) |
| 1427 | if format is None: |
| 1428 | raise ReadError("Unknown archive format '{0}'".format(filename)) |
| 1429 | |
| 1430 | func = _UNPACK_FORMATS[format][1] |
| 1431 | kwargs = dict(_UNPACK_FORMATS[format][2]) | filter_kwargs |
| 1432 | func(filename, extract_dir, **kwargs) |
| 1433 | |
| 1434 | |
| 1435 | if hasattr(os, 'statvfs'): |