-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.py
84 lines (74 loc) · 2.4 KB
/
build.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
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
"""Build this into a release for depmap-releases."""
import datetime
import glob
import os
import subprocess
import sys
RELPATH = "/home/akrherz/projects/depmap-releases"
RELEASE = f"v{datetime.datetime.now():%Y%m%dT%H%M}"
JSINC = ["js/appvars.js", "js/nextgen.js", "js/start.js"]
def buildjs():
"""Build (Google Compiler) our javascript release."""
fns = " ".join([f"--js=src/{f}" for f in JSINC])
cmd = (
f"java -jar ~/lib/compiler.jar {fns} "
f"--js_output_file={RELPATH}/{RELEASE}.js"
)
proc = subprocess.Popen(
cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
(stdout, stderr) = proc.communicate()
if stdout != b"" or stderr != b"":
print(f"cmd: {cmd}")
print(f"stdout: {stdout}")
print(f"stderr: {stderr}")
print("ABORT")
sys.exit()
def indexhtml():
"""index.html logic."""
with open(f"{RELPATH}/index.html", "w", encoding="utf-8") as fh:
donework = False
with open("src/index.html", "r", encoding="utf-8") as ifh:
for line in ifh:
if line.find("WEB_INTERFACE_VERSION") > -1:
fh.write(line.replace("WEB_INTERFACE_VERSION", RELEASE))
continue
if line.find("<!-- replaceme -->") == -1:
fh.write(line)
elif not donework:
fh.write(f'<script src="{RELEASE}.js"></script>\n')
donework = True
def main():
"""Go Main Go."""
# assemble javascript into release
buildjs()
# git tag this repo
subprocess.call(["git", "tag", RELEASE])
# Edit index.html
indexhtml()
# Copy files
subprocess.call(
[
"rsync",
"-a",
"-v",
"--delete",
"src/css",
"src/images",
"src/lib",
RELPATH,
]
)
# git commit, tag, and push to github
os.chdir(RELPATH)
subprocess.call(["git", "add", *glob.glob("*")])
subprocess.call(["git", "commit", "-m", f"depmap release {RELEASE}"])
subprocess.call(["git", "tag", RELEASE])
# Open browser to see what we have
subprocess.call(["gio", "open", "http://depmap-releases.local/"])
if input("Process with push? y/[n]") == "y":
subprocess.call(["git", "push", "--all"])
else:
print("ABORT git push.")
if __name__ == "__main__":
main()