forked from SeleniumHQ/selenium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buckw
executable file
·90 lines (72 loc) · 2.98 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env python2.7
import argparse
import datetime
import hashlib
import os
import os.path
import requests
import stat
import sys
import subprocess
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)
# Figure out the git revision and current timestamp
parser = argparse.ArgumentParser()
parser.prog = "buckw"
parser.add_argument("--stamp-build", default="stable", choices=["stable", "detect"])
parsed, remainder = parser.parse_known_args(sys.argv)
remainder.pop(0)
cmd = remainder.pop(0)
args = ["python", buck_pex, cmd]
stamped_commands = ["build", "publish", "test"]
if "stable" == parsed.stamp_build and cmd in stamped_commands:
args.extend(["--config", "selenium.rev=unknown", "--config", "selenium.timestamp=unknown"])
elif "detect" == parsed.stamp_build and cmd in stamped_commands:
timestamp = datetime.datetime.utcnow().replace(microsecond=0).isoformat()
try:
rev = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).strip()
args.extend(["--config", "selenium.rev=%s" % rev, "--config", "selenium.timestamp=%s" % timestamp])
except subprocess.CalledProcessError:
print("WARNING: UNABLE TO DETERMINE SELENIUM REVISION. BUILD NOT STAMPED PROPERLY")
args.extend(["--config", "selenium.rev=unknown", "--config", "selenium.timestamp=%s" % timestamp])
args.extend(remainder)
sys.exit(subprocess.call(args))