Skip to content

Commit 1332427

Browse files
committed
Update recipe from upstream
1 parent 124cceb commit 1332427

File tree

1 file changed

+27
-20
lines changed

1 file changed

+27
-20
lines changed

pythonforandroid/recipe.py

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
from os.path import basename, dirname, exists, isdir, isfile, join, realpath, split
2-
import importlib
1+
import fnmatch
32
import glob
4-
from shutil import rmtree
5-
from six import PY2, with_metaclass
6-
73
import hashlib
8-
from re import match
9-
10-
import sh
4+
import importlib
115
import shutil
12-
import fnmatch
136
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
1410
from sys import stdout
11+
12+
import sh
13+
from six import PY2, with_metaclass
14+
1515
try:
1616
from urlparse import urlparse
1717
except ImportError:
@@ -144,7 +144,19 @@ def report_hook(index, blksize, size):
144144
if exists(target):
145145
unlink(target)
146146

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
148160
return target
149161
elif parsed_url.scheme in ('git', 'git+file', 'git+ssh', 'git+http', 'git+https'):
150162
if isdir(target):
@@ -375,17 +387,12 @@ def unpack(self, arch):
375387
root_directory = fileh.filelist[0].filename.split('/')[0]
376388
if root_directory != basename(directory_name):
377389
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')):
384392
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):
389396
shprint(sh.mv, root_directory, directory_name)
390397
else:
391398
raise Exception(

0 commit comments

Comments
 (0)