refactor(webclients): always remove config sections

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
dw-0
2024-03-20 22:10:51 +01:00
parent 9eb0531cdf
commit 7ec055f562
3 changed files with 11 additions and 44 deletions

View File

@@ -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:

View File

@@ -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,
)

View File

@@ -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