]>
jfr.im git - irc/quakenet/qwebirc.git/blob - bin/pagegen.py
1 import os
, sys
, pages
, subprocess
, re
, optionsgen
, config
3 class GitException(Exception):
6 def jslist(name
, debug
):
9 x
= [pages
.JS_DEBUG_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]
13 x
= [pages
.JS_RAW_BASE
, name
]
14 gitid
= "-" + getgitid()
16 return list(y
if y
.startswith("//") else "js/%s%s.js" % (y
, gitid
) for y
in pages
.flatten(x
))
18 def csslist(name
, debug
, gen
=False):
20 nocss
= ui
.get("nocss")
22 return ["css/%s-%s.css" % (name
, getgitid())]
23 css
= list(pages
.flatten([ui
.get("extracss", []), "colours", "dialogs"]))
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
)
33 p
= subprocess
.Popen(["git", "rev-parse", "HEAD"], stdout
=subprocess
.PIPE
, shell
=os
.name
== "nt")
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
)
39 data
= p
.communicate()[0]
41 raise GitException
, "unable to get id"
42 return re
.match("^([0-9a-f]+).*", data
).group(1)
50 except GitException
, e
:
51 print >>sys
.stderr
, "warning: git: %s (using a random id)." % e
52 GITID
= os
.urandom(10).encode("hex")
55 def producehtml(name
, debug
):
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
)
62 if hasattr(config
, "ANALYTICS_HTML"):
63 jshtml
+="\n" + config
.ANALYTICS_HTML
65 div
= ui
.get("div", "")
66 customjs
= ui
.get("customjs", "")
69 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
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
80 <script type="text/javascript">
81 var ui = new qwebirc.ui.Interface("ircui", qwebirc.ui.%s, %s);
87 <div id="noscript">Javascript is required to use IRC.</div>
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
)
94 def main(outputdir
=".", produce_debug
=True):
95 p
= os
.path
.join(outputdir
, "static")
98 f
= open(os
.path
.join(p
, "%sdebug.html" % x
), "wb")
100 f
.write(producehtml(x
, debug
=True))
104 f
= open(os
.path
.join(p
, "%s.html" % x
), "wb")
106 f
.write(producehtml(x
, debug
=False))
110 if __name__
== "__main__":