forked from SeleniumHQ/selenium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buckw
executable file
·65 lines (53 loc) · 1.89 KB
/
buckw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python2
import hashlib
import os
import os.path
import requests
import stat
import sys
from subprocess import call
buck_version = open(".buckversion").readline().rstrip()
buck_hash = open(".buckhash").readline().rstrip()
buck_pex = os.path.join("buck-out", "crazy-fun", buck_version, "buck.pex")
url = "https://github.com/SeleniumHQ/buck/releases/download/buck-release-%s/buck.pex" % buck_version
def download(url, out, hash):
base_name = os.path.dirname(out)
if not os.path.exists(base_name):
try:
os.makedirs(base_name)
except OSError as e:
if e.errno != errno.EEXIST:
raise
print "Downloading Buck. This may take some time"
response = requests.get(url, stream=True)
if response.status_code != 200:
raise IOError("Unable to download buck")
total_length = float(response.headers.get('content-length'))
count = 0
with open(out, "wb") as f:
md5 = hashlib.md5()
for chunk in response.iter_content(chunk_size=4096):
count += len(chunk)
done = int(50 * float(count) / total_length)
sys.stdout.write("\r[%s%s]" % ('=' * done, ' ' * (50-done)) )
sys.stdout.flush()
f.write(chunk)
md5.update(chunk)
if md5.hexdigest() != hash:
raise IOError("Downloaded buck version doesn't match expected hash")
if os.path.isfile(buck_pex):
md5 = hashlib.md5()
with open(buck_pex, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
md5.update(chunk)
if md5.hexdigest() != buck_hash:
print "MD5 hashes don't match. Re-downloading"
download(url, buck_pex, buck_hash)
else:
download(url, buck_pex, buck_hash)
st = os.stat(buck_pex)
os.chmod(buck_pex, st.st_mode | stat.S_IEXEC)
sys.argv.pop(0)
args = ["python", buck_pex]
args.extend(sys.argv)
sys.exit(call(args))