]>
Commit | Line | Data |
---|---|---|
7c4c581c | 1 | import os, sys, pages, subprocess, re |
ef8a4598 | 2 | |
a21fb915 CP |
3 | class HGException(Exception): |
4 | pass | |
5 | ||
ef8a4598 | 6 | def jslist(name, debug): |
01a3d0e1 | 7 | ui = pages.UIs[name] |
ef8a4598 | 8 | if debug: |
01a3d0e1 | 9 | x = [pages.JS_BASE, ui.get("extra", []), pages.DEBUG, ["debug/ui/frontends/%s" % y for y in ui["uifiles"]]] |
7c4c581c | 10 | hgid = "" |
ef8a4598 | 11 | else: |
60ce7bee CP |
12 | #x = [pages.JS_BASE, ui.get("buildextra", ui.get("extra", [])), pages.BUILD_BASE, name] |
13 | x = [name] | |
7c4c581c CP |
14 | hgid = "-" + gethgid() |
15 | ||
16 | return list("js/%s%s.js" % (y, hgid) for y in pages.flatten(x)) | |
ef8a4598 | 17 | |
60ce7bee CP |
18 | def csslist(name, debug, gen=False): |
19 | if not debug: | |
7c4c581c | 20 | return ["css/%s-%s.css" % (name, gethgid())] |
01a3d0e1 | 21 | ui = pages.UIs[name] |
60ce7bee | 22 | return list("css/%s%s.css" % ("debug/" if gen else "", x) for x in pages.flatten([ui.get("extracss", []), "colours", "dialogs", "%s" % name])) |
ef8a4598 | 23 | |
a21fb915 CP |
24 | def _gethgid(): |
25 | try: | |
26 | p = subprocess.Popen(["hg", "id"], stdout=subprocess.PIPE) | |
27 | except Exception, e: | |
28 | if hasattr(e, "errno") and e.errno == 2: | |
29 | raise HGException, "unable to execute" | |
30 | ||
31 | data = p.communicate()[0] | |
32 | if p.wait() != 0: | |
33 | raise HGException, "unable to get id" | |
34 | return re.match("^([0-9a-f]+).*", data).group(1) | |
35 | ||
7c4c581c CP |
36 | HGID = None |
37 | def gethgid(): | |
38 | global HGID | |
39 | if HGID is None: | |
a21fb915 CP |
40 | try: |
41 | HGID = _gethgid() | |
42 | except HGException, e: | |
43 | print >>sys.stderr, "warning: hg: %s (using a random id)." % e | |
44 | HGID = os.urandom(10).encode("hex") | |
7c4c581c | 45 | return HGID |
a21fb915 | 46 | |
ef8a4598 | 47 | def producehtml(name, debug): |
01a3d0e1 | 48 | ui = pages.UIs[name] |
ef8a4598 | 49 | js = jslist(name, debug) |
1e9c8714 | 50 | css = csslist(name, debug, gen=True) |
8a56ed4c | 51 | csshtml = "\n".join(" <link rel=\"stylesheet\" href=\"%s\" type=\"text/css\"/>" % x for x in css) |
ef8a4598 CP |
52 | jshtml = "\n".join(" <script type=\"text/javascript\" src=\"%s\"></script>" % x for x in js) |
53 | ||
54 | div = ui.get("div", "") | |
55 | customjs = ui.get("customjs", "") | |
56 | ||
57 | return """%s | |
8a56ed4c | 58 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
ef8a4598 CP |
59 | <head> |
60 | <title>QuakeNet Web IRC</title> | |
8a56ed4c CP |
61 | <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> |
62 | <link rel="icon" type="image/png" href="images/favicon.png"/> | |
ef8a4598 CP |
63 | %s%s |
64 | %s | |
65 | <script type="text/javascript"> | |
66 | var ui = new qwebirc.ui.Interface("ircui", qwebirc.ui.%s); | |
67 | </script> | |
68 | </head> | |
69 | <body> | |
0b638f3c CP |
70 | <div id="ircui"> |
71 | <noscript> | |
72 | <div id="noscript">Javascript is required to use IRC.</div> | |
73 | </noscript>%s | |
ef8a4598 CP |
74 | </div> |
75 | </body> | |
76 | </html> | |
77 | """ % (ui["doctype"], csshtml, customjs, jshtml, ui["class"], div) | |
78 | ||
60ce7bee | 79 | def main(outputdir=".", produce_debug=True): |
01a3d0e1 CP |
80 | p = os.path.join(outputdir, "static") |
81 | for x in pages.UIs: | |
60ce7bee CP |
82 | if produce_debug: |
83 | f = open(os.path.join(p, "%sdebug.html" % x), "wb") | |
84 | try: | |
85 | f.write(producehtml(x, debug=True)) | |
86 | finally: | |
87 | f.close() | |
ef8a4598 CP |
88 | |
89 | f = open(os.path.join(p, "%s.html" % x), "wb") | |
90 | try: | |
91 | f.write(producehtml(x, debug=False)) | |
92 | finally: | |
93 | f.close() | |
94 | ||
95 | if __name__ == "__main__": | |
96 | main() | |
97 |