Correctly stop the build if there is an error during the downloading.
This commit is contained in:
parent
8f0c6a321b
commit
5d08673a52
|
@ -101,22 +101,26 @@ def download_remote(what, where, check_certificate=True):
|
||||||
batch_size = 1024 * 8
|
batch_size = 1024 * 8
|
||||||
extra_args = {'context':context} if sys.version_info >= (3, 4, 3) else {}
|
extra_args = {'context':context} if sys.version_info >= (3, 4, 3) else {}
|
||||||
progress_chars = "/-\|"
|
progress_chars = "/-\|"
|
||||||
with urllib.request.urlopen(file_url, **extra_args) as resource, open(file_path, 'wb') as file:
|
try:
|
||||||
tsize = resource.getheader('Content-Length', None)
|
with urllib.request.urlopen(file_url, **extra_args) as resource, open(file_path, 'wb') as file:
|
||||||
if tsize is not None:
|
tsize = resource.getheader('Content-Length', None)
|
||||||
tsize = int(tsize)
|
if tsize is not None:
|
||||||
current = 0
|
tsize = int(tsize)
|
||||||
while True:
|
current = 0
|
||||||
batch = resource.read(batch_size)
|
while True:
|
||||||
if not batch:
|
batch = resource.read(batch_size)
|
||||||
break
|
if not batch:
|
||||||
if tsize:
|
break
|
||||||
current += batch_size
|
if tsize:
|
||||||
print_progress("{:.2%}".format(current/tsize))
|
current += batch_size
|
||||||
else:
|
print_progress("{:.2%}".format(current/tsize))
|
||||||
print_progress(progress_chars[current])
|
else:
|
||||||
current = (current+1)%4
|
print_progress(progress_chars[current])
|
||||||
file.write(batch)
|
current = (current+1)%4
|
||||||
|
file.write(batch)
|
||||||
|
except urllib.error.HTTPError:
|
||||||
|
print("Cannot download url {}".format(file_url))
|
||||||
|
raise StopBuild()
|
||||||
|
|
||||||
if not what.sha256:
|
if not what.sha256:
|
||||||
print('Sha256 for {} not set, do no verify download'.format(what.name))
|
print('Sha256 for {} not set, do no verify download'.format(what.name))
|
||||||
|
|
Loading…
Reference in New Issue