]>
Commit | Line | Data |
---|---|---|
15295989 | 1 | #!/usr/bin/env python |
a409b906 CP |
2 | import dependencies |
3 | dependencies.vcheck() | |
4 | ||
982a98fa | 5 | import pages, os, subprocess, pagegen, shutil, sys, time |
15295989 CP |
6 | |
7 | COPYRIGHT = open("js/copyright.js", "rb").read() | |
8 | ||
a21fb915 CP |
9 | class MinifyException(Exception): |
10 | pass | |
11 | ||
15295989 | 12 | def jarit(src): |
a21fb915 | 13 | try: |
91743bbe | 14 | p = subprocess.Popen(["java", "-jar", "bin/yuicompressor-2.4.8.jar", src], stdout=subprocess.PIPE, shell=os.name == "nt") |
a21fb915 CP |
15 | except Exception, e: |
16 | if hasattr(e, "errno") and e.errno == 2: | |
17 | raise MinifyException, "unable to run java" | |
18 | raise | |
19 | data = p.communicate()[0] | |
20 | if p.wait() != 0: | |
21 | raise MinifyException, "an error occured" | |
22 | return data | |
15295989 | 23 | |
a21fb915 | 24 | JAVA_WARNING_SURPRESSED = False |
4dd199c3 | 25 | def jmerge_files(prefix, suffix, output, files, *args, **kwargs): |
15295989 | 26 | global COPYRIGHT |
60ce7bee | 27 | output = output + "." + suffix |
15295989 CP |
28 | o = os.path.join(prefix, "compiled", output) |
29 | merge_files(o, files, *args) | |
a21fb915 CP |
30 | |
31 | # cough hack | |
a21fb915 CP |
32 | try: |
33 | compiled = jarit(o) | |
34 | except MinifyException, e: | |
35 | global JAVA_WARNING_SURPRESSED | |
36 | if not JAVA_WARNING_SURPRESSED: | |
37 | JAVA_WARNING_SURPRESSED = True | |
38 | print >>sys.stderr, "warning: minify: %s (not minifying -- javascript will be HUGE)." % e | |
b567a4f4 CP |
39 | try: |
40 | f = open(o, "rb") | |
41 | compiled = f.read() | |
42 | finally: | |
43 | f.close() | |
a21fb915 | 44 | |
0fab628b CP |
45 | try: |
46 | os.unlink(o) | |
47 | except: | |
48 | time.sleep(1) # windows sucks | |
49 | os.unlink(o) | |
b567a4f4 | 50 | |
60ce7bee | 51 | f = open(os.path.join(prefix, "static", suffix, output), "wb") |
15295989 | 52 | f.write(COPYRIGHT) |
4dd199c3 CP |
53 | |
54 | if kwargs.get("file_prefix"): | |
55 | f.write(kwargs.get("file_prefix")) | |
56 | ||
15295989 CP |
57 | f.write(compiled) |
58 | f.close() | |
59 | ||
60 | def merge_files(output, files, root_path=lambda x: x): | |
61 | f = open(output, "wb") | |
62 | ||
63 | for x in files: | |
40296624 CP |
64 | if x.startswith("//"): |
65 | continue | |
15295989 | 66 | f2 = open(root_path(x), "rb") |
87fbc08a | 67 | f.write(f2.read() + "\n") |
15295989 CP |
68 | f2.close() |
69 | f.close() | |
70 | ||
1e9c8714 | 71 | def main(outputdir=".", produce_debug=True): |
7c4c581c CP |
72 | ID = pagegen.gethgid() |
73 | ||
60ce7bee | 74 | pagegen.main(outputdir, produce_debug=produce_debug) |
15295989 CP |
75 | |
76 | coutputdir = os.path.join(outputdir, "compiled") | |
77 | try: | |
78 | os.mkdir(coutputdir) | |
79 | except: | |
80 | pass | |
60ce7bee CP |
81 | |
82 | try: | |
83 | os.mkdir(os.path.join(outputdir, "static", "css")) | |
84 | except: | |
85 | pass | |
15295989 | 86 | |
60ce7bee | 87 | #jmerge_files(outputdir, "js", "qwebirc", pages.DEBUG_BASE, lambda x: os.path.join("js", x + ".js")) |
15295989 CP |
88 | |
89 | for uiname, value in pages.UIs.items(): | |
60ce7bee | 90 | csssrc = pagegen.csslist(uiname, True) |
7c4c581c | 91 | jmerge_files(outputdir, "css", uiname + "-" + ID, csssrc) |
c3d261fc | 92 | shutil.copy2(os.path.join(outputdir, "static", "css", uiname + "-" + ID + ".css"), os.path.join(outputdir, "static", "css", uiname + ".css")) |
4dd199c3 CP |
93 | |
94 | mcssname = os.path.join("css", uiname + ".mcss") | |
95 | if os.path.exists(mcssname): | |
96 | mcssdest = os.path.join(outputdir, "static", "css", uiname + ".mcss") | |
97 | shutil.copy2(mcssname, mcssdest) | |
98 | shutil.copy2(mcssdest, os.path.join(outputdir, "static", "css", uiname + "-" + ID + ".mcss")) | |
99 | ||
60ce7bee CP |
100 | #jmerge_files(outputdir, "js", uiname, value["uifiles"], lambda x: os.path.join("js", "ui", "frontends", x + ".js")) |
101 | ||
56fe2252 | 102 | alljs = ["js/debugdisabled.js"] |
60ce7bee CP |
103 | for y in pages.JS_BASE: |
104 | alljs.append(os.path.join("static", "js", y + ".js")) | |
105 | for y in value.get("buildextra", []): | |
106 | alljs.append(os.path.join("static", "js", "%s.js" % y)) | |
107 | for y in pages.DEBUG_BASE: | |
108 | alljs.append(os.path.join("js", y + ".js")) | |
109 | for y in value["uifiles"]: | |
110 | alljs.append(os.path.join("js", "ui", "frontends", y + ".js")) | |
4dd199c3 | 111 | jmerge_files(outputdir, "js", uiname + "-" + ID, alljs, file_prefix="QWEBIRC_BUILD=\"" + ID + "\";\n") |
97fd8c3a | 112 | |
15295989 CP |
113 | os.rmdir(coutputdir) |
114 | ||
a409b906 CP |
115 | f = open(".compiled", "w") |
116 | f.close() | |
117 | ||
118 | def has_compiled(): | |
119 | try: | |
120 | f = open(".compiled", "r") | |
121 | f.close() | |
122 | return True | |
123 | except: | |
124 | pass | |
125 | ||
126 | try: | |
127 | f = open(os.path.join("bin", ".compiled"), "r") | |
128 | f.close() | |
129 | return True | |
130 | except: | |
131 | pass | |
132 | ||
133 | return False | |
134 | ||
135 | def vcheck(): | |
136 | if has_compiled(): | |
137 | return | |
138 | ||
139 | print >>sys.stderr, "error: not yet compiled, run compile.py first." | |
140 | sys.exit(1) | |
141 | ||
15295989 CP |
142 | if __name__ == "__main__": |
143 | main() | |
40296624 | 144 |