2013-07-16 11:28:28 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
# This script simply downloads waf to the current directory
|
|
|
|
|
|
|
|
from __future__ import print_function
|
2013-11-24 21:01:03 +00:00
|
|
|
import os, sys, stat, hashlib, subprocess
|
|
|
|
|
2014-12-04 20:55:00 +00:00
|
|
|
WAFRELEASE = "waf-1.8.4"
|
2015-03-15 20:11:11 +00:00
|
|
|
WAFURLS = ["http://ftp.waf.io/pub/release/" + WAFRELEASE,
|
|
|
|
"http://www.freehackers.org/~tnagy/release/" + WAFRELEASE]
|
2014-12-04 20:55:00 +00:00
|
|
|
SHA256HASH = "f02035fa5d8814f33f19b2b20d43822ddef6bb39b955ca196c2a247a1f9ffaa8"
|
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
|
|
|
|
2013-07-16 11:28:28 +00:00
|
|
|
try:
|
2015-03-15 20:11:11 +00:00
|
|
|
from urllib.request import urlopen, URLError
|
2013-07-16 11:28:28 +00:00
|
|
|
except:
|
2015-03-15 20:11:11 +00:00
|
|
|
from urllib2 import urlopen, URLError
|
2013-07-16 11:28:28 +00:00
|
|
|
|
2015-03-15 20:11:11 +00: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 11:28:28 +00: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 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)
|