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 = 'win_flex_bison-{}.zip'
18 UPSTREAM_URL = 'https://github.com/lexxmark/winflexbison/releases/download/v{}/{}'
19 GSTREAMER_URL = 'https://gstreamer.freedesktop.org/src/mirror/{}'
22 zip_sha256 = sys.argv[2]
23 source_dir = os.path.join(os.environ['MESON_SOURCE_ROOT'], os.environ['MESON_SUBDIR'])
24 dest = BASENAME.format(version)
25 dest_path = os.path.join(source_dir, dest)
28 hasher = hashlib.sha256()
29 with open(zipf, 'rb') as f:
30 hasher.update(f.read())
31 return hasher.hexdigest()
33 if os.path.isfile(dest_path):
34 found_sha256 = get_sha256(dest_path)
35 if found_sha256 == zip_sha256:
36 print('{} already downloaded'.format(dest))
39 print('{} checksum mismatch, redownloading'.format(dest))
41 for url in (GSTREAMER_URL.format(dest), UPSTREAM_URL.format(version, dest)):
42 print('Downloading {} to {}'.format(url, dest))
44 with open(dest_path, 'wb') as d:
45 f = urllib.request.urlopen(url, context=ctx)
48 except urllib.error.URLError as ex:
50 print('Failed to download from {!r}, trying mirror...'.format(url))
53 curdir = os.path.dirname(sys.argv[0])
54 print('Couldn\'t download {!r}! Try downloading it manually and '
55 'placing it into {!r}'.format(dest, curdir))
57 found_sha256 = get_sha256(dest_path)
58 if found_sha256 != zip_sha256:
59 print('SHA256 of downloaded file {} was {} instead of {}'
60 ''.format(dest, found_sha256, zip_sha256))
63 print('Extracting {}'.format(dest))
64 zf = zipfile.ZipFile(dest_path, "r")
65 zf.extractall(path=source_dir)