From c9c40bc6bc64e67365338751e4967d86d0882abf Mon Sep 17 00:00:00 2001 From: Julien Phalip Date: Sat, 2 Feb 2013 13:53:43 -0800 Subject: Fixed #19333 -- Moved compress.py outside of the admin static folder. Thanks to camilonova, Russell Keith-Magee, Aymeric Augustin and Ramiro Morales for the feedback. --- django/contrib/admin/bin/compress.py | 47 ++++++++++++++++++++++ django/contrib/admin/static/admin/js/compress.py | 47 ---------------------- .../writing-code/submitting-patches.txt | 6 ++- 3 files changed, 51 insertions(+), 49 deletions(-) create mode 100644 django/contrib/admin/bin/compress.py delete mode 100644 django/contrib/admin/static/admin/js/compress.py diff --git a/django/contrib/admin/bin/compress.py b/django/contrib/admin/bin/compress.py new file mode 100644 index 0000000000..e15f2d3ef6 --- /dev/null +++ b/django/contrib/admin/bin/compress.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python +import os +import optparse +import subprocess +import sys + +js_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'static', 'admin', 'js') + +def main(): + usage = "usage: %prog [file1..fileN]" + description = """With no file paths given this script will automatically +compress all jQuery-based files of the admin app. Requires the Google Closure +Compiler library and Java version 6 or later.""" + parser = optparse.OptionParser(usage, description=description) + parser.add_option("-c", dest="compiler", default="~/bin/compiler.jar", + help="path to Closure Compiler jar file") + parser.add_option("-v", "--verbose", + action="store_true", dest="verbose") + parser.add_option("-q", "--quiet", + action="store_false", dest="verbose") + (options, args) = parser.parse_args() + + compiler = os.path.expanduser(options.compiler) + if not os.path.exists(compiler): + sys.exit("Google Closure compiler jar file %s not found. Please use the -c option to specify the path." % compiler) + + if not args: + if options.verbose: + sys.stdout.write("No filenames given; defaulting to admin scripts\n") + args = [os.path.join(js_path, f) for f in [ + "actions.js", "collapse.js", "inlines.js", "prepopulate.js"]] + + for arg in args: + if not arg.endswith(".js"): + arg = arg + ".js" + to_compress = os.path.expanduser(arg) + if os.path.exists(to_compress): + to_compress_min = "%s.min.js" % "".join(arg.rsplit(".js")) + cmd = "java -jar %s --js %s --js_output_file %s" % (compiler, to_compress, to_compress_min) + if options.verbose: + sys.stdout.write("Running: %s\n" % cmd) + subprocess.call(cmd.split()) + else: + sys.stdout.write("File %s not found. Sure it exists?\n" % to_compress) + +if __name__ == '__main__': + main() diff --git a/django/contrib/admin/static/admin/js/compress.py b/django/contrib/admin/static/admin/js/compress.py deleted file mode 100644 index 8d2caa28ea..0000000000 --- a/django/contrib/admin/static/admin/js/compress.py +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/env python -import os -import optparse -import subprocess -import sys - -here = os.path.dirname(__file__) - -def main(): - usage = "usage: %prog [file1..fileN]" - description = """With no file paths given this script will automatically -compress all jQuery-based files of the admin app. Requires the Google Closure -Compiler library and Java version 6 or later.""" - parser = optparse.OptionParser(usage, description=description) - parser.add_option("-c", dest="compiler", default="~/bin/compiler.jar", - help="path to Closure Compiler jar file") - parser.add_option("-v", "--verbose", - action="store_true", dest="verbose") - parser.add_option("-q", "--quiet", - action="store_false", dest="verbose") - (options, args) = parser.parse_args() - - compiler = os.path.expanduser(options.compiler) - if not os.path.exists(compiler): - sys.exit("Google Closure compiler jar file %s not found. Please use the -c option to specify the path." % compiler) - - if not args: - if options.verbose: - sys.stdout.write("No filenames given; defaulting to admin scripts\n") - args = [os.path.join(here, f) for f in [ - "actions.js", "collapse.js", "inlines.js", "prepopulate.js"]] - - for arg in args: - if not arg.endswith(".js"): - arg = arg + ".js" - to_compress = os.path.expanduser(arg) - if os.path.exists(to_compress): - to_compress_min = "%s.min.js" % "".join(arg.rsplit(".js")) - cmd = "java -jar %s --js %s --js_output_file %s" % (compiler, to_compress, to_compress_min) - if options.verbose: - sys.stdout.write("Running: %s\n" % cmd) - subprocess.call(cmd.split()) - else: - sys.stdout.write("File %s not found. Sure it exists?\n" % to_compress) - -if __name__ == '__main__': - main() diff --git a/docs/internals/contributing/writing-code/submitting-patches.txt b/docs/internals/contributing/writing-code/submitting-patches.txt index a90dc32605..ed8aad99b3 100644 --- a/docs/internals/contributing/writing-code/submitting-patches.txt +++ b/docs/internals/contributing/writing-code/submitting-patches.txt @@ -176,8 +176,10 @@ Compressing JavaScript ~~~~~~~~~~~~~~~~~~~~~~ To simplify the process of providing optimized javascript code, Django -includes a handy script which should be used to create a "minified" version. -This script is located at ``django/contrib/admin/static/admin/js/compress.py``. +includes a handy python script which should be used to create a "minified" +version. To run it:: + + python django/contrib/admin/bin/compress.py Behind the scenes, ``compress.py`` is a front-end for Google's `Closure Compiler`_ which is written in Java. However, the Closure Compiler -- cgit v1.3