7
here = os.path.dirname(__file__)
10
usage = "usage: %prog [file1..fileN]"
11
description = """With no file paths given this script will automatically
12
compress all jQuery-based files of the admin app. Requires the Google Closure
13
Compiler library and Java version 6 or later."""
14
parser = optparse.OptionParser(usage, description=description)
15
parser.add_option("-c", dest="compiler", default="~/bin/compiler.jar",
16
help="path to Closure Compiler jar file")
17
parser.add_option("-v", "--verbose",
18
action="store_true", dest="verbose")
19
parser.add_option("-q", "--quiet",
20
action="store_false", dest="verbose")
21
(options, args) = parser.parse_args()
23
compiler = os.path.expanduser(options.compiler)
24
if not os.path.exists(compiler):
25
sys.exit("Google Closure compiler jar file %s not found. Please use the -c option to specify the path." % compiler)
29
sys.stdout.write("No filenames given; defaulting to admin scripts\n")
30
args = [os.path.join(here, f) for f in [
31
"actions.js", "collapse.js", "inlines.js", "prepopulate.js"]]
34
if not arg.endswith(".js"):
36
to_compress = os.path.expanduser(arg)
37
if os.path.exists(to_compress):
38
to_compress_min = "%s.min.js" % "".join(arg.rsplit(".js"))
39
cmd = "java -jar %s --js %s --js_output_file %s" % (compiler, to_compress, to_compress_min)
41
sys.stdout.write("Running: %s\n" % cmd)
42
subprocess.call(cmd.split())
44
sys.stdout.write("File %s not found. Sure it exists?\n" % to_compress)
46
if __name__ == '__main__':