diff --git a/tools/download_file.py b/tools/download_file.py index d4ddf1c2d6..d5d8b66b74 100755 --- a/tools/download_file.py +++ b/tools/download_file.py @@ -28,6 +28,7 @@ GERRIT_HOME = path.expanduser('~/.gerritcodereview') CACHE_DIR = path.join(GERRIT_HOME, 'buck-cache') LOCAL_PROPERTIES = 'local.properties' + def hashfile(p): d = sha1() with open(p, 'rb') as f: @@ -38,6 +39,7 @@ def hashfile(p): d.update(b) return d.hexdigest() + def safe_mkdirs(d): if path.isdir(d): return @@ -47,6 +49,7 @@ def safe_mkdirs(d): if not path.isdir(d): raise err + def download_properties(root_dir): """ Get the download properties. @@ -73,6 +76,7 @@ def download_properties(root_dir): pass return p + def cache_entry(args): if args.v: h = args.v @@ -81,6 +85,7 @@ def cache_entry(args): name = '%s-%s' % (path.basename(args.o), h) return path.join(CACHE_DIR, name) + opts = OptionParser() opts.add_option('-o', help='local output file') opts.add_option('-u', help='URL to download') @@ -137,30 +142,24 @@ if args.x: exclude += args.x if args.exclude_java_sources: try: - zf = ZipFile(cache_ent, 'r') - try: + with ZipFile(cache_ent, 'r') as zf: for n in zf.namelist(): if n.endswith('.java'): exclude.append(n) - finally: - zf.close() except (BadZipfile, LargeZipFile) as err: - print('error opening %s: %s' % (cache_ent, err), file=stderr) + print('error opening %s: %s' % (cache_ent, err), file=stderr) exit(1) if args.unsign: try: - zf = ZipFile(cache_ent, 'r') - try: + with ZipFile(cache_ent, 'r') as zf: for n in zf.namelist(): if (n.endswith('.RSA') or n.endswith('.SF') or n.endswith('.LIST')): exclude.append(n) - finally: - zf.close() except (BadZipfile, LargeZipFile) as err: - print('error opening %s: %s' % (cache_ent, err), file=stderr) + print('error opening %s: %s' % (cache_ent, err), file=stderr) exit(1) safe_mkdirs(path.dirname(args.o)) diff --git a/tools/maven/mvn.py b/tools/maven/mvn.py index 6a33bcfe30..cc10816a6a 100644 --- a/tools/maven/mvn.py +++ b/tools/maven/mvn.py @@ -16,9 +16,8 @@ from __future__ import print_function from optparse import OptionParser from os import path, environ - +from subprocess import check_output from sys import stderr -from tools.util import check_output opts = OptionParser() opts.add_option('--repository', help='maven repository id') diff --git a/tools/pack_war.py b/tools/pack_war.py index 09ff054df0..ee87b510cf 100755 --- a/tools/pack_war.py +++ b/tools/pack_war.py @@ -16,9 +16,8 @@ from __future__ import print_function from optparse import OptionParser from os import getcwd, chdir, makedirs, path, symlink -from subprocess import check_call +from subprocess import check_call, check_output import sys -from util import check_output opts = OptionParser() opts.add_option('-o', help='path to write WAR to') @@ -31,6 +30,7 @@ war = args.tmp root = war[:war.index('buck-out')] jars = set() + def link_jars(libs, directory): makedirs(directory) while not path.isfile('.buckconfig'): @@ -51,7 +51,7 @@ if args.pgmlib: try: for s in ctx: check_call(['unzip', '-q', '-d', war, s]) - check_call(['zip', '-9qr', args.o, '.'], cwd = war) + check_call(['zip', '-9qr', args.o, '.'], cwd=war) except KeyboardInterrupt: print('Interrupted by user', file=sys.stderr) exit(1) diff --git a/tools/util.py b/tools/util.py index 9115ac7aa4..6dfe7194ac 100644 --- a/tools/util.py +++ b/tools/util.py @@ -14,13 +14,6 @@ from os import path -try: - from subprocess import check_output -except ImportError: - from subprocess import Popen, PIPE - def check_output(*cmd): - return Popen(*cmd, stdout=PIPE).communicate()[0] - REPO_ROOTS = { 'GERRIT': 'http://gerrit-maven.storage.googleapis.com', 'GERRIT_API': 'https://gerrit-api.commondatastorage.googleapis.com/release', @@ -29,6 +22,7 @@ REPO_ROOTS = { 'MAVEN_LOCAL': 'file://' + path.expanduser('~/.m2/repository'), } + def resolve_url(url, redirects): """ Resolve URL of a Maven artifact.