diff --git a/django/contrib/admin/bin/compress.py b/django/contrib/admin/bin/compress.py index 7e5d4ea779..f21972708f 100644 --- a/django/contrib/admin/bin/compress.py +++ b/django/contrib/admin/bin/compress.py @@ -1,6 +1,6 @@ #!/usr/bin/env python +import argparse import os -import optparse import subprocess import sys @@ -8,35 +8,37 @@ js_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'static', 'ad 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", + parser = argparse.ArgumentParser(description=description) + parser.add_argument('file', nargs='*') + parser.add_argument("-c", dest="compiler", default="~/bin/compiler.jar", help="path to Closure Compiler jar file") - parser.add_option("-v", "--verbose", + parser.add_argument("-v", "--verbose", action="store_true", dest="verbose") - parser.add_option("-q", "--quiet", + parser.add_argument("-q", "--quiet", action="store_false", dest="verbose") - (options, args) = parser.parse_args() + options = 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 not options.file: if options.verbose: sys.stdout.write("No filenames given; defaulting to admin scripts\n") - args = [os.path.join(js_path, f) for f in [ + files = [os.path.join(js_path, f) for f in [ "actions.js", "collapse.js", "inlines.js", "prepopulate.js"]] + else: + files = options.file - for arg in args: - if not arg.endswith(".js"): - arg = arg + ".js" - to_compress = os.path.expanduser(arg) + for file_name in files: + if not file_name.endswith(".js"): + file_name = file_name + ".js" + to_compress = os.path.expanduser(file_name) if os.path.exists(to_compress): - to_compress_min = "%s.min.js" % "".join(arg.rsplit(".js")) + to_compress_min = "%s.min.js" % "".join(file_name.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) diff --git a/extras/csrf_migration_helper.py b/extras/csrf_migration_helper.py index 9e7b04b85b..e7df65d056 100755 --- a/extras/csrf_migration_helper.py +++ b/extras/csrf_migration_helper.py @@ -112,25 +112,15 @@ PYTHON_ENCODING = "UTF-8" # and fail to find real instances. +from argparse import ArgumentParser import os import sys import re -from optparse import OptionParser -USAGE = """ -This tool helps to locate forms that need CSRF tokens added and the +DESCRIPTION = """This tool helps to locate forms that need CSRF tokens added and the corresponding view code. This processing is NOT fool proof, and you should read the help contained in the script itself. Also, this script may need configuring -(by editing the script) before use. - -Usage: - -python csrf_migration_helper.py [--settings=path.to.your.settings] /path/to/python/code [more paths...] - - Paths can be specified as relative paths. - - With no arguments, this help is printed. -""" +(by editing the script) before use.""" _POST_FORM_RE = \ re.compile(r'(