fix: refresh installer catalog on demand

This commit is contained in:
Mirko Brombin
2026-09-28 18:12:15 +02:00
parent afad471a36
commit 3066083caf
5 changed files with 55 additions and 1 deletions
+7
View File
@@ -86,6 +86,13 @@ class InstallerManager:
catalog = dict(sorted(catalog.items()))
return catalog
def refresh_catalog(self) -> dict:
self.__repo.refresh()
self.fetch_catalog.cache_clear()
self.get_installer.cache_clear()
self.get_review.cache_clear()
return self.fetch_catalog()
def get_icon_url(self, installer):
"""Wrapper for the repo method."""
return self.__repo.get_icon(installer)
+5
View File
@@ -46,6 +46,7 @@ class Repo:
):
self.url = url
self.cache_url = cache_url or url
self.index = index
self.offline = offline
self.catalog = None
@@ -66,6 +67,10 @@ class Repo:
offline=offline,
)
def refresh(self) -> dict:
self.catalog = self.__get_catalog(self.index, self.offline)
return self.catalog
def __get_catalog(self, index: str, offline: bool = False):
cache_path = self.__get_cache_path("catalog.yml")
if index in ["", None] or offline:
+5 -1
View File
@@ -88,7 +88,6 @@ class InstallersView(Adw.Bin):
if config is None:
config = BottleConfig()
self.config = config
installers = self.manager.supported_installers.items()
include_unstable = self.window.settings.get_boolean("release-candidate")
self.list_installers.set_sensitive(False)
@@ -110,6 +109,11 @@ class InstallersView(Adw.Bin):
time.sleep(0.5) # workaround for freezing bug on bottle load
GLib.idle_add(self.empty_list)
catalog = self.manager.installer_manager.refresh_catalog()
if catalog:
self.manager.supported_installers = catalog
installers = self.manager.supported_installers.items()
if len(installers) == 0:
return Result(False)
@@ -43,6 +43,26 @@ def test_installer_respects_compatible_runners(runners, runner, expected):
assert InstallerManager.supports_runner(installer, runner) is expected
def test_installer_refreshes_catalog_and_cached_manifests(mocker):
repository = mocker.Mock()
repository.catalog = {"old": {"Name": "Old"}}
def refresh():
repository.catalog = {"new": {"Name": "New"}}
repository.refresh.side_effect = refresh
installer = object.__new__(InstallerManager)
installer._InstallerManager__repo = repository
installer._InstallerManager__utils_conn = mocker.Mock(check_connection=lambda: True)
assert installer.fetch_catalog() == {"old": {"Name": "Old"}}
repository.get.return_value = {"Version": 1}
assert installer.get_installer("office") == {"Version": 1}
repository.get.return_value = {"Version": 2}
assert installer.refresh_catalog() == {"new": {"Name": "New"}}
assert installer.get_installer("office") == {"Version": 2}
@pytest.mark.parametrize("current_value", [True, False])
def test_installer_applies_window_decoration_parameter(mocker, current_value):
registry = mocker.patch(
+18
View File
@@ -37,6 +37,24 @@ def test_catalog_callback_mode_is_configurable(monkeypatch, callback_in_main_loo
assert callback_modes == [callback_in_main_loop]
def test_repository_refresh_reloads_the_current_index(monkeypatch):
repository = object.__new__(ComponentRepo)
repository.index = "https://repo.example.test/index.yml"
repository.offline = False
repository.catalog = {"old": {}}
calls = []
def get_catalog(_repository, index, offline=False):
calls.append((index, offline))
return {"new": {}}
monkeypatch.setattr(repo_module.Repo, "_Repo__get_catalog", get_catalog)
assert repository.refresh() == {"new": {}}
assert repository.catalog == {"new": {}}
assert calls == [(repository.index, False)]
@pytest.mark.parametrize(
("manager_type", "repository_name"),
[