~ubuntu-branches/ubuntu/quantal/python-django/quantal-security

« back to all changes in this revision

Viewing changes to django/contrib/admin/media/js/compress.py

  • Committer: Bazaar Package Importer
  • Author(s): Chris Lamb
  • Date: 2010-05-21 07:52:55 UTC
  • mfrom: (1.3.6 upstream)
  • mto: This revision was merged to the branch mainline in revision 28.
  • Revision ID: james.westby@ubuntu.com-20100521075255-ii78v1dyfmyu3uzx
Tags: upstream-1.2
ImportĀ upstreamĀ versionĀ 1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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()