From 816fced5d728a13304a9d8b41f86a440c549b2f5 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Mon, 1 Feb 2010 14:16:01 +0000 Subject: [PATCH] Being a good citizen, adding the jQuery license and a command line script to easily minify the jQuery based scripts. git-svn-id: http://code.djangoproject.com/svn/django/trunk@12371 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- .../contrib/admin/media/js/LICENSE-JQUERY.txt | 20 +++++++++ django/contrib/admin/media/js/compress.py | 45 +++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 django/contrib/admin/media/js/LICENSE-JQUERY.txt create mode 100644 django/contrib/admin/media/js/compress.py diff --git a/django/contrib/admin/media/js/LICENSE-JQUERY.txt b/django/contrib/admin/media/js/LICENSE-JQUERY.txt new file mode 100644 index 0000000000..a4c5bd76ac --- /dev/null +++ b/django/contrib/admin/media/js/LICENSE-JQUERY.txt @@ -0,0 +1,20 @@ +Copyright (c) 2010 John Resig, http://jquery.com/ + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/django/contrib/admin/media/js/compress.py b/django/contrib/admin/media/js/compress.py new file mode 100644 index 0000000000..bb39229745 --- /dev/null +++ b/django/contrib/admin/media/js/compress.py @@ -0,0 +1,45 @@ +#!/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.""" + 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("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"]] + + 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()