Create a property in the remotefile to get the correct url.

This commit is contained in:
Matthieu Gautier 2018-11-14 11:08:44 +01:00
parent 22f1693335
commit 0b9f13a2f0
1 changed files with 6 additions and 3 deletions

View File

@ -88,7 +88,6 @@ def copy_tree(src, dst, post_copy_function=None):
def download_remote(what, where): def download_remote(what, where):
file_path = pj(where, what.name) file_path = pj(where, what.name)
file_url = what.url or (REMOTE_PREFIX + what.name)
if os.path.exists(file_path): if os.path.exists(file_path):
if what.sha256 == get_sha256(file_path): if what.sha256 == get_sha256(file_path):
raise SkipCommand() raise SkipCommand()
@ -104,7 +103,7 @@ def download_remote(what, where):
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: try:
with urllib.request.urlopen(file_url, **extra_args) as resource, open(file_path, 'wb') as file: with urllib.request.urlopen(what.url, **extra_args) as resource, open(file_path, 'wb') as file:
tsize = resource.info().get('Content-Length', None) tsize = resource.info().get('Content-Length', None)
if tsize is not None: if tsize is not None:
tsize = int(tsize) tsize = int(tsize)
@ -121,7 +120,7 @@ def download_remote(what, where):
current = (current+1)%4 current = (current+1)%4
file.write(batch) file.write(batch)
except urllib.error.URLError as e: except urllib.error.URLError as e:
print("Cannot download url {}:\n{}".format(file_url, e.reason)) print("Cannot download url {}:\n{}".format(what.url, e.reason))
raise StopBuild() raise StopBuild()
if not what.sha256: if not what.sha256:
@ -143,6 +142,10 @@ class Remotefile(namedtuple('Remotefile', ('name', 'sha256', 'url'))):
def __new__(cls, name, sha256, url=None): def __new__(cls, name, sha256, url=None):
return super().__new__(cls, name, sha256, url) return super().__new__(cls, name, sha256, url)
@property
def url(self):
return self.url or (REMOTE_PREFIX + self.name)
class Context: class Context:
def __init__(self, command_name, log_file, force_native_build): def __init__(self, command_name, log_file, force_native_build):