|
| 1 | +import zipfile |
| 2 | + |
1 | 3 | import argh
|
2 | 4 | import os
|
3 | 5 | import json
|
@@ -472,18 +474,22 @@ def _can_use_cache(uri, crate_dir):
|
472 | 474 |
|
473 | 475 | def _download_and_extract(uri, crate_root):
|
474 | 476 | 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) |
476 | 478 | crate_dir = os.path.join(crate_root, crate_folder_name)
|
477 | 479 |
|
478 | 480 | 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) |
480 | 482 | return crate_dir
|
481 | 483 | elif os.path.exists(crate_dir):
|
482 | 484 | shutil.rmtree(crate_dir, ignore_errors=True)
|
483 | 485 | log.info('Downloading %s and extracting to %s', uri, crate_root)
|
484 | 486 | 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) |
487 | 493 | tmpfile.seek(0)
|
488 | 494 | checksum = sha1(tmpfile.read()).hexdigest()
|
489 | 495 | with open(os.path.join(crate_dir, checksum), 'a'):
|
|
0 commit comments