]>
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()
17 for url
in pages
.flatten(x
):
18 if isinstance(url
, tuple):
22 l
.append((url
if url
.startswith("//") else "js/%s%s.js" % (url
, gitid
), digest
))
25 def csslist(name
, debug
, gen
=False):
27 nocss
= ui
.get("nocss")
29 return ["css/%s-%s.css" % (name
, getgitid())]
30 css
= list(pages
.flatten([ui
.get("extracss", []), "colours", "dialogs"]))
33 css
= ["%s.css" % x
for x
in css
]
34 if hasattr(config
, "CUSTOM_CSS"):
35 css
+=[config
.CUSTOM_CSS
]
36 return list("css/%s%s" % ("debug/" if gen
else "", x
) for x
in css
)
40 p
= subprocess
.Popen(["git", "rev-parse", "HEAD"], stdout
=subprocess
.PIPE
, shell
=os
.name
== "nt")
42 if hasattr(e
, "errno") and e
.errno
== 2:
43 raise GitException
, "unable to execute"
44 raise GitException
, "unknown exception running git: %s" % repr(e
)
46 data
= p
.communicate()[0]
48 raise GitException
, "unable to get id"
49 return re
.match("^([0-9a-f]+).*", data
).group(1)
57 except GitException
, e
:
58 print >>sys
.stderr
, "warning: git: %s (using a random id)." % e
59 GITID
= os
.urandom(10).encode("hex")
62 def producehtml(name
, debug
):
64 js
= jslist(name
, debug
)
65 css
= csslist(name
, debug
, gen
=True)
66 csshtml
= "\n".join(" <link rel=\"stylesheet\" href=\"%s%s\" type=\"text/css\"/>" % (config
.STATIC_BASE_URL
, x
) for x
in css
)
68 def toscript((url
, digest
)):
70 subresource_int
= " integrity=\"%s\" crossorigin=\"anonymous\"" % digest
73 return " <script type=\"text/javascript\" src=\"%s%s\"%s></script>" % ("" if url
.startswith("//") else config
.STATIC_BASE_URL
, url
, subresource_int
)
75 jshtml
= "\n".join(toscript(x
) for x
in js
)
77 if hasattr(config
, "ANALYTICS_HTML"):
78 jshtml
+="\n" + config
.ANALYTICS_HTML
80 div
= ui
.get("div", "")
81 customjs
= ui
.get("customjs", "")
84 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
87 <title>%s (qwebirc)</title>
88 <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
89 <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />
90 <meta name="mobile-web-app-capable" content="yes" />
91 <link rel="icon" sizes="192x192" href="%simages/highresicon.png"/>
92 <link rel="shortcut icon" type="image/png" href="%simages/favicon.png"/>
93 %s<script type="text/javascript">QWEBIRC_DEBUG=%s;</script>%s
95 <script type="text/javascript">
96 var ui = new qwebirc.ui.Interface("ircui", qwebirc.ui.%s, %s);
102 <div id="noscript">Javascript is required to use IRC.</div>
107 """ % (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
)
109 def main(outputdir
=".", produce_debug
=True):
110 p
= os
.path
.join(outputdir
, "static")
113 f
= open(os
.path
.join(p
, "%sdebug.html" % x
), "wb")
115 f
.write(producehtml(x
, debug
=True))
119 f
= open(os
.path
.join(p
, "%s.html" % x
), "wb")
121 f
.write(producehtml(x
, debug
=False))
125 if __name__
== "__main__":