tools: Use common hash_file implementation
Change-Id: Idf0dce913e012bfc3bcf12d6cd19d322af69505b
This commit is contained in:
@@ -21,7 +21,7 @@ from os import link, makedirs, path, remove
|
|||||||
import shutil
|
import shutil
|
||||||
from subprocess import check_call, CalledProcessError
|
from subprocess import check_call, CalledProcessError
|
||||||
from sys import stderr
|
from sys import stderr
|
||||||
from util import resolve_url
|
from util import hash_file, resolve_url
|
||||||
from zipfile import ZipFile, BadZipfile, LargeZipFile
|
from zipfile import ZipFile, BadZipfile, LargeZipFile
|
||||||
|
|
||||||
GERRIT_HOME = path.expanduser('~/.gerritcodereview')
|
GERRIT_HOME = path.expanduser('~/.gerritcodereview')
|
||||||
@@ -33,17 +33,6 @@ LEGACY_CACHE_DIR = path.join(GERRIT_HOME, 'buck-cache')
|
|||||||
LOCAL_PROPERTIES = 'local.properties'
|
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):
|
def safe_mkdirs(d):
|
||||||
if path.isdir(d):
|
if path.isdir(d):
|
||||||
return
|
return
|
||||||
@@ -148,7 +137,7 @@ if not path.exists(cache_ent):
|
|||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
if args.v:
|
if args.v:
|
||||||
have = hashfile(cache_ent)
|
have = hash_file(sha1(), cache_ent).hexdigest()
|
||||||
if args.v != have:
|
if args.v != have:
|
||||||
print((
|
print((
|
||||||
'%s:\n' +
|
'%s:\n' +
|
||||||
|
@@ -15,5 +15,6 @@ python_binary(
|
|||||||
python_binary(
|
python_binary(
|
||||||
name = 'run_npm_binary',
|
name = 'run_npm_binary',
|
||||||
main = 'run_npm_binary.py',
|
main = 'run_npm_binary.py',
|
||||||
|
deps = ['//tools:util'],
|
||||||
visibility = ['PUBLIC'],
|
visibility = ['PUBLIC'],
|
||||||
)
|
)
|
||||||
|
@@ -25,16 +25,7 @@ import sys
|
|||||||
import tarfile
|
import tarfile
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
|
from tools import util
|
||||||
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()
|
|
||||||
|
|
||||||
|
|
||||||
def extract(path, outdir, bin):
|
def extract(path, outdir, bin):
|
||||||
@@ -80,7 +71,8 @@ def main(args):
|
|||||||
return 1
|
return 1
|
||||||
|
|
||||||
name, version = parts
|
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)
|
rel_bin = os.path.join('package', 'bin', name)
|
||||||
bin = os.path.join(outdir, rel_bin)
|
bin = os.path.join(outdir, rel_bin)
|
||||||
if not os.path.isfile(bin):
|
if not os.path.isfile(bin):
|
||||||
|
Reference in New Issue
Block a user