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