]> jfr.im git - irc/quakenet/qwebirc.git/blame - bin/compile.py
Added tag stable for changeset 231e288a731a
[irc/quakenet/qwebirc.git] / bin / compile.py
CommitLineData
15295989 1#!/usr/bin/env python
c3d261fc 2import pages, os, subprocess, pagegen, shutil
15295989
CP
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)
c3d261fc 51 shutil.copy2(os.path.join(outputdir, "static", "css", uiname + "-" + ID + ".css"), os.path.join(outputdir, "static", "css", uiname + ".css"))
60ce7bee
CP
52 #jmerge_files(outputdir, "js", uiname, value["uifiles"], lambda x: os.path.join("js", "ui", "frontends", x + ".js"))
53
54 alljs = []
55 for y in pages.JS_BASE:
56 alljs.append(os.path.join("static", "js", y + ".js"))
57 for y in value.get("buildextra", []):
58 alljs.append(os.path.join("static", "js", "%s.js" % y))
59 for y in pages.DEBUG_BASE:
60 alljs.append(os.path.join("js", y + ".js"))
61 for y in value["uifiles"]:
62 alljs.append(os.path.join("js", "ui", "frontends", y + ".js"))
7c4c581c 63 jmerge_files(outputdir, "js", uiname + "-" + ID, alljs)
60ce7bee 64
15295989
CP
65 os.rmdir(coutputdir)
66
67if __name__ == "__main__":
68 main()
69