]>
Commit | Line | Data |
---|---|---|
1 | import os, sys, pages, subprocess, re, optionsgen, config | |
2 | ||
3 | class GitException(Exception): | |
4 | pass | |
5 | ||
6 | def jslist(name, debug): | |
7 | ui = pages.UIs[name] | |
8 | if debug: | |
9 | x = [pages.JS_DEBUG_BASE, ui.get("extra", []), pages.DEBUG, ["debug/ui/frontends/%s" % y for y in ui["uifiles"]]] | |
10 | gitid = "" | |
11 | else: | |
12 | #x = [pages.JS_BASE, ui.get("buildextra", ui.get("extra", [])), pages.BUILD_BASE, name] | |
13 | x = [pages.JS_RAW_BASE, name] | |
14 | gitid = "-" + getgitid() | |
15 | ||
16 | return list(y if y.startswith("//") else "js/%s%s.js" % (y, gitid) for y in pages.flatten(x)) | |
17 | ||
18 | def csslist(name, debug, gen=False): | |
19 | ui = pages.UIs[name] | |
20 | nocss = ui.get("nocss") | |
21 | if not debug: | |
22 | return ["css/%s-%s.css" % (name, getgitid())] | |
23 | css = list(pages.flatten([ui.get("extracss", []), "colours", "dialogs"])) | |
24 | if not nocss: | |
25 | css+=[name] | |
26 | css = ["%s.css" % x for x in css] | |
27 | if hasattr(config, "CUSTOM_CSS"): | |
28 | css+=[config.CUSTOM_CSS] | |
29 | return list("css/%s%s" % ("debug/" if gen else "", x) for x in css) | |
30 | ||
31 | def _getgitid(): | |
32 | try: | |
33 | p = subprocess.Popen(["git", "rev-parse", "HEAD"], stdout=subprocess.PIPE, shell=os.name == "nt") | |
34 | except Exception, e: | |
35 | if hasattr(e, "errno") and e.errno == 2: | |
36 | raise GitException, "unable to execute" | |
37 | raise GitException, "unknown exception running git: %s" % repr(e) | |
38 | ||
39 | data = p.communicate()[0] | |
40 | if p.wait() != 0: | |
41 | raise GitException, "unable to get id" | |
42 | return re.match("^([0-9a-f]+).*", data).group(1) | |
43 | ||
44 | GITID = None | |
45 | def getgitid(): | |
46 | global GITID | |
47 | if GITID is None: | |
48 | try: | |
49 | GITID = _getgitid() | |
50 | except GitException, e: | |
51 | print >>sys.stderr, "warning: git: %s (using a random id)." % e | |
52 | GITID = os.urandom(10).encode("hex") | |
53 | return GITID | |
54 | ||
55 | def producehtml(name, debug): | |
56 | ui = pages.UIs[name] | |
57 | js = jslist(name, debug) | |
58 | css = csslist(name, debug, gen=True) | |
59 | csshtml = "\n".join(" <link rel=\"stylesheet\" href=\"%s%s\" type=\"text/css\"/>" % (config.STATIC_BASE_URL, x) for x in css) | |
60 | jshtml = "\n".join(" <script type=\"text/javascript\" src=\"%s%s\"></script>" % ("" if x.startswith("//") else config.STATIC_BASE_URL, x) for x in js) | |
61 | ||
62 | if hasattr(config, "ANALYTICS_HTML"): | |
63 | jshtml+="\n" + config.ANALYTICS_HTML | |
64 | ||
65 | div = ui.get("div", "") | |
66 | customjs = ui.get("customjs", "") | |
67 | ||
68 | return """%s | |
69 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | |
70 | <head> | |
71 | <base /> | |
72 | <title>%s (qwebirc)</title> | |
73 | <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> | |
74 | <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" /> | |
75 | <meta name="mobile-web-app-capable" content="yes" /> | |
76 | <link rel="icon" sizes="192x192" href="%simages/highresicon.png"/> | |
77 | <link rel="shortcut icon" type="image/png" href="%simages/favicon.png"/> | |
78 | %s<script type="text/javascript">QWEBIRC_DEBUG=%s;</script>%s | |
79 | %s | |
80 | <script type="text/javascript"> | |
81 | var ui = new qwebirc.ui.Interface("ircui", qwebirc.ui.%s, %s); | |
82 | </script> | |
83 | </head> | |
84 | <body> | |
85 | <div id="ircui"> | |
86 | <noscript> | |
87 | <div id="noscript">Javascript is required to use IRC.</div> | |
88 | </noscript>%s | |
89 | </div> | |
90 | </body> | |
91 | </html> | |
92 | """ % (ui["doctype"], config.APP_TITLE, config.STATIC_BASE_URL, config.STATIC_BASE_URL, csshtml, debug and "true" or "false", customjs, jshtml, ui["class"], optionsgen.get_options(), div) | |
93 | ||
94 | def main(outputdir=".", produce_debug=True): | |
95 | p = os.path.join(outputdir, "static") | |
96 | for x in pages.UIs: | |
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() | |
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() | |
112 |