X-Git-Url: https://jfr.im/git/irc/quakenet/qwebirc.git/blobdiff_plain/7c4c581ccb2f4b299a8336e7e6caef8830139231..31cf69da711d788e330a44d20e29ce901615d13c:/bin/pagegen.py diff --git a/bin/pagegen.py b/bin/pagegen.py old mode 100644 new mode 100755 index 7ae2475..a4b9f5d --- a/bin/pagegen.py +++ b/bin/pagegen.py @@ -1,5 +1,8 @@ -import os, sys, pages, subprocess, re +import os, sys, pages, subprocess, re, optionsgen, config +class HGException(Exception): + pass + def jslist(name, debug): ui = pages.UIs[name] if debug: @@ -13,25 +16,48 @@ def jslist(name, debug): return list("js/%s%s.js" % (y, hgid) for y in pages.flatten(x)) def csslist(name, debug, gen=False): + ui = pages.UIs[name] + nocss = ui.get("nocss") if not debug: return ["css/%s-%s.css" % (name, gethgid())] - ui = pages.UIs[name] - return list("css/%s%s.css" % ("debug/" if gen else "", x) for x in pages.flatten([ui.get("extracss", []), "colours", "dialogs", "%s" % name])) + css = pages.flatten([ui.get("extracss", []), "colours", "dialogs"]) + if not nocss: + css = list(css) + [name] + return list("css/%s%s.css" % ("debug/" if gen else "", x) for x in css) + +def _gethgid(): + try: + p = subprocess.Popen(["hg", "id"], stdout=subprocess.PIPE, shell=os.name == "nt") + except Exception, e: + if hasattr(e, "errno") and e.errno == 2: + raise HGException, "unable to execute" + raise HGException, "unknown exception running hg: %s" % repr(e) + + data = p.communicate()[0] + if p.wait() != 0: + raise HGException, "unable to get id" + return re.match("^([0-9a-f]+).*", data).group(1) HGID = None def gethgid(): global HGID if HGID is None: - hgid = subprocess.Popen(["hg", "id"], stdout=subprocess.PIPE).communicate()[0] - HGID = re.match("^([0-9a-f]+).*", hgid).group(1) + try: + HGID = _gethgid() + except HGException, e: + print >>sys.stderr, "warning: hg: %s (using a random id)." % e + HGID = os.urandom(10).encode("hex") return HGID - + def producehtml(name, debug): ui = pages.UIs[name] js = jslist(name, debug) css = csslist(name, debug, gen=True) - csshtml = "\n".join(" " % x for x in css) - jshtml = "\n".join(" " % x for x in js) + csshtml = "\n".join(" " % (config.STATIC_BASE_URL, x) for x in css) + jshtml = "\n".join(" " % (config.STATIC_BASE_URL, x) for x in js) + + if hasattr(config, "ANALYTICS_HTML"): + jshtml+="\n" + config.ANALYTICS_HTML div = ui.get("div", "") customjs = ui.get("customjs", "") @@ -39,13 +65,15 @@ def producehtml(name, debug): return """%s - QuakeNet Web IRC + + %s (qwebirc) - + + %s%s %s @@ -56,7 +84,7 @@ def producehtml(name, debug): -""" % (ui["doctype"], csshtml, customjs, jshtml, ui["class"], div) +""" % (ui["doctype"], config.APP_TITLE, config.STATIC_BASE_URL, csshtml, customjs, jshtml, ui["class"], optionsgen.get_options(), div) def main(outputdir=".", produce_debug=True): p = os.path.join(outputdir, "static") @@ -76,4 +104,4 @@ def main(outputdir=".", produce_debug=True): if __name__ == "__main__": main() - \ No newline at end of file +