]> jfr.im git - irc/quakenet/qwebirc.git/blobdiff - bin/pagegen.py
Merge.
[irc/quakenet/qwebirc.git] / bin / pagegen.py
old mode 100644 (file)
new mode 100755 (executable)
index 5ec6a2f..7423a2b
@@ -1,25 +1,63 @@
-import os, sys, pages
+import os, sys, pages, subprocess, re, optionsgen, config
 
+class HGException(Exception):
+  pass
+  
 def jslist(name, debug):
   ui = pages.UIs[name]
   if debug:
-    x = [pages.JS_BASE, ui.get("extra", []), pages.DEBUG, ["debug/ui/frontends/%s" % y for y in ui["uifiles"]]]
+    x = [pages.JS_DEBUG_BASE, ui.get("extra", []), pages.DEBUG, ["debug/ui/frontends/%s" % y for y in ui["uifiles"]]]
+    hgid = ""
   else:
-    x = [pages.JS_BASE, ui.get("buildextra", ui.get("extra", [])), pages.BUILD_BASE, name]
-    
-  return list("js/%s.js" % y for y in pages.flatten(x))
+    #x = [pages.JS_BASE, ui.get("buildextra", ui.get("extra", [])), pages.BUILD_BASE, name]
+    x = [pages.JS_RAW_BASE, name]
+    hgid = "-" + gethgid()  
+  
+  return list(y if y.startswith("//") else "js/%s%s.js" % (y, hgid) for y in pages.flatten(x))
 
-def csslist(name):
+def csslist(name, debug, gen=False):
   ui = pages.UIs[name]
-  return list("css/%s.css" % x for x in pages.flatten([ui.get("extracss", []), "colours", "dialogs", "%s" % name]))
+  nocss = ui.get("nocss")
+  if not debug:
+    return ["css/%s-%s.css" % (name, gethgid())]
+  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:
+    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)
-  
-  csshtml = "\n".join("  <link rel=\"stylesheet\" href=\"%s\" type=\"text/css\"/>" % x for x in css)
-  jshtml = "\n".join("  <script type=\"text/javascript\" src=\"%s\"></script>" % x for x in js)
+  css = csslist(name, debug, gen=True)
+  csshtml = "\n".join("  <link rel=\"stylesheet\" href=\"%s%s\" type=\"text/css\"/>" % (config.STATIC_BASE_URL, x) for x in css)
+  jshtml = "\n".join("  <script type=\"text/javascript\" src=\"%s%s\"></script>" % ("" if x.startswith("//") else 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", "")
@@ -27,13 +65,15 @@ def producehtml(name, debug):
   return """%s
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 <head>
-  <title>QuakeNet Web IRC</title>
+  <base />
+  <title>%s (qwebirc)</title>
   <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
-  <link rel="icon" type="image/png" href="images/favicon.png"/>
-%s%s
+  <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />
+  <link rel="shortcut icon" type="image/png" href="%simages/favicon.png"/>
+%s<script type="text/javascript">QWEBIRC_DEBUG=%s;</script>%s
 %s
   <script type="text/javascript">
-    var ui = new qwebirc.ui.Interface("ircui", qwebirc.ui.%s);
+    var ui = new qwebirc.ui.Interface("ircui", qwebirc.ui.%s, %s);
   </script>
 </head>
 <body>
@@ -44,16 +84,17 @@ def producehtml(name, debug):
   </div>
 </body>
 </html>
-""" % (ui["doctype"], csshtml, customjs, jshtml, ui["class"], div)
+""" % (ui["doctype"], config.APP_TITLE, config.STATIC_BASE_URL, csshtml, debug and "true" or "false", customjs, jshtml, ui["class"], optionsgen.get_options(), div)
 
-def main(outputdir="."):
+def main(outputdir=".", produce_debug=True):
   p = os.path.join(outputdir, "static")
   for x in pages.UIs:
-    f = open(os.path.join(p, "%sdebug.html" % x), "wb")
-    try:
-      f.write(producehtml(x, debug=True))
-    finally:
-      f.close()
+    if produce_debug:
+      f = open(os.path.join(p, "%sdebug.html" % x), "wb")
+      try:
+        f.write(producehtml(x, debug=True))
+      finally:
+        f.close()
       
     f = open(os.path.join(p, "%s.html" % x), "wb")
     try:
@@ -63,4 +104,4 @@ def main(outputdir="."):
 
 if __name__ == "__main__":
   main()
-  
\ No newline at end of file
+