]>
Commit | Line | Data |
---|---|---|
15295989 | 1 | #!/usr/bin/env python |
a21fb915 | 2 | import pages, os, subprocess, pagegen, shutil, sys |
15295989 CP |
3 | |
4 | COPYRIGHT = open("js/copyright.js", "rb").read() | |
5 | ||
a21fb915 CP |
6 | class MinifyException(Exception): |
7 | pass | |
8 | ||
15295989 | 9 | def jarit(src): |
a21fb915 CP |
10 | try: |
11 | p = subprocess.Popen(["java", "-jar", "bin/yuicompressor-2.3.5.jar", src], stdout=subprocess.PIPE) | |
12 | except Exception, e: | |
13 | if hasattr(e, "errno") and e.errno == 2: | |
14 | raise MinifyException, "unable to run java" | |
15 | raise | |
16 | data = p.communicate()[0] | |
17 | if p.wait() != 0: | |
18 | raise MinifyException, "an error occured" | |
19 | return data | |
15295989 | 20 | |
a21fb915 | 21 | JAVA_WARNING_SURPRESSED = False |
60ce7bee | 22 | def jmerge_files(prefix, suffix, output, files, *args): |
15295989 | 23 | global COPYRIGHT |
60ce7bee | 24 | output = output + "." + suffix |
15295989 CP |
25 | o = os.path.join(prefix, "compiled", output) |
26 | merge_files(o, files, *args) | |
a21fb915 CP |
27 | |
28 | # cough hack | |
29 | compiled = open(o, "rb").read() | |
30 | try: | |
31 | compiled = jarit(o) | |
32 | except MinifyException, e: | |
33 | global JAVA_WARNING_SURPRESSED | |
34 | if not JAVA_WARNING_SURPRESSED: | |
35 | JAVA_WARNING_SURPRESSED = True | |
36 | print >>sys.stderr, "warning: minify: %s (not minifying -- javascript will be HUGE)." % e | |
37 | ||
15295989 | 38 | os.unlink(o) |
60ce7bee | 39 | f = open(os.path.join(prefix, "static", suffix, output), "wb") |
15295989 CP |
40 | f.write(COPYRIGHT) |
41 | f.write(compiled) | |
42 | f.close() | |
43 | ||
44 | def merge_files(output, files, root_path=lambda x: x): | |
45 | f = open(output, "wb") | |
46 | ||
47 | for x in files: | |
48 | f2 = open(root_path(x), "rb") | |
49 | f.write(f2.read()) | |
50 | f2.close() | |
51 | f.close() | |
52 | ||
1e9c8714 | 53 | def main(outputdir=".", produce_debug=True): |
7c4c581c CP |
54 | ID = pagegen.gethgid() |
55 | ||
60ce7bee | 56 | pagegen.main(outputdir, produce_debug=produce_debug) |
15295989 CP |
57 | |
58 | coutputdir = os.path.join(outputdir, "compiled") | |
59 | try: | |
60 | os.mkdir(coutputdir) | |
61 | except: | |
62 | pass | |
60ce7bee CP |
63 | |
64 | try: | |
65 | os.mkdir(os.path.join(outputdir, "static", "css")) | |
66 | except: | |
67 | pass | |
15295989 | 68 | |
60ce7bee | 69 | #jmerge_files(outputdir, "js", "qwebirc", pages.DEBUG_BASE, lambda x: os.path.join("js", x + ".js")) |
15295989 CP |
70 | |
71 | for uiname, value in pages.UIs.items(): | |
60ce7bee | 72 | csssrc = pagegen.csslist(uiname, True) |
7c4c581c | 73 | jmerge_files(outputdir, "css", uiname + "-" + ID, csssrc) |
c3d261fc | 74 | shutil.copy2(os.path.join(outputdir, "static", "css", uiname + "-" + ID + ".css"), os.path.join(outputdir, "static", "css", uiname + ".css")) |
60ce7bee CP |
75 | #jmerge_files(outputdir, "js", uiname, value["uifiles"], lambda x: os.path.join("js", "ui", "frontends", x + ".js")) |
76 | ||
77 | alljs = [] | |
78 | for y in pages.JS_BASE: | |
79 | alljs.append(os.path.join("static", "js", y + ".js")) | |
80 | for y in value.get("buildextra", []): | |
81 | alljs.append(os.path.join("static", "js", "%s.js" % y)) | |
82 | for y in pages.DEBUG_BASE: | |
83 | alljs.append(os.path.join("js", y + ".js")) | |
84 | for y in value["uifiles"]: | |
85 | alljs.append(os.path.join("js", "ui", "frontends", y + ".js")) | |
7c4c581c | 86 | jmerge_files(outputdir, "js", uiname + "-" + ID, alljs) |
60ce7bee | 87 | |
15295989 CP |
88 | os.rmdir(coutputdir) |
89 | ||
90 | if __name__ == "__main__": | |
91 | main() | |
92 |