]> jfr.im git - irc/quakenet/qwebirc.git/blame - bin/pagegen.py
tidy up autobahn support -- now requires 0.17.2
[irc/quakenet/qwebirc.git] / bin / pagegen.py
CommitLineData
b4b23628 1import os, sys, pages, subprocess, re, optionsgen, config
ef8a4598 2
ab2c1ee9 3class GitException(Exception):
a21fb915
CP
4 pass
5
ef8a4598 6def jslist(name, debug):
01a3d0e1 7 ui = pages.UIs[name]
ef8a4598 8 if debug:
40296624 9 x = [pages.JS_DEBUG_BASE, ui.get("extra", []), pages.DEBUG, ["debug/ui/frontends/%s" % y for y in ui["uifiles"]]]
ab2c1ee9 10 gitid = ""
ef8a4598 11 else:
60ce7bee 12 #x = [pages.JS_BASE, ui.get("buildextra", ui.get("extra", [])), pages.BUILD_BASE, name]
40296624 13 x = [pages.JS_RAW_BASE, name]
ab2c1ee9 14 gitid = "-" + getgitid()
7c4c581c 15
ab2c1ee9 16 return list(y if y.startswith("//") else "js/%s%s.js" % (y, gitid) 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:
ab2c1ee9 22 return ["css/%s-%s.css" % (name, getgitid())]
614427b2 23 css = list(pages.flatten([ui.get("extracss", []), "colours", "dialogs"]))
4dd199c3 24 if not nocss:
614427b2
CP
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)
ef8a4598 30
ab2c1ee9 31def _getgitid():
a21fb915 32 try:
ab2c1ee9 33 p = subprocess.Popen(["git", "rev-parse", "HEAD"], stdout=subprocess.PIPE, shell=os.name == "nt")
a21fb915
CP
34 except Exception, e:
35 if hasattr(e, "errno") and e.errno == 2:
ab2c1ee9
CP
36 raise GitException, "unable to execute"
37 raise GitException, "unknown exception running git: %s" % repr(e)
5128c475 38
a21fb915
CP
39 data = p.communicate()[0]
40 if p.wait() != 0:
ab2c1ee9 41 raise GitException, "unable to get id"
a21fb915
CP
42 return re.match("^([0-9a-f]+).*", data).group(1)
43
ab2c1ee9
CP
44GITID = None
45def getgitid():
46 global GITID
47 if GITID is None:
a21fb915 48 try:
ab2c1ee9
CP
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
a21fb915 54
ef8a4598 55def producehtml(name, debug):
01a3d0e1 56 ui = pages.UIs[name]
ef8a4598 57 js = jslist(name, debug)
1e9c8714 58 css = csslist(name, debug, gen=True)
fbe5af77 59 csshtml = "\n".join(" <link rel=\"stylesheet\" href=\"%s%s\" type=\"text/css\"/>" % (config.STATIC_BASE_URL, x) for x in css)
40296624 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)
ef8a4598 61
d47f88d9
CP
62 if hasattr(config, "ANALYTICS_HTML"):
63 jshtml+="\n" + config.ANALYTICS_HTML
64
ef8a4598
CP
65 div = ui.get("div", "")
66 customjs = ui.get("customjs", "")
67
68 return """%s
8a56ed4c 69<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
ef8a4598 70<head>
fbe5af77 71 <base />
b4b23628 72 <title>%s (qwebirc)</title>
8a56ed4c 73 <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
31cf69da 74 <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />
09eb051b
CP
75 <meta name="mobile-web-app-capable" content="yes" />
76 <link rel="icon" sizes="192x192" href="%simages/highresicon.png"/>
0e4aa757 77 <link rel="shortcut icon" type="image/png" href="%simages/favicon.png"/>
9a4de2c9 78%s<script type="text/javascript">QWEBIRC_DEBUG=%s;</script>%s
ef8a4598
CP
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>
74ee64b3 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)
ef8a4598 93
60ce7bee 94def 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
110if __name__ == "__main__":
111 main()
5128c475 112