diff options
author | fanquake <fanquake@gmail.com> | 2020-07-21 20:08:44 +0800 |
---|---|---|
committer | fanquake <fanquake@gmail.com> | 2020-07-21 20:32:20 +0800 |
commit | 910a8d9c6fb4205f514b4443367d3acaaa4054f5 (patch) | |
tree | ccf3cac2bb4f20b0e9539886eaa440268d9c6216 | |
parent | 65a54d684fcfa5b2cb15b09fd9be9acb56bb5f79 (diff) | |
parent | facdf530c731fbe80b86f484175ccf7a691c7131 (diff) | |
download | bitcoin-910a8d9c6fb4205f514b4443367d3acaaa4054f5.tar.xz |
Merge #19560: contrib: Clean up previous_releases.py
facdf530c731fbe80b86f484175ccf7a691c7131 contrib: Clean up previous_releases.py (MarcoFalke)
Pull request description:
ACKs for top commit:
fjahr:
tACK facdf530c731fbe80b86f484175ccf7a691c7131
Sjors:
tACK facdf53
hebasto:
ACK facdf530c731fbe80b86f484175ccf7a691c7131, I have reviewed the code and it looks OK, I agree it can be merged.
Tree-SHA512: c3543320572267035aa342dd170128bbdeb83ca4e2e36a8e46596dd76c8ff1b26ed6759a8073884228b133c45b06ec48889cd0ec83a13bef276b48073d8248e4
-rwxr-xr-x | contrib/devtools/previous_release.py | 39 |
1 files changed, 17 insertions, 22 deletions
diff --git a/contrib/devtools/previous_release.py b/contrib/devtools/previous_release.py index bea4f56010..5599051cf3 100755 --- a/contrib/devtools/previous_release.py +++ b/contrib/devtools/previous_release.py @@ -4,7 +4,9 @@ # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. # -# Build previous releases. +# Download or build previous releases. +# Needs curl and tar to download a release, or the build dependencies when +# building a release. import argparse import contextlib @@ -52,14 +54,14 @@ def download_binary(tag, args) -> int: print('Fetching: {sha256SumsUrl}'.format(sha256SumsUrl=sha256SumsUrl)) header, status = subprocess.Popen( - ['curl', '-I', tarballUrl], stdout=subprocess.PIPE).communicate() + ['curl', '--head', tarballUrl], stdout=subprocess.PIPE).communicate() if re.search("404 Not Found", header.decode("utf-8")): print("Binary tag was not found") return 1 curlCmds = [ - ['curl', '-O', tarballUrl], - ['curl', "-o", sha256Sums, sha256SumsUrl], + ['curl', '--remote-name', tarballUrl], + ['curl', '--output', sha256Sums, sha256SumsUrl], ] for cmd in curlCmds: @@ -69,23 +71,17 @@ def download_binary(tag, args) -> int: hasher = hashlib.sha256() with open(tarball, "rb") as afile: - buf = afile.read() - hasher.update(buf) - afile.close() + hasher.update(afile.read()) tarballHash = hasher.hexdigest() - file = open(sha256Sums, 'r', encoding="utf-8") - lst = list(file.readlines()) - file.close() - lastline = lst[len(lst)-1] - - for line in lst: - if re.search(tarballHash, line): - print("Checksum matched") - break - elif lastline == line: - print("Checksum did not match") - Path(tarball).unlink() - return 1 + tarballHash = '{} {}\n'.format(tarballHash, tarball) + with open(sha256Sums, 'r', encoding="utf-8") as afile: + shasums = afile.readlines() + + if tarballHash not in shasums: + print("Checksum did not match") + Path(tarball).unlink() + return 1 + print("Checksum matched") # Bitcoin Core Release Signing Keys v0.11.0+ signingKey = "01EA5486DE18A882D4C2684590C8019E36C2E964" @@ -182,8 +178,7 @@ def check_host(args) -> int: def main(args) -> int: - if not Path(args.target_dir).is_dir(): - Path(args.target_dir).mkdir(exist_ok=True, parents=True) + Path(args.target_dir).mkdir(exist_ok=True, parents=True) print("Releases directory: {}".format(args.target_dir)) ret = check_host(args) if ret: |