|
1 | | -from os.path import basename, dirname, exists, isdir, isfile, join, realpath, split |
2 | | -import importlib |
| 1 | +import fnmatch |
3 | 2 | import glob |
4 | | -from shutil import rmtree |
5 | | -from six import PY2, with_metaclass |
6 | | - |
7 | 3 | import hashlib |
8 | | -from re import match |
9 | | - |
10 | | -import sh |
| 4 | +import importlib |
11 | 5 | import shutil |
12 | | -import fnmatch |
13 | 6 | from os import listdir, unlink, environ, mkdir, curdir, walk |
| 7 | +from os.path import basename, dirname, exists, isdir, isfile, join, realpath, split |
| 8 | +from re import match |
| 9 | +from shutil import rmtree |
14 | 10 | from sys import stdout |
| 11 | + |
| 12 | +import sh |
| 13 | +from six import PY2, with_metaclass |
| 14 | + |
15 | 15 | try: |
16 | 16 | from urlparse import urlparse |
17 | 17 | except ImportError: |
@@ -144,7 +144,19 @@ def report_hook(index, blksize, size): |
144 | 144 | if exists(target): |
145 | 145 | unlink(target) |
146 | 146 |
|
147 | | - urlretrieve(url, target, report_hook) |
| 147 | + # Download item with multiple attempts (for bad connections): |
| 148 | + attempts = 0 |
| 149 | + while True: |
| 150 | + try: |
| 151 | + urlretrieve(url, target, report_hook) |
| 152 | + except OSError: |
| 153 | + attempts += 1 |
| 154 | + if attempts >= 5: |
| 155 | + raise |
| 156 | + stdout.write('Download failed retrying in a second...') |
| 157 | + time.sleep(1) |
| 158 | + continue |
| 159 | + break |
148 | 160 | return target |
149 | 161 | elif parsed_url.scheme in ('git', 'git+file', 'git+ssh', 'git+http', 'git+https'): |
150 | 162 | if isdir(target): |
@@ -375,17 +387,12 @@ def unpack(self, arch): |
375 | 387 | root_directory = fileh.filelist[0].filename.split('/')[0] |
376 | 388 | if root_directory != basename(directory_name): |
377 | 389 | shprint(sh.mv, root_directory, directory_name) |
378 | | - elif (extraction_filename.endswith('.tar.gz') or |
379 | | - extraction_filename.endswith('.tgz') or |
380 | | - extraction_filename.endswith('.tar.bz2') or |
381 | | - extraction_filename.endswith('.tbz2') or |
382 | | - extraction_filename.endswith('.tar.xz') or |
383 | | - extraction_filename.endswith('.txz')): |
| 390 | + elif extraction_filename.endswith( |
| 391 | + ('.tar.gz', '.tgz', '.tar.bz2', '.tbz2', '.tar.xz', '.txz')): |
384 | 392 | sh.tar('xf', extraction_filename) |
385 | | - root_directory = shprint( |
386 | | - sh.tar, 'tf', extraction_filename).stdout.decode( |
387 | | - 'utf-8').split('\n')[0].split('/')[0] |
388 | | - if root_directory != directory_name: |
| 393 | + root_directory = sh.tar('tf', extraction_filename).stdout.decode( |
| 394 | + 'utf-8').split('\n')[0].split('/')[0] |
| 395 | + if root_directory != basename(directory_name): |
389 | 396 | shprint(sh.mv, root_directory, directory_name) |
390 | 397 | else: |
391 | 398 | raise Exception( |
|
0 commit comments