]> jfr.im git - irc/quakenet/qwebirc.git/blobdiff - bin/compile.py
Merge in default.
[irc/quakenet/qwebirc.git] / bin / compile.py
index cbe0255a3d519072cd7c828586c82272474ad8ff..cd71d93b34f8d830b84a0945f92cea7e2bc0129c 100644 (file)
@@ -1,5 +1,8 @@
 #!/usr/bin/env python
-import pages, os, subprocess, pagegen, shutil, sys
+import dependencies
+dependencies.vcheck()
+
+import pages, os, subprocess, pagegen, shutil, sys, time
 
 COPYRIGHT = open("js/copyright.js", "rb").read()
 
@@ -19,14 +22,13 @@ def jarit(src):
   return data
 
 JAVA_WARNING_SURPRESSED = False
-def jmerge_files(prefix, suffix, output, files, *args):
+def jmerge_files(prefix, suffix, output, files, *args, **kwargs):
   global COPYRIGHT
   output = output + "." + suffix
   o = os.path.join(prefix, "compiled", output)
   merge_files(o, files, *args)
   
   # cough hack
-  compiled = open(o, "rb").read()
   try:
     compiled = jarit(o)
   except MinifyException, e:
@@ -34,10 +36,24 @@ def jmerge_files(prefix, suffix, output, files, *args):
     if not JAVA_WARNING_SURPRESSED:
       JAVA_WARNING_SURPRESSED = True
       print >>sys.stderr, "warning: minify: %s (not minifying -- javascript will be HUGE)." % e
+    try:
+      f = open(o, "rb")
+      compiled = f.read()
+    finally:
+      f.close()
 
-  os.unlink(o)
+  try:
+    os.unlink(o)
+  except:
+    time.sleep(1) # windows sucks
+    os.unlink(o)
+    
   f = open(os.path.join(prefix, "static", suffix, output), "wb")
   f.write(COPYRIGHT)
+
+  if kwargs.get("file_prefix"):
+    f.write(kwargs.get("file_prefix"))
+    
   f.write(compiled)
   f.close()
   
@@ -72,6 +88,13 @@ def main(outputdir=".", produce_debug=True):
     csssrc = pagegen.csslist(uiname, True)
     jmerge_files(outputdir, "css", uiname + "-" + ID, csssrc)
     shutil.copy2(os.path.join(outputdir, "static", "css", uiname + "-" + ID + ".css"), os.path.join(outputdir, "static", "css", uiname + ".css"))
+    
+    mcssname = os.path.join("css", uiname + ".mcss")
+    if os.path.exists(mcssname):
+      mcssdest = os.path.join(outputdir, "static", "css", uiname + ".mcss")
+      shutil.copy2(mcssname, mcssdest)
+      shutil.copy2(mcssdest, os.path.join(outputdir, "static", "css", uiname + "-" + ID + ".mcss"))
+    
     #jmerge_files(outputdir, "js", uiname, value["uifiles"], lambda x: os.path.join("js", "ui", "frontends", x + ".js"))
     
     alljs = []
@@ -83,10 +106,37 @@ def main(outputdir=".", produce_debug=True):
       alljs.append(os.path.join("js", y + ".js"))
     for y in value["uifiles"]:
       alljs.append(os.path.join("js", "ui", "frontends", y + ".js"))
-    jmerge_files(outputdir, "js", uiname + "-" + ID, alljs)
+    jmerge_files(outputdir, "js", uiname + "-" + ID, alljs, file_prefix="QWEBIRC_BUILD=\"" + ID + "\";\n")
     
   os.rmdir(coutputdir)
   
+  f = open(".compiled", "w")
+  f.close()
+  
+def has_compiled():
+  try:
+    f = open(".compiled", "r")
+    f.close()
+    return True
+  except:
+    pass
+    
+  try:
+    f = open(os.path.join("bin", ".compiled"), "r")
+    f.close()
+    return True
+  except:
+    pass
+  
+  return False
+  
+def vcheck():
+  if has_compiled():
+    return
+    
+  print >>sys.stderr, "error: not yet compiled, run compile.py first."
+  sys.exit(1)
+  
 if __name__ == "__main__":
   main()
   
\ No newline at end of file