X-Git-Url: https://jfr.im/git/irc/quakenet/qwebirc.git/blobdiff_plain/7c4c581ccb2f4b299a8336e7e6caef8830139231..75b05108ce496fce928a246457a5c73ce0c80d3e:/bin/compile.py diff --git a/bin/compile.py b/bin/compile.py index c287bc7..5ca4a84 100644 --- a/bin/compile.py +++ b/bin/compile.py @@ -1,20 +1,59 @@ #!/usr/bin/env python -import pages, os, subprocess, pagegen +import dependencies +dependencies.vcheck() + +import pages, os, subprocess, pagegen, shutil, sys, time 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.4.2.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 -def jmerge_files(prefix, suffix, output, files, *args): +JAVA_WARNING_SURPRESSED = False +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) - compiled = jarit(o) - os.unlink(o) + + # cough hack + 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 + try: + f = open(o, "rb") + compiled = f.read() + finally: + f.close() + + 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() @@ -22,8 +61,10 @@ def merge_files(output, files, root_path=lambda x: x): f = open(output, "wb") for x in files: + if x.startswith("//"): + continue f2 = open(root_path(x), "rb") - f.write(f2.read()) + f.write(f2.read() + "\n") f2.close() f.close() @@ -48,6 +89,14 @@ def main(outputdir=".", produce_debug=True): for uiname, value in pages.UIs.items(): 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 = [] @@ -59,10 +108,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 +