14
14
import os
15
15
import pprint
16
16
import sys
17
- import tarfile
18
17
import urllib .error
19
18
import urllib .parse
20
19
import urllib .request
21
- import zipfile
22
20
23
21
from autobuild import autobuild_base , common , configfile
24
22
from autobuild .autobuild_tool_source_environment import get_enriched_environment
25
23
from autobuild .hash_algorithms import verify_hash
26
- from autobuild import filetype
24
+ from autobuild import archive_utils
27
25
28
26
logger = logging .getLogger ('autobuild.install' )
29
27
@@ -405,7 +403,7 @@ def _install_binary(configured_name, platform, package, config_file, install_dir
405
403
406
404
def get_metadata_from_package (package_file ) -> configfile .MetadataDescription :
407
405
try :
408
- with open_archive (package_file ) as archive :
406
+ with archive_utils . open_archive (package_file ) as archive :
409
407
f = archive .extractfile (configfile .PACKAGE_METADATA_FILE )
410
408
return configfile .MetadataDescription (stream = f )
411
409
except (FileNotFoundError , KeyError ):
@@ -439,18 +437,6 @@ def _default_metadata_for_package(package_file: str, package = None):
439
437
return metadata
440
438
441
439
442
- def open_archive (filename : str ) -> tarfile .TarFile | zipfile .ZipFile :
443
- f_type = filetype .detect_archive_type (filename )
444
-
445
- if f_type == filetype .ArchiveType .ZST :
446
- return common .ZstdTarFile (filename , "r" )
447
-
448
- if f_type == filetype .ArchiveType .ZIP :
449
- return zipfile .ZipFile (filename , "r" )
450
-
451
- return tarfile .open (filename , "r" )
452
-
453
-
454
440
class ExtractPackageResults :
455
441
files : list [str ]
456
442
conflicts : list [str ]
@@ -468,7 +454,7 @@ def raise_conflicts(self):
468
454
469
455
470
456
def extract_package (package_file : str , install_dir : str , dry_run : bool = False ) -> ExtractPackageResults :
471
- with open_archive (package_file ) as archive :
457
+ with archive_utils . open_archive (package_file ) as archive :
472
458
results = ExtractPackageResults ()
473
459
for t in archive :
474
460
if t .name == configfile .PACKAGE_METADATA_FILE :
0 commit comments