From 38dd224ffe20575a917e3af5aa74245dff3fa931 Mon Sep 17 00:00:00 2001 From: Max Gautier Date: Fri, 20 Dec 2024 11:18:18 +0100 Subject: [PATCH] Extract get_hash into it's own function Also, always raise even for 404 not found (should not happen now that we'll use GraphQL to find the exact set of versions) --- scripts/download_hash.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/scripts/download_hash.py b/scripts/download_hash.py index bb60803c1..536a6ca38 100644 --- a/scripts/download_hash.py +++ b/scripts/download_hash.py @@ -149,14 +149,11 @@ def download_hash(only_downloads: [str]) -> None: @cache def _get_hash_by_arch(download: str, version: str) -> {str: str}: - hash_file = s.get(downloads[download].format( + hash_file = s.get(downloads[download]['url'].format( version = version, os = "linux", ), allow_redirects=True) - if hash_file.status_code == 404: - print(f"Unable to find {download} hash file for version {version} at {hash_file.url}") - return None hash_file.raise_for_status() return download_hash_extract[download](hash_file.content.decode()) @@ -206,6 +203,20 @@ def download_hash(only_downloads: [str]) -> None: and (cur_v := sorted(Version(k) for k in next(archs.values().__iter__()).keys())) } + def get_hash(component: str, version: Version, arch: str): + if component in download_hash_extract: + hashes = _get_hash_by_arch(component, version) + return hashes[arch] + else: + hash_file = s.get( + downloads[component]['url'].format( + version = version, + os = "linux", + arch = arch + ), + allow_redirects=True) + hash_file.raise_for_status() + return (hash_file.content.decode().split()[0]) for download, url in (downloads if only_downloads == []