]>
Commit | Line | Data |
---|---|---|
b4b23628 | 1 | import os, sys, pages, subprocess, re, optionsgen, config |
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 | 18 | def csslist(name, debug, gen=False): |
4dd199c3 CP |
19 | ui = pages.UIs[name] |
20 | nocss = ui.get("nocss") | |
60ce7bee | 21 | if not debug: |
7c4c581c | 22 | return ["css/%s-%s.css" % (name, gethgid())] |
4dd199c3 CP |
23 | css = pages.flatten([ui.get("extracss", []), "colours", "dialogs"]) |
24 | if not nocss: | |
25 | css = list(css) + [name] | |
26 | return list("css/%s%s.css" % ("debug/" if gen else "", x) for x in css) | |
ef8a4598 | 27 | |
a21fb915 CP |
28 | def _gethgid(): |
29 | try: | |
30 | p = subprocess.Popen(["hg", "id"], stdout=subprocess.PIPE) | |
31 | except Exception, e: | |
32 | if hasattr(e, "errno") and e.errno == 2: | |
33 | raise HGException, "unable to execute" | |
5128c475 CP |
34 | raise HGException, "unknown exception running hg: %s" % repr(e) |
35 | ||
a21fb915 CP |
36 | data = p.communicate()[0] |
37 | if p.wait() != 0: | |
38 | raise HGException, "unable to get id" | |
39 | return re.match("^([0-9a-f]+).*", data).group(1) | |
40 | ||
7c4c581c CP |
41 | HGID = None |
42 | def gethgid(): | |
43 | global HGID | |
44 | if HGID is None: | |
a21fb915 CP |
45 | try: |
46 | HGID = _gethgid() | |
47 | except HGException, e: | |
48 | print >>sys.stderr, "warning: hg: %s (using a random id)." % e | |
49 | HGID = os.urandom(10).encode("hex") | |
7c4c581c | 50 | return HGID |
a21fb915 | 51 | |
ef8a4598 | 52 | def producehtml(name, debug): |
01a3d0e1 | 53 | ui = pages.UIs[name] |
ef8a4598 | 54 | js = jslist(name, debug) |
1e9c8714 | 55 | css = csslist(name, debug, gen=True) |
fbe5af77 CP |
56 | csshtml = "\n".join(" <link rel=\"stylesheet\" href=\"%s%s\" type=\"text/css\"/>" % (config.STATIC_BASE_URL, x) for x in css) |
57 | jshtml = "\n".join(" <script type=\"text/javascript\" src=\"%s%s\"></script>" % (config.STATIC_BASE_URL, x) for x in js) | |
ef8a4598 | 58 | |
d47f88d9 CP |
59 | if hasattr(config, "ANALYTICS_HTML"): |
60 | jshtml+="\n" + config.ANALYTICS_HTML | |
61 | ||
ef8a4598 CP |
62 | div = ui.get("div", "") |
63 | customjs = ui.get("customjs", "") | |
64 | ||
97fd8c3a CP |
65 | if debug: |
66 | customjs = """<script type="text/javascript"> | |
67 | QWEBIRC_DEBUG = true; | |
68 | </script> | |
69 | """ + customjs | |
70 | ||
ef8a4598 | 71 | return """%s |
8a56ed4c | 72 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
ef8a4598 | 73 | <head> |
fbe5af77 | 74 | <base /> |
b4b23628 | 75 | <title>%s (qwebirc)</title> |
8a56ed4c | 76 | <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> |
0e4aa757 | 77 | <link rel="shortcut icon" type="image/png" href="%simages/favicon.png"/> |
ef8a4598 CP |
78 | %s%s |
79 | %s | |
80 | <script type="text/javascript"> | |
348574ee | 81 | var ui = new qwebirc.ui.Interface("ircui", qwebirc.ui.%s, %s); |
ef8a4598 CP |
82 | </script> |
83 | </head> | |
84 | <body> | |
0b638f3c CP |
85 | <div id="ircui"> |
86 | <noscript> | |
87 | <div id="noscript">Javascript is required to use IRC.</div> | |
88 | </noscript>%s | |
ef8a4598 CP |
89 | </div> |
90 | </body> | |
91 | </html> | |
fbe5af77 | 92 | """ % (ui["doctype"], config.APP_TITLE, config.STATIC_BASE_URL, csshtml, customjs, jshtml, ui["class"], optionsgen.get_options(), div) |
ef8a4598 | 93 | |
60ce7bee | 94 | def main(outputdir=".", produce_debug=True): |
01a3d0e1 CP |
95 | p = os.path.join(outputdir, "static") |
96 | for x in pages.UIs: | |
60ce7bee CP |
97 | if produce_debug: |
98 | f = open(os.path.join(p, "%sdebug.html" % x), "wb") | |
99 | try: | |
100 | f.write(producehtml(x, debug=True)) | |
101 | finally: | |
102 | f.close() | |
ef8a4598 CP |
103 | |
104 | f = open(os.path.join(p, "%s.html" % x), "wb") | |
105 | try: | |
106 | f.write(producehtml(x, debug=False)) | |
107 | finally: | |
108 | f.close() | |
109 | ||
110 | if __name__ == "__main__": | |
111 | main() | |
5128c475 | 112 |