tools: Use common hash_file implementation

Change-Id: Idf0dce913e012bfc3bcf12d6cd19d322af69505b
This commit is contained in:
Dave Borowitz 2015-11-18 15:25:24 -05:00
parent 5da89cf34c
commit 868f76458a
3 changed files with 6 additions and 24 deletions

View File

@ -21,7 +21,7 @@ from os import link, makedirs, path, remove
import shutil
from subprocess import check_call, CalledProcessError
from sys import stderr
from util import resolve_url
from util import hash_file, resolve_url
from zipfile import ZipFile, BadZipfile, LargeZipFile
GERRIT_HOME = path.expanduser('~/.gerritcodereview')
@ -33,17 +33,6 @@ LEGACY_CACHE_DIR = path.join(GERRIT_HOME, 'buck-cache')
LOCAL_PROPERTIES = 'local.properties'
def hashfile(p):
d = sha1()
with open(p, 'rb') as f:
while True:
b = f.read(8192)
if not b:
break
d.update(b)
return d.hexdigest()
def safe_mkdirs(d):
if path.isdir(d):
return
@ -148,7 +137,7 @@ if not path.exists(cache_ent):
exit(1)
if args.v:
have = hashfile(cache_ent)
have = hash_file(sha1(), cache_ent).hexdigest()
if args.v != have:
print((
'%s:\n' +

View File

@ -15,5 +15,6 @@ python_binary(
python_binary(
name = 'run_npm_binary',
main = 'run_npm_binary.py',
deps = ['//tools:util'],
visibility = ['PUBLIC'],
)

View File

@ -25,16 +25,7 @@ import sys
import tarfile
import tempfile
def hash_file(p):
d = hashlib.sha1()
with open(p, 'rb') as f:
while True:
b = f.read(8192)
if not b:
break
d.update(b)
return d.hexdigest()
from tools import util
def extract(path, outdir, bin):
@ -80,7 +71,8 @@ def main(args):
return 1
name, version = parts
outdir = '%s-%s' % (path[:-len(suffix)], hash_file(path))
sha1 = util.hash_file(hashlib.sha1(), path).hexdigest()
outdir = '%s-%s' % (path[:-len(suffix)], sha1)
rel_bin = os.path.join('package', 'bin', name)
bin = os.path.join(outdir, rel_bin)
if not os.path.isfile(bin):