build.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 import sys
00004 import os
00005 sys.path.append("../tools")
00006 import mergejs
00007 import optparse
00008 
00009 def build(config_file = None, output_file = None, options = None):
00010     have_compressor = []
00011     try:
00012         import jsmin
00013         have_compressor.append("jsmin")
00014     except ImportError:
00015         print "No jsmin"
00016     try:
00017         # tools/closure_library_jscompiler.py from: 
00018         #       http://code.google.com/p/closure-library/source/browse/trunk/closure/bin/build/jscompiler.py
00019         import closure_library_jscompiler as closureCompiler
00020         have_compressor.append("closure")
00021     except Exception, E:
00022         print "No closure (%s)" % E
00023     try:
00024         import closure_ws
00025         have_compressor.append("closure_ws")
00026     except ImportError:
00027         print "No closure_ws"
00028     
00029     try:
00030         import minimize
00031         have_compressor.append("minimize")
00032     except ImportError:
00033         print "No minimize"
00034 
00035     use_compressor = None
00036     if options.compressor and options.compressor in have_compressor:
00037         use_compressor = options.compressor
00038 
00039     sourceDirectory = "../lib"
00040     configFilename = "full.cfg"
00041     outputFilename = "OpenLayers.js"
00042 
00043     if config_file:
00044         configFilename = config_file
00045         extension = configFilename[-4:]
00046 
00047         if extension  != ".cfg":
00048             configFilename = config_file + ".cfg"
00049 
00050     if output_file:
00051         outputFilename = output_file
00052 
00053     print "Merging libraries."
00054     try:
00055         if use_compressor == "closure":
00056             sourceFiles = mergejs.getNames(sourceDirectory, configFilename)
00057         else:
00058             merged = mergejs.run(sourceDirectory, None, configFilename)
00059     except mergejs.MissingImport, E:
00060         print "\nAbnormal termination."
00061         sys.exit("ERROR: %s" % E)
00062 
00063     print "Compressing using %s" % use_compressor
00064     if use_compressor == "jsmin":
00065         minimized = jsmin.jsmin(merged)
00066     elif use_compressor == "minimize":
00067         minimized = minimize.minimize(merged)
00068     elif use_compressor == "closure_ws":
00069         if len(merged) > 1000000: # The maximum file size for this web service is 1000 KB.
00070             print "\nPre-compressing using jsmin"
00071             merged = jsmin.jsmin(merged)
00072         print "\nIs being compressed using Closure Compiler Service."
00073         try:
00074             minimized = closure_ws.minimize(merged)
00075         except Exception, E:
00076             print "\nAbnormal termination."
00077             sys.exit("ERROR: Closure Compilation using Web service failed!\n%s" % E)
00078         if len(minimized) <= 2:
00079             print "\nAbnormal termination due to compilation errors."
00080             sys.exit("ERROR: Closure Compilation using Web service failed!")
00081         else:
00082             print "Closure Compilation using Web service has completed successfully."
00083     elif use_compressor == "closure":
00084         jscompilerJar = "../tools/closure-compiler.jar"
00085         if not os.path.isfile(jscompilerJar):
00086             print "\nNo closure-compiler.jar; read README.txt!"
00087             sys.exit("ERROR: Closure Compiler \"%s\" does not exist! Read README.txt" % jscompilerJar)
00088         minimized = closureCompiler.Compile(
00089             jscompilerJar, 
00090             sourceFiles, [
00091                 "--externs", "closure-compiler/Externs.js",
00092                 "--jscomp_warning", "checkVars",   # To enable "undefinedVars"
00093                 "--jscomp_error",   "checkRegExp", # Also necessary to enable "undefinedVars"
00094                 "--jscomp_error",   "undefinedVars"
00095             ]
00096         )
00097         if minimized is None:
00098             print "\nAbnormal termination due to compilation errors." 
00099             sys.exit("ERROR: Closure Compilation failed! See compilation errors.") 
00100         print "Closure Compilation has completed successfully."
00101     else: # fallback
00102         minimized = merged 
00103 
00104     print "\nAdding license file."
00105     minimized = file("license.txt").read() + minimized
00106 
00107     print "Writing to %s." % outputFilename
00108     file(outputFilename, "w").write(minimized)
00109 
00110     print "Done."
00111 
00112 if __name__ == '__main__':
00113   opt = optparse.OptionParser(usage="%s [options] [config_file] [output_file]\n  Default config_file is 'full.cfg', Default output_file is 'OpenLayers.js'")
00114   opt.add_option("-c", "--compressor", dest="compressor", help="compression method: one of 'jsmin', 'minimize', 'closure_ws', 'closure', or 'none'", default="jsmin")
00115   (options, args) = opt.parse_args()
00116   if not len(args):
00117     build(options=options)
00118   elif len(args) == 1:
00119     build(args[0], options=options)
00120   elif len(args) == 2:
00121     build(args[0], args[1], options=options)
00122   else:
00123     print "Wrong number of arguments"


websocket_gui
Author(s): Benoit Lescot and Stéphane Magnenat
autogenerated on Mon Oct 6 2014 08:54:48