]> jfr.im git - irc/quakenet/qwebirc.git/blame - bin/compile.py
. in nick now adds a random number.
[irc/quakenet/qwebirc.git] / bin / compile.py
CommitLineData
15295989
CP
1#!/usr/bin/env python
2import pages, os, subprocess, pagegen
3
4COPYRIGHT = open("js/copyright.js", "rb").read()
5
6def jarit(src):
7 return subprocess.Popen(["java", "-jar", "bin/yuicompressor-2.3.5.jar", src], stdout=subprocess.PIPE).communicate()[0]
8
60ce7bee 9def jmerge_files(prefix, suffix, output, files, *args):
15295989 10 global COPYRIGHT
60ce7bee 11 output = output + "." + suffix
15295989
CP
12 o = os.path.join(prefix, "compiled", output)
13 merge_files(o, files, *args)
14 compiled = jarit(o)
15 os.unlink(o)
60ce7bee 16 f = open(os.path.join(prefix, "static", suffix, output), "wb")
15295989
CP
17 f.write(COPYRIGHT)
18 f.write(compiled)
19 f.close()
20
21def merge_files(output, files, root_path=lambda x: x):
22 f = open(output, "wb")
23
24 for x in files:
25 f2 = open(root_path(x), "rb")
26 f.write(f2.read())
27 f2.close()
28 f.close()
29
1e9c8714 30def main(outputdir=".", produce_debug=True):
7c4c581c
CP
31 ID = pagegen.gethgid()
32
60ce7bee 33 pagegen.main(outputdir, produce_debug=produce_debug)
15295989
CP
34
35 coutputdir = os.path.join(outputdir, "compiled")
36 try:
37 os.mkdir(coutputdir)
38 except:
39 pass
60ce7bee
CP
40
41 try:
42 os.mkdir(os.path.join(outputdir, "static", "css"))
43 except:
44 pass
15295989 45
60ce7bee 46 #jmerge_files(outputdir, "js", "qwebirc", pages.DEBUG_BASE, lambda x: os.path.join("js", x + ".js"))
15295989
CP
47
48 for uiname, value in pages.UIs.items():
60ce7bee 49 csssrc = pagegen.csslist(uiname, True)
7c4c581c 50 jmerge_files(outputdir, "css", uiname + "-" + ID, csssrc)
60ce7bee
CP
51 #jmerge_files(outputdir, "js", uiname, value["uifiles"], lambda x: os.path.join("js", "ui", "frontends", x + ".js"))
52
53 alljs = []
54 for y in pages.JS_BASE:
55 alljs.append(os.path.join("static", "js", y + ".js"))
56 for y in value.get("buildextra", []):
57 alljs.append(os.path.join("static", "js", "%s.js" % y))
58 for y in pages.DEBUG_BASE:
59 alljs.append(os.path.join("js", y + ".js"))
60 for y in value["uifiles"]:
61 alljs.append(os.path.join("js", "ui", "frontends", y + ".js"))
7c4c581c 62 jmerge_files(outputdir, "js", uiname + "-" + ID, alljs)
60ce7bee 63
15295989
CP
64 os.rmdir(coutputdir)
65
66if __name__ == "__main__":
67 main()
68