diff options
| author | Tom Forbes <tom.forbes@contextis.co.uk> | 2017-07-21 13:32:50 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-07-21 10:24:49 -0400 |
| commit | 462f1589cd70544121d4ad0ba476009b1b5be9af (patch) | |
| tree | a7172abd69e202ffc47847b8ea0d1223791fda35 | |
| parent | 3159ad4df6ec05c3eac07b930b4af32739bec7b0 (diff) | |
Refs #23919 -- Updated contrib.admin's compress.py to use pathlib.
| -rw-r--r-- | django/contrib/admin/bin/compress.py | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/django/contrib/admin/bin/compress.py b/django/contrib/admin/bin/compress.py index dbef84d759..06e750f3cb 100644 --- a/django/contrib/admin/bin/compress.py +++ b/django/contrib/admin/bin/compress.py @@ -1,17 +1,17 @@ #!/usr/bin/env python import argparse -import os import subprocess import sys +from pathlib import Path try: import closure except ImportError: closure_compiler = None else: - closure_compiler = os.path.join(os.path.dirname(closure.__file__), 'closure.jar') + closure_compiler = closure.get_jar_filename() -js_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'static', 'admin', 'js') +js_path = Path(__file__).parent.parent / 'static' / 'admin' / 'js' def main(): @@ -28,8 +28,8 @@ Compiler library and Java version 6 or later.""" parser.add_argument("-q", "--quiet", action="store_false", dest="verbose") options = parser.parse_args() - compiler = closure_compiler if closure_compiler else os.path.expanduser(options.compiler) - if not os.path.exists(compiler): + compiler = Path(closure_compiler if closure_compiler else options.compiler).expanduser() + if not compiler.exists(): sys.exit( "Google Closure compiler jar file %s not found. Please use the -c " "option to specify the path." % compiler @@ -39,18 +39,16 @@ Compiler library and Java version 6 or later.""" if options.verbose: sys.stdout.write("No filenames given; defaulting to admin scripts\n") files = [ - os.path.join(js_path, f) for f in - ["actions.js", "collapse.js", "inlines.js", "prepopulate.js"] + js_path / f + for f in ["actions.js", "collapse.js", "inlines.js", "prepopulate.js"] ] else: - files = options.file + files = [Path(f) for f in options.file] - 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(file_name.rsplit(".js")) + for file_path in files: + to_compress = file_path.expanduser() + if to_compress.exists(): + to_compress_min = to_compress.with_suffix('.min.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) |
