feat: implement update all feature (#541)

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
dw-0
2024-09-22 09:38:15 +02:00
committed by GitHub
parent 4b17c68454
commit afeb2bf02e

View File

@@ -73,14 +73,54 @@ class UpdateMenu(BaseMenu):
self.mainsail_data = MainsailData()
self.fluidd_data = FluiddData()
self.status_data = {
"klipper": {"installed": False, "local": None, "remote": None},
"moonraker": {"installed": False, "local": None, "remote": None},
"mainsail": {"installed": False, "local": None, "remote": None},
"mainsail_config": {"installed": False, "local": None, "remote": None},
"fluidd": {"installed": False, "local": None, "remote": None},
"fluidd_config": {"installed": False, "local": None, "remote": None},
"klipperscreen": {"installed": False, "local": None, "remote": None},
"crowsnest": {"installed": False, "local": None, "remote": None},
"klipper": {
"display_name": "Klipper",
"installed": False,
"local": None,
"remote": None,
},
"moonraker": {
"display_name": "Moonraker",
"installed": False,
"local": None,
"remote": None,
},
"mainsail": {
"display_name": "Mainsail",
"installed": False,
"local": None,
"remote": None,
},
"mainsail_config": {
"display_name": "Mainsail-Config",
"installed": False,
"local": None,
"remote": None,
},
"fluidd": {
"display_name": "Fluidd",
"installed": False,
"local": None,
"remote": None,
},
"fluidd_config": {
"display_name": "Fluidd-Config",
"installed": False,
"local": None,
"remote": None,
},
"klipperscreen": {
"display_name": "KlipperScreen",
"installed": False,
"local": None,
"remote": None,
},
"crowsnest": {
"display_name": "Crowsnest",
"installed": False,
"local": None,
"remote": None,
},
}
def set_previous_menu(self, previous_menu: Type[BaseMenu] | None) -> None:
@@ -152,39 +192,56 @@ class UpdateMenu(BaseMenu):
print(menu, end="")
def update_all(self, **kwargs) -> None:
print("update_all")
Logger.print_status("Updating all components ...")
self.update_klipper()
self.update_moonraker()
self.update_mainsail()
self.update_mainsail_config()
self.update_fluidd()
self.update_fluidd_config()
self.update_klipperscreen()
self.update_crowsnest()
self.upgrade_system_packages()
def update_klipper(self, **kwargs) -> None:
if self._check_is_installed("klipper"):
update_klipper()
self._run_update_routine("klipper", update_klipper)
def update_moonraker(self, **kwargs) -> None:
if self._check_is_installed("moonraker"):
update_moonraker()
self._run_update_routine("moonraker", update_moonraker)
def update_mainsail(self, **kwargs) -> None:
if self._check_is_installed("mainsail"):
update_client(self.mainsail_data)
self._run_update_routine(
"mainsail",
update_client,
self.mainsail_data,
)
def update_mainsail_config(self, **kwargs) -> None:
if self._check_is_installed("mainsail_config"):
update_client_config(self.mainsail_data)
self._run_update_routine(
"mainsail_config",
update_client_config,
self.mainsail_data,
)
def update_fluidd(self, **kwargs) -> None:
if self._check_is_installed("fluidd"):
update_client(self.fluidd_data)
self._run_update_routine(
"fluidd",
update_client,
self.fluidd_data,
)
def update_fluidd_config(self, **kwargs) -> None:
if self._check_is_installed("fluidd_config"):
update_client_config(self.fluidd_data)
self._run_update_routine(
"fluidd_config",
update_client_config,
self.fluidd_data,
)
def update_klipperscreen(self, **kwargs) -> None:
if self._check_is_installed("klipperscreen"):
update_klipperscreen()
self._run_update_routine("klipperscreen", update_klipperscreen)
def update_crowsnest(self, **kwargs) -> None:
if self._check_is_installed("crowsnest"):
update_crowsnest()
self._run_update_routine("crowsnest", update_crowsnest)
def upgrade_system_packages(self, **kwargs) -> None:
self._run_system_updates()
@@ -239,10 +296,24 @@ class UpdateMenu(BaseMenu):
setattr(self, f"{name}_remote", remote_txt)
def _check_is_installed(self, name: str) -> bool:
if not self.status_data[name]["installed"]:
Logger.print_info(f"{name.capitalize()} is not installed! Skipped ...")
return False
return True
return self.status_data[name]["installed"]
def _is_update_available(self, name: str) -> bool:
return self.status_data[name]["local"] != self.status_data[name]["remote"]
def _run_update_routine(self, name: str, update_fn: Callable, *args) -> None:
display_name = self.status_data[name]["display_name"]
is_installed = self._check_is_installed(name)
is_update_available = self._is_update_available(name)
if not is_installed:
Logger.print_info(f"{display_name} is not installed! Skipped ...")
return
elif not is_update_available:
Logger.print_info(f"{display_name} is already up to date! Skipped ...")
return
update_fn(*args)
def _run_system_updates(self) -> None:
if not self.packages: