2019-12-24 12:22:36 +01:00
|
|
|
#!/usr/bin/env python3
|
2013-07-16 13:28:28 +02:00
|
|
|
|
|
|
|
# This script simply downloads waf to the current directory
|
|
|
|
|
|
|
|
from __future__ import print_function
|
2013-11-24 22:01:03 +01:00
|
|
|
import os, sys, stat, hashlib, subprocess
|
|
|
|
|
2018-07-01 01:39:12 +02:00
|
|
|
WAFRELEASE = "waf-2.0.9"
|
2015-07-11 22:03:27 +02:00
|
|
|
WAFURLS = ["https://waf.io/" + WAFRELEASE,
|
2015-03-15 21:11:11 +01:00
|
|
|
"http://www.freehackers.org/~tnagy/release/" + WAFRELEASE]
|
2018-07-01 01:39:12 +02:00
|
|
|
SHA256HASH = "2a8e0816f023995e557f79ea8940d322bec18f286917c8f9a6fa2dc3875dfa48"
|
2013-07-16 13:28:28 +02:00
|
|
|
|
2013-11-24 17:00:12 +01:00
|
|
|
if os.path.exists("waf"):
|
2015-06-04 11:10:02 +02:00
|
|
|
wafver = subprocess.check_output([sys.executable, './waf', '--version']).decode()
|
2013-11-26 21:34:02 +01:00
|
|
|
if WAFRELEASE.split('-')[1] == wafver.split(' ')[1]:
|
|
|
|
print("Found 'waf', skipping download.")
|
|
|
|
sys.exit(0)
|
2013-11-24 17:00:12 +01:00
|
|
|
|
2018-07-11 04:15:19 +02:00
|
|
|
if "--no-download" in sys.argv[1:]:
|
|
|
|
print("Did not find {} and no download was requested.".format(WAFRELEASE))
|
|
|
|
sys.exit(1)
|
|
|
|
|
2013-07-16 13:28:28 +02:00
|
|
|
try:
|
2015-03-15 21:11:11 +01:00
|
|
|
from urllib.request import urlopen, URLError
|
2013-07-16 13:28:28 +02:00
|
|
|
except:
|
2015-03-15 21:11:11 +01:00
|
|
|
from urllib2 import urlopen, URLError
|
2013-07-16 13:28:28 +02:00
|
|
|
|
2015-03-15 21:11:11 +01:00
|
|
|
waf = None
|
|
|
|
|
|
|
|
for WAFURL in WAFURLS:
|
|
|
|
try:
|
|
|
|
print("Downloading {}...".format(WAFURL))
|
|
|
|
waf = urlopen(WAFURL).read()
|
|
|
|
break
|
|
|
|
except URLError:
|
|
|
|
print("Download failed.")
|
|
|
|
|
|
|
|
if not waf:
|
|
|
|
print("Could not download {}.".format(WAFRELEASE))
|
|
|
|
|
|
|
|
sys.exit(1)
|
2013-07-16 13:28:28 +02:00
|
|
|
|
|
|
|
if SHA256HASH == hashlib.sha256(waf).hexdigest():
|
|
|
|
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 20:35:10 +02:00
|
|
|
print(" - got: {}".format(hashlib.sha256(waf).hexdigest()))
|
|
|
|
print(" - expected: {}".format(SHA256HASH))
|
2013-07-16 13:28:28 +02:00
|
|
|
print("Please download and verify the file manually.")
|
|
|
|
|
|
|
|
sys.exit(1)
|