11 # Disable certificate checking because it always fails on Windows
12 # We verify the checksum anyway.
13 ctx = ssl.create_default_context()
14 ctx.check_hostname = False
15 ctx.verify_mode = ssl.CERT_NONE
17 BASENAME = 'nasm-{}-{}.zip'
18 UPSTREAM_URL = 'https://www.nasm.us/pub/nasm/releasebuilds/{}/{}/{}'
19 GSTREAMER_URL = 'https://gstreamer.freedesktop.org/src/mirror/{}'
22 arch = 'win64' if sys.argv[2] == 'x86_64' else 'win32'
23 zip_sha256 = sys.argv[3]
24 source_dir = os.path.join(os.environ['MESON_SOURCE_ROOT'], os.environ['MESON_SUBDIR'])
25 dest = BASENAME.format(version, arch)
26 dest_path = os.path.join(source_dir, dest)
29 hasher = hashlib.sha256()
30 with open(zipf, 'rb') as f:
31 hasher.update(f.read())
32 return hasher.hexdigest()
34 if os.path.isfile(dest_path):
35 found_sha256 = get_sha256(dest_path)
36 if found_sha256 == zip_sha256:
37 print('{} already downloaded'.format(dest))
40 print('{} checksum mismatch, redownloading'.format(dest))
42 for url in (GSTREAMER_URL.format(dest), UPSTREAM_URL.format(version, arch, dest)):
43 print('Downloading {} to {}'.format(url, dest))
45 with open(dest_path, 'wb') as d:
46 f = urllib.request.urlopen(url, context=ctx)
49 except urllib.error.URLError as ex:
51 print('Failed to download from {!r}, trying mirror...'.format(url))
54 curdir = os.path.dirname(sys.argv[0])
55 print('Couldn\'t download {!r}! Try downloading it manually and '
56 'placing it into {!r}'.format(dest, curdir))
58 found_sha256 = get_sha256(dest_path)
59 if found_sha256 != zip_sha256:
60 print('SHA256 of downloaded file {} was {} instead of {}'
61 ''.format(dest, found_sha256, zip_sha256))
64 print('Extracting {}'.format(dest))
65 zf = zipfile.ZipFile(dest_path, "r")
66 zf.extractall(path=source_dir)