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.
This commit is contained in:
Nirbheek Chauhan 2020-01-18 17:37:46 +05:30
parent 439dfa2955
commit 352b838121

View file

@ -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: