]>
jfr.im git - irc/quakenet/qwebirc.git/blob - bin/pagegen.py
1 import os
, sys
, pages
, subprocess
, re
, optionsgen
, config
3 class HGException(Exception):
6 def jslist(name
, debug
):
9 x
= [pages
.JS_BASE
, ui
.get("extra", []), pages
.DEBUG
, ["debug/ui/frontends/%s" % y
for y
in ui
["uifiles"]]]
12 #x = [pages.JS_BASE, ui.get("buildextra", ui.get("extra", [])), pages.BUILD_BASE, name]
14 hgid
= "-" + gethgid()
16 return list("js/%s%s.js" % (y
, hgid
) for y
in pages
.flatten(x
))
18 def csslist(name
, debug
, gen
=False):
20 return ["css/%s-%s.css" % (name
, gethgid())]
22 return list("css/%s%s.css" % ("debug/" if gen
else "", x
) for x
in pages
.flatten([ui
.get("extracss", []), "colours", "dialogs", "%s" % name
]))
26 p
= subprocess
.Popen(["hg", "id"], stdout
=subprocess
.PIPE
)
28 if hasattr(e
, "errno") and e
.errno
== 2:
29 raise HGException
, "unable to execute"
31 data
= p
.communicate()[0]
33 raise HGException
, "unable to get id"
34 return re
.match("^([0-9a-f]+).*", data
).group(1)
42 except HGException
, e
:
43 print >>sys
.stderr
, "warning: hg: %s (using a random id)." % e
44 HGID
= os
.urandom(10).encode("hex")
47 def producehtml(name
, debug
):
49 js
= jslist(name
, debug
)
50 css
= csslist(name
, debug
, gen
=True)
51 csshtml
= "\n".join(" <link rel=\"stylesheet\" href=\"%s\" type=\"text/css\"/>" % x
for x
in css
)
52 jshtml
= "\n".join(" <script type=\"text/javascript\" src=\"%s\"></script>" % x
for x
in js
)
54 div
= ui
.get("div", "")
55 customjs
= ui
.get("customjs", "")
58 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
60 <title>%s (qwebirc)</title>
61 <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
62 <link rel="icon" type="image/png" href="images/favicon.png"/>
65 <script type="text/javascript">
66 var ui = new qwebirc.ui.Interface("ircui", qwebirc.ui.%s, %s);
72 <div id="noscript">Javascript is required to use IRC.</div>
77 """ % (ui
["doctype"], config
.APP_TITLE
, csshtml
, customjs
, jshtml
, ui
["class"], optionsgen
.get_options(), div
)
79 def main(outputdir
=".", produce_debug
=True):
80 p
= os
.path
.join(outputdir
, "static")
83 f
= open(os
.path
.join(p
, "%sdebug.html" % x
), "wb")
85 f
.write(producehtml(x
, debug
=True))
89 f
= open(os
.path
.join(p
, "%s.html" % x
), "wb")
91 f
.write(producehtml(x
, debug
=False))
95 if __name__
== "__main__":