Skip to content

Commit

Permalink
fix(openSUSE): No longer attempt to download unreleased editions
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaVandaele committed Aug 2, 2024
1 parent d408306 commit dfc2d88
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions modules/updaters/OpenSUSE.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from modules.utils import parse_hash, sha256_hash_check

DOMAIN = "https://download.opensuse.org"
DOWNLOAD_PAGE_URL = f"{DOMAIN}/download/distribution/leap"
DOWNLOAD_PAGE_URL = f"{DOMAIN}/download/distribution/[[EDITION]]"
FILE_NAME = "openSUSE-[[EDITION]]-[[VER]]-DVD-x86_64-Current.iso"


Expand All @@ -27,13 +27,28 @@ def __init__(self, folder_path: Path, edition: str) -> None:
self.valid_editions = ["leap", "leap-micro", "jump"]
self.edition = edition.lower()

self.download_page_url = DOWNLOAD_PAGE_URL.replace("[[EDITION]]", self.edition)

file_path = folder_path / FILE_NAME
super().__init__(file_path)

def _capitalize_edition(self) -> str:
return "-".join([s.capitalize() for s in self.edition.split("-")])

@cache
def _get_download_link(self) -> str:
latest_version_str = self._version_to_str(self._get_latest_version())
return f"{DOWNLOAD_PAGE_URL}/{latest_version_str}/iso/openSUSE-Leap-{latest_version_str}-NET-x86_64-Media.iso"
url = f"{self.download_page_url}/{latest_version_str}"

edition_page = requests.get(f"{url}?jsontable").json()["data"]

if any("product" in item["name"] for item in edition_page):
url += "/product"

if self.edition != "leap-micro":
latest_version_str += "-NET"

return f"{url}/iso/openSUSE-{self._capitalize_edition()}-{latest_version_str}-x86_64{"-Current" if self.edition != "leap-micro" else ""}.iso"

def check_integrity(self) -> bool:
sha256_url = f"{self._get_download_link()}.sha256"
Expand All @@ -49,7 +64,7 @@ def check_integrity(self) -> bool:

@cache
def _get_latest_version(self) -> list[str]:
r = requests.get(f"{DOWNLOAD_PAGE_URL}?jsontable")
r = requests.get(f"{self.download_page_url}?jsontable")

data = r.json()["data"]

Expand All @@ -61,6 +76,11 @@ def _get_latest_version(self) -> list[str]:
continue
version_number = self._str_to_version(data[i]["name"][:-1])
if self._compare_version_numbers(latest, version_number):
sub_r = requests.get(f"{self.download_page_url}/{self._version_to_str(version_number)}?jsontable")
sub_data = sub_r.json()["data"]
if not any("iso" in item["name"] or "product" in item["name"] for item in sub_data):
continue

latest = version_number

return latest

0 comments on commit dfc2d88

Please sign in to comment.