Skip to content

Commit

Permalink
fix: switch from curl to requests for HTTP requests
Browse files Browse the repository at this point in the history
  • Loading branch information
iw4p committed Apr 26, 2024
1 parent 7973a67 commit 38176a7
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions test/get_previous_releases.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
#
# Download or build previous releases.
# Needs curl and tar to download a release, or the build dependencies when
# Needs requests built-in python library and tar to download a release, or the build dependencies when
# building a release.

import argparse
Expand All @@ -18,6 +18,7 @@
import subprocess
import sys
import hashlib
import requests

SHA256_SUMS = {
"0e2819135366f150d9906e294b61dff58fd1996ebd26c2f8e979d6c0b7a79580": {"tag": "v0.14.3", "tarball": "bitcoin-0.14.3-aarch64-linux-gnu.tar.gz"},
Expand Down Expand Up @@ -133,20 +134,15 @@ def download_binary(tag, args) -> int:

print('Fetching: {tarballUrl}'.format(tarballUrl=tarballUrl))

header, status = subprocess.Popen(
['curl', '--head', tarballUrl], stdout=subprocess.PIPE).communicate()
if re.search("404 Not Found", header.decode("utf-8")):
response = requests.head(tarballUrl)

if response.status_code == 404:
print("Binary tag was not found")
return 1

curlCmds = [
['curl', '--remote-name', tarballUrl]
]

for cmd in curlCmds:
ret = subprocess.run(cmd).returncode
if ret:
return ret
response = requests.get(tarballUrl)
with open(tarball, 'wb') as file:
file.write(response.content)

hasher = hashlib.sha256()
with open(tarball, "rb") as afile:
Expand Down

0 comments on commit 38176a7

Please sign in to comment.