Skip to content

Commit facdf53

Browse files
author
MarcoFalke
committed
contrib: Clean up previous_releases.py
* Replace curl single char options with their verbose counterpart * Stricter check for tarballHash
1 parent ea595d3 commit facdf53

File tree

1 file changed

+17
-22
lines changed

1 file changed

+17
-22
lines changed

contrib/devtools/previous_release.py

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
# Distributed under the MIT software license, see the accompanying
55
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
66
#
7-
# Build previous releases.
7+
# Download or build previous releases.
8+
# Needs curl and tar to download a release, or the build dependencies when
9+
# building a release.
810

911
import argparse
1012
import contextlib
@@ -52,14 +54,14 @@ def download_binary(tag, args) -> int:
5254
print('Fetching: {sha256SumsUrl}'.format(sha256SumsUrl=sha256SumsUrl))
5355

5456
header, status = subprocess.Popen(
55-
['curl', '-I', tarballUrl], stdout=subprocess.PIPE).communicate()
57+
['curl', '--head', tarballUrl], stdout=subprocess.PIPE).communicate()
5658
if re.search("404 Not Found", header.decode("utf-8")):
5759
print("Binary tag was not found")
5860
return 1
5961

6062
curlCmds = [
61-
['curl', '-O', tarballUrl],
62-
['curl', "-o", sha256Sums, sha256SumsUrl],
63+
['curl', '--remote-name', tarballUrl],
64+
['curl', '--output', sha256Sums, sha256SumsUrl],
6365
]
6466

6567
for cmd in curlCmds:
@@ -69,23 +71,17 @@ def download_binary(tag, args) -> int:
6971

7072
hasher = hashlib.sha256()
7173
with open(tarball, "rb") as afile:
72-
buf = afile.read()
73-
hasher.update(buf)
74-
afile.close()
74+
hasher.update(afile.read())
7575
tarballHash = hasher.hexdigest()
76-
file = open(sha256Sums, 'r', encoding="utf-8")
77-
lst = list(file.readlines())
78-
file.close()
79-
lastline = lst[len(lst)-1]
80-
81-
for line in lst:
82-
if re.search(tarballHash, line):
83-
print("Checksum matched")
84-
break
85-
elif lastline == line:
86-
print("Checksum did not match")
87-
Path(tarball).unlink()
88-
return 1
76+
tarballHash = '{} {}\n'.format(tarballHash, tarball)
77+
with open(sha256Sums, 'r', encoding="utf-8") as afile:
78+
shasums = afile.readlines()
79+
80+
if tarballHash not in shasums:
81+
print("Checksum did not match")
82+
Path(tarball).unlink()
83+
return 1
84+
print("Checksum matched")
8985

9086
# Bitcoin Core Release Signing Keys v0.11.0+
9187
signingKey = "01EA5486DE18A882D4C2684590C8019E36C2E964"
@@ -182,8 +178,7 @@ def check_host(args) -> int:
182178

183179

184180
def main(args) -> int:
185-
if not Path(args.target_dir).is_dir():
186-
Path(args.target_dir).mkdir(exist_ok=True, parents=True)
181+
Path(args.target_dir).mkdir(exist_ok=True, parents=True)
187182
print("Releases directory: {}".format(args.target_dir))
188183
ret = check_host(args)
189184
if ret:

0 commit comments

Comments
 (0)