mpv/bootstrap.py

52 lines
1.4 KiB
Python
Raw Normal View History

#!/usr/bin/env python
# This script simply downloads waf to the current directory
from __future__ import print_function
import os, sys, stat, hashlib, subprocess
2015-07-18 16:06:01 +00:00
WAFRELEASE = "waf-1.8.12"
WAFURLS = ["https://waf.io/" + WAFRELEASE,
2015-03-15 20:11:11 +00:00
"http://www.freehackers.org/~tnagy/release/" + WAFRELEASE]
2015-07-18 16:06:01 +00:00
SHA256HASH = "01bf2beab2106d1558800c8709bc2c8e496d3da4a2ca343fe091f22fca60c98b"
if os.path.exists("waf"):
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)
try:
2015-03-15 20:11:11 +00:00
from urllib.request import urlopen, URLError
except:
2015-03-15 20:11:11 +00:00
from urllib2 import urlopen, URLError
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)
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!")
print(" - got: {}".format(hashlib.sha256(waf).hexdigest()))
print(" - expected: {}".format(SHA256HASH))
print("Please download and verify the file manually.")
sys.exit(1)