]> jfr.im git - irc/quakenet/qwebirc.git/blame - bin/pagegen.py
Executable bit on run.py got lost somehow.
[irc/quakenet/qwebirc.git] / bin / pagegen.py
CommitLineData
b4b23628 1import os, sys, pages, subprocess, re, optionsgen, config
ef8a4598 2
a21fb915
CP
3class HGException(Exception):
4 pass
5
ef8a4598 6def 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 18def 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
28def _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"
34
35 data = p.communicate()[0]
36 if p.wait() != 0:
37 raise HGException, "unable to get id"
38 return re.match("^([0-9a-f]+).*", data).group(1)
39
7c4c581c
CP
40HGID = None
41def gethgid():
42 global HGID
43 if HGID is None:
a21fb915
CP
44 try:
45 HGID = _gethgid()
46 except HGException, e:
47 print >>sys.stderr, "warning: hg: %s (using a random id)." % e
48 HGID = os.urandom(10).encode("hex")
7c4c581c 49 return HGID
a21fb915 50
ef8a4598 51def producehtml(name, debug):
01a3d0e1 52 ui = pages.UIs[name]
ef8a4598 53 js = jslist(name, debug)
1e9c8714 54 css = csslist(name, debug, gen=True)
8a56ed4c 55 csshtml = "\n".join(" <link rel=\"stylesheet\" href=\"%s\" type=\"text/css\"/>" % x for x in css)
ef8a4598
CP
56 jshtml = "\n".join(" <script type=\"text/javascript\" src=\"%s\"></script>" % x for x in js)
57
58 div = ui.get("div", "")
59 customjs = ui.get("customjs", "")
60
61 return """%s
8a56ed4c 62<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
ef8a4598 63<head>
b4b23628 64 <title>%s (qwebirc)</title>
8a56ed4c
CP
65 <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
66 <link rel="icon" type="image/png" href="images/favicon.png"/>
ef8a4598
CP
67%s%s
68%s
69 <script type="text/javascript">
348574ee 70 var ui = new qwebirc.ui.Interface("ircui", qwebirc.ui.%s, %s);
ef8a4598
CP
71 </script>
72</head>
73<body>
0b638f3c
CP
74 <div id="ircui">
75 <noscript>
76 <div id="noscript">Javascript is required to use IRC.</div>
77 </noscript>%s
ef8a4598
CP
78 </div>
79</body>
80</html>
b4b23628 81""" % (ui["doctype"], config.APP_TITLE, csshtml, customjs, jshtml, ui["class"], optionsgen.get_options(), div)
ef8a4598 82
60ce7bee 83def main(outputdir=".", produce_debug=True):
01a3d0e1
CP
84 p = os.path.join(outputdir, "static")
85 for x in pages.UIs:
60ce7bee
CP
86 if produce_debug:
87 f = open(os.path.join(p, "%sdebug.html" % x), "wb")
88 try:
89 f.write(producehtml(x, debug=True))
90 finally:
91 f.close()
ef8a4598
CP
92
93 f = open(os.path.join(p, "%s.html" % x), "wb")
94 try:
95 f.write(producehtml(x, debug=False))
96 finally:
97 f.close()
98
99if __name__ == "__main__":
100 main()
101