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