]> jfr.im git - irc/quakenet/qwebirc.git/blob - bin/pagegen.py
Make scripts executable.
[irc/quakenet/qwebirc.git] / bin / pagegen.py
1 import os, sys, pages, subprocess, re
2
3 def jslist(name, debug):
4 ui = pages.UIs[name]
5 if debug:
6 x = [pages.JS_BASE, ui.get("extra", []), pages.DEBUG, ["debug/ui/frontends/%s" % y for y in ui["uifiles"]]]
7 hgid = ""
8 else:
9 #x = [pages.JS_BASE, ui.get("buildextra", ui.get("extra", [])), pages.BUILD_BASE, name]
10 x = [name]
11 hgid = "-" + gethgid()
12
13 return list("js/%s%s.js" % (y, hgid) for y in pages.flatten(x))
14
15 def csslist(name, debug, gen=False):
16 if not debug:
17 return ["css/%s-%s.css" % (name, gethgid())]
18 ui = pages.UIs[name]
19 return list("css/%s%s.css" % ("debug/" if gen else "", x) for x in pages.flatten([ui.get("extracss", []), "colours", "dialogs", "%s" % name]))
20
21 HGID = None
22 def gethgid():
23 global HGID
24 if HGID is None:
25 hgid = subprocess.Popen(["hg", "id"], stdout=subprocess.PIPE).communicate()[0]
26 HGID = re.match("^([0-9a-f]+).*", hgid).group(1)
27 return HGID
28
29 def producehtml(name, debug):
30 ui = pages.UIs[name]
31 js = jslist(name, debug)
32 css = csslist(name, debug, gen=True)
33 csshtml = "\n".join(" <link rel=\"stylesheet\" href=\"%s\" type=\"text/css\"/>" % x for x in css)
34 jshtml = "\n".join(" <script type=\"text/javascript\" src=\"%s\"></script>" % x for x in js)
35
36 div = ui.get("div", "")
37 customjs = ui.get("customjs", "")
38
39 return """%s
40 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
41 <head>
42 <title>QuakeNet Web IRC</title>
43 <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
44 <link rel="icon" type="image/png" href="images/favicon.png"/>
45 %s%s
46 %s
47 <script type="text/javascript">
48 var ui = new qwebirc.ui.Interface("ircui", qwebirc.ui.%s);
49 </script>
50 </head>
51 <body>
52 <div id="ircui">
53 <noscript>
54 <div id="noscript">Javascript is required to use IRC.</div>
55 </noscript>%s
56 </div>
57 </body>
58 </html>
59 """ % (ui["doctype"], csshtml, customjs, jshtml, ui["class"], div)
60
61 def main(outputdir=".", produce_debug=True):
62 p = os.path.join(outputdir, "static")
63 for x in pages.UIs:
64 if produce_debug:
65 f = open(os.path.join(p, "%sdebug.html" % x), "wb")
66 try:
67 f.write(producehtml(x, debug=True))
68 finally:
69 f.close()
70
71 f = open(os.path.join(p, "%s.html" % x), "wb")
72 try:
73 f.write(producehtml(x, debug=False))
74 finally:
75 f.close()
76
77 if __name__ == "__main__":
78 main()
79