From 7ec055f5628d175b06587a08dce552f884dcf82c Mon Sep 17 00:00:00 2001 From: dw-0 Date: Wed, 20 Mar 2024 22:10:51 +0100 Subject: [PATCH] refactor(webclients): always remove config sections Signed-off-by: Dominik Willner --- .../client_config/client_config_remove.py | 10 ++---- .../components/webui_client/client_remove.py | 13 ++++---- .../webui_client/menus/client_remove_menu.py | 32 ++----------------- 3 files changed, 11 insertions(+), 44 deletions(-) diff --git a/kiauh/components/webui_client/client_config/client_config_remove.py b/kiauh/components/webui_client/client_config/client_config_remove.py index dc3eb39..22d00fb 100644 --- a/kiauh/components/webui_client/client_config/client_config_remove.py +++ b/kiauh/components/webui_client/client_config/client_config_remove.py @@ -24,19 +24,13 @@ from utils.logger import Logger def run_client_config_removal( client_config: ClientConfigData, - remove_moonraker_conf_section: bool, - remove_printer_cfg_include: bool, kl_instances: List[Klipper], mr_instances: List[Moonraker], ) -> None: remove_client_config_dir(client_config) remove_client_config_symlink(client_config) - if remove_moonraker_conf_section: - remove_config_section( - f"update_manager {client_config.get('name')}", mr_instances - ) - if remove_printer_cfg_include: - remove_config_section(client_config.get("printer_cfg_section"), kl_instances) + remove_config_section(f"update_manager {client_config.get('name')}", mr_instances) + remove_config_section(client_config.get("printer_cfg_section"), kl_instances) def remove_client_config_dir(client_config: ClientConfigData) -> None: diff --git a/kiauh/components/webui_client/client_remove.py b/kiauh/components/webui_client/client_remove.py index 49bc694..7a8648c 100644 --- a/kiauh/components/webui_client/client_remove.py +++ b/kiauh/components/webui_client/client_remove.py @@ -35,28 +35,27 @@ def run_client_removal( rm_client: bool, rm_client_config: bool, backup_ms_config_json: bool, - rm_moonraker_conf_section: bool, - rm_printer_cfg_section: bool, ) -> None: mr_im = InstanceManager(Moonraker) mr_instances: List[Moonraker] = mr_im.instances kl_im = InstanceManager(Klipper) kl_instances: List[Klipper] = kl_im.instances + if backup_ms_config_json and client.get("name") == "mainsail": backup_mainsail_config_json() + if rm_client: client_name = client.get("name") remove_client_dir(client) remove_nginx_config(client_name) remove_nginx_logs(client_name) - if rm_moonraker_conf_section: - section = f"update_manager {client_name}" - remove_config_section(section, mr_instances) + + section = f"update_manager {client_name}" + remove_config_section(section, mr_instances) + if rm_client_config: run_client_config_removal( client.get("client_config"), - rm_moonraker_conf_section, - rm_printer_cfg_section, kl_instances, mr_instances, ) diff --git a/kiauh/components/webui_client/menus/client_remove_menu.py b/kiauh/components/webui_client/menus/client_remove_menu.py index b4648d6..6db4097 100644 --- a/kiauh/components/webui_client/menus/client_remove_menu.py +++ b/kiauh/components/webui_client/menus/client_remove_menu.py @@ -25,8 +25,6 @@ class ClientRemoveMenu(BaseMenu): self.rm_client = False self.rm_client_config = False self.backup_mainsail_config_json = False - self.rm_moonraker_conf_section = False - self.rm_printer_cfg_section = False super().__init__( header=False, @@ -39,12 +37,10 @@ class ClientRemoveMenu(BaseMenu): "0": self.toggle_all, "1": self.toggle_rm_client, "2": self.toggle_rm_client_config, - "3": self.toggle_rm_printer_cfg_section, - "4": self.toggle_rm_moonraker_conf_section, "c": self.run_removal_process, } if self.client.get("name") == "mainsail": - options["5"] = self.toggle_backup_mainsail_config_json + options["3"] = self.toggle_backup_mainsail_config_json return options @@ -60,8 +56,6 @@ class ClientRemoveMenu(BaseMenu): unchecked = "[ ]" o1 = checked if self.rm_client else unchecked o2 = checked if self.rm_client_config else unchecked - o3 = checked if self.rm_printer_cfg_section else unchecked - o4 = checked if self.rm_moonraker_conf_section else unchecked menu = textwrap.dedent( f""" /=======================================================\\ @@ -74,20 +68,14 @@ class ClientRemoveMenu(BaseMenu): |-------------------------------------------------------| | 1) {o1} Remove {client_name:16} | | 2) {o2} Remove {client_config_name:24} | - | | - | printer.cfg & moonraker.conf | - | 3) {o3} Remove printer.cfg include | - | 4) {o4} Remove Moonraker update section | """ )[1:] if self.client.get("name") == "mainsail": - o5 = checked if self.backup_mainsail_config_json else unchecked + o3 = checked if self.backup_mainsail_config_json else unchecked menu += textwrap.dedent( f""" - | | - | Mainsail config.json | - | 5) {o5} Backup config.json | + | 3) {o3} Backup config.json | """ )[1:] @@ -103,8 +91,6 @@ class ClientRemoveMenu(BaseMenu): self.rm_client = True self.rm_client_config = True self.backup_mainsail_config_json = True - self.rm_moonraker_conf_section = True - self.rm_printer_cfg_section = True def toggle_rm_client(self, **kwargs) -> None: self.rm_client = not self.rm_client @@ -115,19 +101,11 @@ class ClientRemoveMenu(BaseMenu): def toggle_backup_mainsail_config_json(self, **kwargs) -> None: self.backup_mainsail_config_json = not self.backup_mainsail_config_json - def toggle_rm_moonraker_conf_section(self, **kwargs) -> None: - self.rm_moonraker_conf_section = not self.rm_moonraker_conf_section - - def toggle_rm_printer_cfg_section(self, **kwargs) -> None: - self.rm_printer_cfg_section = not self.rm_printer_cfg_section - def run_removal_process(self, **kwargs) -> None: if ( not self.rm_client and not self.rm_client_config and not self.backup_mainsail_config_json - and not self.rm_moonraker_conf_section - and not self.rm_printer_cfg_section ): error = f"{COLOR_RED}Nothing selected ...{RESET_FORMAT}" print(error) @@ -138,12 +116,8 @@ class ClientRemoveMenu(BaseMenu): rm_client=self.rm_client, rm_client_config=self.rm_client_config, backup_ms_config_json=self.backup_mainsail_config_json, - rm_moonraker_conf_section=self.rm_moonraker_conf_section, - rm_printer_cfg_section=self.rm_printer_cfg_section, ) self.rm_client = False self.rm_client_config = False self.backup_mainsail_config_json = False - self.rm_moonraker_conf_section = False - self.rm_printer_cfg_section = False