2019-12-24 11:22:36 +00:00
|
|
|
#!/usr/bin/env python3
|
2013-07-16 11:28:28 +00:00
|
|
|
|
|
|
|
# This script simply downloads waf to the current directory
|
|
|
|
|
2013-11-24 21:01:03 +00:00
|
|
|
import os, sys, stat, hashlib, subprocess
|
2020-11-23 00:07:46 +00:00
|
|
|
from urllib.request import urlopen, URLError
|
2013-11-24 21:01:03 +00:00
|
|
|
|
2022-09-20 17:34:45 +00:00
|
|
|
WAFRELEASE = "waf-2.0.24"
|
2015-07-11 20:03:27 +00:00
|
|
|
WAFURLS = ["https://waf.io/" + WAFRELEASE,
|
2022-09-20 17:34:45 +00:00
|
|
|
"https://www.freehackers.org/~tnagy/release/" + WAFRELEASE]
|
|
|
|
SHA256HASH = "93909bca823a675f9f40af7c65b24887c3a3c0efdf411ff1978ba827194bdeb0"
|
2013-07-16 11:28:28 +00:00
|
|
|
|
2013-11-24 16:00:12 +00:00
|
|
|
if os.path.exists("waf"):
|
2015-06-04 09:10:02 +00:00
|
|
|
wafver = subprocess.check_output([sys.executable, './waf', '--version']).decode()
|
2013-11-26 20:34:02 +00:00
|
|
|
if WAFRELEASE.split('-')[1] == wafver.split(' ')[1]:
|
|
|
|
print("Found 'waf', skipping download.")
|
|
|
|
sys.exit(0)
|
2013-11-24 16:00:12 +00:00
|
|
|
|
2018-07-11 02:15:19 +00:00
|
|
|
if "--no-download" in sys.argv[1:]:
|
|
|
|
print("Did not find {} and no download was requested.".format(WAFRELEASE))
|
|
|
|
sys.exit(1)
|
|
|
|
|
2015-03-15 20:11:11 +00:00
|
|
|
waf = None
|
|
|
|
|
|
|
|
for WAFURL in WAFURLS:
|
|
|
|
try:
|
|
|
|
print("Downloading {}...".format(WAFURL))
|
|
|
|
waf = urlopen(WAFURL).read()
|
|
|
|
break
|
2020-12-22 17:05:59 +00:00
|
|
|
except URLError as err:
|
|
|
|
print("Download failed! ({})".format(err))
|
2015-03-15 20:11:11 +00:00
|
|
|
|
|
|
|
if not waf:
|
|
|
|
print("Could not download {}.".format(WAFRELEASE))
|
|
|
|
|
|
|
|
sys.exit(1)
|
2013-07-16 11:28:28 +00:00
|
|
|
|
|
|
|
if SHA256HASH == hashlib.sha256(waf).hexdigest():
|
2020-11-19 16:16:16 +00:00
|
|
|
# Upstream waf is not changing the default interpreter during
|
|
|
|
# 2.0.x line due to compatibility reasons apparently. So manually
|
|
|
|
# convert it to use python3 (the script works with both).
|
|
|
|
expected = b"#!/usr/bin/env python\n"
|
|
|
|
assert waf.startswith(expected)
|
|
|
|
waf = b"#!/usr/bin/env python3\n" + waf[len(expected):]
|
2013-07-16 11:28:28 +00:00
|
|
|
with open("waf", "wb") as wf:
|
|
|
|
wf.write(waf)
|
|
|
|
|
|
|
|
os.chmod("waf", os.stat("waf").st_mode | stat.S_IXUSR)
|
|
|
|
print("Checksum verified.")
|
|
|
|
else:
|
|
|
|
print("The checksum of the downloaded file does not match!")
|
2014-10-11 18:35:10 +00:00
|
|
|
print(" - got: {}".format(hashlib.sha256(waf).hexdigest()))
|
|
|
|
print(" - expected: {}".format(SHA256HASH))
|
2013-07-16 11:28:28 +00:00
|
|
|
print("Please download and verify the file manually.")
|
|
|
|
|
|
|
|
sys.exit(1)
|