mirror of
https://github.com/basicswap/basicswap.git
synced 2026-05-07 06:52:12 +02:00
feat: add fallback urls to downloadRelease
This commit is contained in:
+25
-15
@@ -29,6 +29,7 @@ import urllib.parse
|
||||
import zipfile
|
||||
import zmq
|
||||
|
||||
from typing import List
|
||||
from urllib.request import urlopen
|
||||
|
||||
import basicswap.config as cfg
|
||||
@@ -460,12 +461,23 @@ def getRemoteFileLength(url: str) -> (int, bool):
|
||||
popConnectionParameters()
|
||||
|
||||
|
||||
def downloadRelease(url: str, path: str, extra_opts, timeout: int = 10) -> None:
|
||||
"""If file exists at path compare it's size to the content length at the url
|
||||
and attempt to resume download if file size is below expected.
|
||||
"""
|
||||
resume_from: int = 0
|
||||
def downloadRelease(
|
||||
url_in: str | List[str], path: str, extra_opts, timeout: int = 10
|
||||
) -> None:
|
||||
# If file exists at path compare it's size to the content length at the url
|
||||
# and attempt to resume download if file size is below expected.
|
||||
|
||||
release_filename: str = os.path.basename(path)
|
||||
urls = (
|
||||
url_in
|
||||
if isinstance(url_in, list)
|
||||
else [
|
||||
url_in,
|
||||
]
|
||||
)
|
||||
for url in urls:
|
||||
try:
|
||||
resume_from: int = 0
|
||||
if os.path.exists(path):
|
||||
if extra_opts.get("redownload_releases", False):
|
||||
logging.warning(f"Overwriting: {path}")
|
||||
@@ -485,8 +497,11 @@ def downloadRelease(url: str, path: str, extra_opts, timeout: int = 10) -> None:
|
||||
else:
|
||||
# File exists and size check is disabled
|
||||
return
|
||||
|
||||
return downloadFile(url, path, timeout, resume_from)
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to download {release_filename} from {url}")
|
||||
logger.debug(f"Download error {e}")
|
||||
raise RuntimeError(f"Failed to download {release_filename}.")
|
||||
|
||||
|
||||
def downloadFile(url: str, path: str, timeout: int = 5, resume_from: int = 0) -> None:
|
||||
@@ -927,15 +942,10 @@ def prepareCore(coin, version_data, settings, data_dir, extra_opts={}):
|
||||
assert_filename,
|
||||
)
|
||||
elif coin == "litecoin":
|
||||
release_url: str = (
|
||||
"https://github.com/litecoin-project/litecoin/releases/download/v{}/{}".format(
|
||||
version + version_tag, release_filename
|
||||
)
|
||||
)
|
||||
if os_name == "osx":
|
||||
release_url: str = (
|
||||
f"https://download.litecoin.org/litecoin-{version}{version_tag}/{release_filename}"
|
||||
)
|
||||
release_url = [
|
||||
f"https://github.com/litecoin-project/litecoin/releases/download/v{version}{version_tag}/{release_filename}",
|
||||
f"https://download.litecoin.org/litecoin-{version}{version_tag}/{release_filename}",
|
||||
]
|
||||
assert_filename = "{}-core-{}-{}-build.assert".format(
|
||||
coin, os_name, ".".join(version.split(".")[:2])
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user