Skip to content
This repository was archived by the owner on Apr 8, 2025. It is now read-only.

Commit 0935765

Browse files
committed
CI: Add support for extracting zip archives
1 parent c570fe1 commit 0935765

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

cr8/run_crate.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import zipfile
2+
13
import argh
24
import os
35
import json
@@ -472,18 +474,22 @@ def _can_use_cache(uri, crate_dir):
472474

473475
def _download_and_extract(uri, crate_root):
474476
filename = os.path.basename(uri)
475-
crate_folder_name = re.sub(r'\.tar(\.gz)?$', '', filename)
477+
crate_folder_name = re.sub(r'\.(tar|zip)(\.gz)?$', '', filename)
476478
crate_dir = os.path.join(crate_root, crate_folder_name)
477479

478480
if _can_use_cache(uri, crate_dir):
479-
log.info('Skipping download, tarball alrady extracted at %s', crate_dir)
481+
log.info('Skipping download, archive already extracted at %s', crate_dir)
480482
return crate_dir
481483
elif os.path.exists(crate_dir):
482484
shutil.rmtree(crate_dir, ignore_errors=True)
483485
log.info('Downloading %s and extracting to %s', uri, crate_root)
484486
with _openuri(uri) as tmpfile:
485-
with tarfile.open(fileobj=tmpfile) as t:
486-
t.extractall(crate_root)
487+
if uri.endswith(".zip"):
488+
with zipfile.ZipFile(file=tmpfile) as t:
489+
t.extractall(crate_root)
490+
else:
491+
with tarfile.open(fileobj=tmpfile) as t:
492+
t.extractall(crate_root)
487493
tmpfile.seek(0)
488494
checksum = sha1(tmpfile.read()).hexdigest()
489495
with open(os.path.join(crate_dir, checksum), 'a'):

0 commit comments

Comments
 (0)