From 352b83812182eed561bc5bb6722994e5f563a25e Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Sat, 18 Jan 2020 17:37:46 +0530 Subject: [PATCH] win-nasm: Use gstreamer mirror as primary source nasm.us went down today and broke all our CI. Use the gstreamer mirror as the primary source and fallback to nasm.us if that's down. --- subprojects/win-nasm/download-binary.py | 29 +++++++++++++++++++------ 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/subprojects/win-nasm/download-binary.py b/subprojects/win-nasm/download-binary.py index 26ad64ba1e..e879ff86dd 100644 --- a/subprojects/win-nasm/download-binary.py +++ b/subprojects/win-nasm/download-binary.py @@ -6,6 +6,7 @@ import ssl import zipfile import hashlib import urllib.request +import urllib.error # Disable certificate checking because it always fails on Windows # We verify the checksum anyway. @@ -13,12 +14,15 @@ ctx = ssl.create_default_context() ctx.check_hostname = False ctx.verify_mode = ssl.CERT_NONE -base_url = 'https://www.nasm.us/pub/nasm/releasebuilds/{0}/{1}/nasm-{0}-{1}.zip' +BASENAME = 'nasm-{}-{}.zip' +UPSTREAM_URL = 'https://www.nasm.us/pub/nasm/releasebuilds/{}/{}/{}' +GSTREAMER_URL = 'https://gstreamer.freedesktop.org/src/mirror/{}' + +version = sys.argv[1] arch = 'win64' if sys.argv[2] == 'x86_64' else 'win32' -url = base_url.format(sys.argv[1], arch) zip_sha256 = sys.argv[3] source_dir = os.path.join(os.environ['MESON_SOURCE_ROOT'], os.environ['MESON_SUBDIR']) -dest = os.path.basename(url) +dest = BASENAME.format(version, arch) dest_path = os.path.join(source_dir, dest) def get_sha256(zipf): @@ -35,10 +39,21 @@ if os.path.isfile(dest_path): else: print('{} checksum mismatch, redownloading'.format(dest)) -print('Downloading {} to {}'.format(url, dest)) -with open(dest_path, 'wb') as d: - f = urllib.request.urlopen(url, context=ctx) - d.write(f.read()) +for url in (GSTREAMER_URL.format(dest), UPSTREAM_URL.format(version, arch, dest)): + print('Downloading {} to {}'.format(url, dest)) + try: + with open(dest_path, 'wb') as d: + f = urllib.request.urlopen(url, context=ctx) + d.write(f.read()) + break + except urllib.error.URLError as ex: + print(ex) + print('Failed to download from {!r}, trying mirror...'.format(url)) + continue +else: + curdir = os.path.dirname(sys.argv[0]) + print('Couldn\'t download {!r}! Try downloading it manually and ' + 'placing it into {!r}'.format(dest, curdir)) found_sha256 = get_sha256(dest_path) if found_sha256 != zip_sha256: