]> jfr.im git - irc/quakenet/qwebirc.git/commitdiff
Now we don't *need* java or hg, though both are still useful.
authorChris Porter <redacted>
Wed, 18 Mar 2009 23:14:23 +0000 (23:14 +0000)
committerChris Porter <redacted>
Wed, 18 Mar 2009 23:14:23 +0000 (23:14 +0000)
bin/compile.py
bin/pagegen.py

index 018be551e8597894717b2a21f1921efde813d825..cbe0255a3d519072cd7c828586c82272474ad8ff 100644 (file)
@@ -1,17 +1,40 @@
 #!/usr/bin/env python
-import pages, os, subprocess, pagegen, shutil
+import pages, os, subprocess, pagegen, shutil, sys
 
 COPYRIGHT = open("js/copyright.js", "rb").read()
 
+class MinifyException(Exception):
+  pass
+  
 def jarit(src):
-  return subprocess.Popen(["java", "-jar", "bin/yuicompressor-2.3.5.jar", src], stdout=subprocess.PIPE).communicate()[0]
+  try:
+    p = subprocess.Popen(["java", "-jar", "bin/yuicompressor-2.3.5.jar", src], stdout=subprocess.PIPE)
+  except Exception, e:
+    if hasattr(e, "errno") and e.errno == 2:
+      raise MinifyException, "unable to run java"
+    raise
+  data = p.communicate()[0]
+  if p.wait() != 0:
+    raise MinifyException, "an error occured"
+  return data
 
+JAVA_WARNING_SURPRESSED = False
 def jmerge_files(prefix, suffix, output, files, *args):
   global COPYRIGHT
   output = output + "." + suffix
   o = os.path.join(prefix, "compiled", output)
   merge_files(o, files, *args)
-  compiled = jarit(o)
+  
+  # cough hack
+  compiled = open(o, "rb").read()
+  try:
+    compiled = jarit(o)
+  except MinifyException, e:
+    global JAVA_WARNING_SURPRESSED
+    if not JAVA_WARNING_SURPRESSED:
+      JAVA_WARNING_SURPRESSED = True
+      print >>sys.stderr, "warning: minify: %s (not minifying -- javascript will be HUGE)." % e
+
   os.unlink(o)
   f = open(os.path.join(prefix, "static", suffix, output), "wb")
   f.write(COPYRIGHT)
index 7ae247591f9d82a00cff12a01e14e72a6045b59b..e183dcd0580ab043cb1c941e43fb3667446ae17f 100755 (executable)
@@ -1,5 +1,8 @@
 import os, sys, pages, subprocess, re
 
+class HGException(Exception):
+  pass
+  
 def jslist(name, debug):
   ui = pages.UIs[name]
   if debug:
@@ -18,14 +21,29 @@ def csslist(name, debug, gen=False):
   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]))
 
+def _gethgid():
+  try:
+    p = subprocess.Popen(["hg", "id"], stdout=subprocess.PIPE)
+  except Exception, e:
+    if hasattr(e, "errno") and e.errno == 2:
+      raise HGException, "unable to execute"
+      
+  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)