This repository has been archived by the owner on Oct 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-61a.py
71 lines (57 loc) · 1.83 KB
/
build-61a.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
from os import mkdir, walk
from os.path import join, relpath
from subprocess import check_call
class HogGUIFilter:
@classmethod
def include(cls, name):
if name in ["common_server.py", "hog_gui.py"]:
return True
ext = name.split(".")[-1]
return ext in ["html", "js", "gif", "css", "LICENSE"]
@classmethod
def exclude(cls, name):
if name.split(".")[-1] in ["map", "pyc"]:
return True
return name in [
"Procfile",
"requirements.txt",
"asset-manifest.json",
"robots.txt",
"service-worker.js",
"hog.py",
]
@staticmethod
def require_same(name):
return name in ["dice.py", "ucb.py"]
BUILD_OUTPUT_LOC = "deploy"
def read(path):
with open(path, "rb") as f:
return f.read()
def main(location):
filt = HogGUIFilter()
check_call(["yarn", "build"])
for dirpath, _, filenames in walk(BUILD_OUTPUT_LOC):
outdir = join(location, relpath(dirpath, BUILD_OUTPUT_LOC))
try:
mkdir(outdir)
except FileExistsError:
pass
for name in filenames:
inp = join(dirpath, name)
out = join(outdir, name)
if filt.exclude(name):
pass
elif filt.include(name):
check_call(["cp", inp, out])
elif filt.require_same(name):
with open(inp) as f:
inp_c = f.read()
with open(out) as f:
out_c = f.read()
if inp_c != out_c:
raise RuntimeError("{} is different from {}".format(inp, out))
else:
raise RuntimeError("unrecognized file: {}".format(inp))
if __name__ == "__main__":
from sys import argv
main(*argv[1:])