Buck: Remove Python 2.6 compatibility workarounds
The check_output method is only available from Python 2.7, so a wrapper method was introduced for compatibility with 2.6. The ZipFile class does not include context manager support in Python 2.6, so the file download code was written to explicitly open and close the zip files. Since Buck itself now requires at least Python 2.7, these workarounds are no longer necessary. Remove them. Also, tidy up a few minor PEP-8 coding style violations in the modified files. Change-Id: I9a1b25ddf7494e25ccadeaed0c1d85cd1ce2fd09
This commit is contained in:
parent
9d466d319b
commit
15a9f53f00
@ -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))
|
||||
|
@ -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')
|
||||
|
@ -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)
|
||||
|
@ -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.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user