Correctly stop the build if there is an error during the downloading.

This commit is contained in:
Matthieu Gautier 2018-04-04 18:16:20 +02:00
parent 8f0c6a321b
commit 5d08673a52
1 changed files with 20 additions and 16 deletions

View File

@ -101,6 +101,7 @@ 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 = "/-\|"
try:
with urllib.request.urlopen(file_url, **extra_args) as resource, open(file_path, 'wb') as file: with urllib.request.urlopen(file_url, **extra_args) as resource, open(file_path, 'wb') as file:
tsize = resource.getheader('Content-Length', None) tsize = resource.getheader('Content-Length', None)
if tsize is not None: if tsize is not None:
@ -117,6 +118,9 @@ def download_remote(what, where, check_certificate=True):
print_progress(progress_chars[current]) print_progress(progress_chars[current])
current = (current+1)%4 current = (current+1)%4
file.write(batch) 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))