forked from xlrl/docker-mantisbt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-dockerfile.py
executable file
·52 lines (40 loc) · 1.11 KB
/
update-dockerfile.py
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
#!/usr/bin/python3
import requests
import re
import sys
def log(msg):
print(msg, flush=True, end="")
def logline(msg):
print(msg, flush=True)
assert len(sys.argv) == 2
m = re.match(r"^[0-9.]+$", sys.argv[1])
assert m
version = m.group(0)
log("Get SHA1 digest for %s..." % version)
url_fmt = "http://downloads.sourceforge.net/project/mantisbt/mantis-stable/{MANTIS_VER}/mantisbt-{MANTIS_VER}.tar.gz.digests"
url = url_fmt.format(MANTIS_VER=version)
resp = requests.get(url)
assert resp.status_code == 200, "Invalid status code %d" % resp.status_code
m = re.search(r"[0-9a-f]{40}", resp.text)
assert m, resp.text
sha1 = m.group(0)
logline(sha1)
filepath = "Dockerfile"
log("Patch %s..." % filepath)
with open(filepath, "r") as file:
t = file.read()
t_old = t
m = re.search(r"MANTIS_VER ([0-9.]+)", t)
assert m
t_new = t[ : m.start(1)] + version
t = t[m.end(0) : ]
m = re.search(r"MANTIS_SHA1 ([0-9a-f]+)", t)
assert m
t_new += t[ : m.start(1)] + sha1
t_new += t[m.end(0) : ]
if t_new == t_old:
logline("Unchanged")
else:
with open(filepath, "w") as file:
file.write(t_new)
logline("Updated")