Project

General

Profile

Statistics
| Branch: | Revision:

root / env / lib / python2.7 / site-packages / django / contrib / admin / static / admin / js / compress.py @ 1a305335

History | View | Annotate | Download (1.85 KB)

1
#!/usr/bin/env python
2
import os
3
import optparse
4
import subprocess
5
import sys
6

    
7
here = os.path.dirname(__file__)
8

    
9
def main():
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()
22

    
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)
26

    
27
    if not args:
28
        if options.verbose:
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"]]
32

    
33
    for arg in args:
34
        if not arg.endswith(".js"):
35
            arg = arg + ".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)
40
            if options.verbose:
41
                sys.stdout.write("Running: %s\n" % cmd)
42
            subprocess.call(cmd.split())
43
        else:
44
            sys.stdout.write("File %s not found. Sure it exists?\n" % to_compress)
45

    
46
if __name__ == '__main__':
47
    main()