refactor(webclients): always remove config sections
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
@@ -24,19 +24,13 @@ from utils.logger import Logger
|
|||||||
|
|
||||||
def run_client_config_removal(
|
def run_client_config_removal(
|
||||||
client_config: ClientConfigData,
|
client_config: ClientConfigData,
|
||||||
remove_moonraker_conf_section: bool,
|
|
||||||
remove_printer_cfg_include: bool,
|
|
||||||
kl_instances: List[Klipper],
|
kl_instances: List[Klipper],
|
||||||
mr_instances: List[Moonraker],
|
mr_instances: List[Moonraker],
|
||||||
) -> None:
|
) -> None:
|
||||||
remove_client_config_dir(client_config)
|
remove_client_config_dir(client_config)
|
||||||
remove_client_config_symlink(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)
|
||||||
remove_config_section(
|
remove_config_section(client_config.get("printer_cfg_section"), kl_instances)
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
def remove_client_config_dir(client_config: ClientConfigData) -> None:
|
def remove_client_config_dir(client_config: ClientConfigData) -> None:
|
||||||
|
|||||||
@@ -35,28 +35,27 @@ def run_client_removal(
|
|||||||
rm_client: bool,
|
rm_client: bool,
|
||||||
rm_client_config: bool,
|
rm_client_config: bool,
|
||||||
backup_ms_config_json: bool,
|
backup_ms_config_json: bool,
|
||||||
rm_moonraker_conf_section: bool,
|
|
||||||
rm_printer_cfg_section: bool,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
mr_im = InstanceManager(Moonraker)
|
mr_im = InstanceManager(Moonraker)
|
||||||
mr_instances: List[Moonraker] = mr_im.instances
|
mr_instances: List[Moonraker] = mr_im.instances
|
||||||
kl_im = InstanceManager(Klipper)
|
kl_im = InstanceManager(Klipper)
|
||||||
kl_instances: List[Klipper] = kl_im.instances
|
kl_instances: List[Klipper] = kl_im.instances
|
||||||
|
|
||||||
if backup_ms_config_json and client.get("name") == "mainsail":
|
if backup_ms_config_json and client.get("name") == "mainsail":
|
||||||
backup_mainsail_config_json()
|
backup_mainsail_config_json()
|
||||||
|
|
||||||
if rm_client:
|
if rm_client:
|
||||||
client_name = client.get("name")
|
client_name = client.get("name")
|
||||||
remove_client_dir(client)
|
remove_client_dir(client)
|
||||||
remove_nginx_config(client_name)
|
remove_nginx_config(client_name)
|
||||||
remove_nginx_logs(client_name)
|
remove_nginx_logs(client_name)
|
||||||
if rm_moonraker_conf_section:
|
|
||||||
section = f"update_manager {client_name}"
|
section = f"update_manager {client_name}"
|
||||||
remove_config_section(section, mr_instances)
|
remove_config_section(section, mr_instances)
|
||||||
|
|
||||||
if rm_client_config:
|
if rm_client_config:
|
||||||
run_client_config_removal(
|
run_client_config_removal(
|
||||||
client.get("client_config"),
|
client.get("client_config"),
|
||||||
rm_moonraker_conf_section,
|
|
||||||
rm_printer_cfg_section,
|
|
||||||
kl_instances,
|
kl_instances,
|
||||||
mr_instances,
|
mr_instances,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -25,8 +25,6 @@ class ClientRemoveMenu(BaseMenu):
|
|||||||
self.rm_client = False
|
self.rm_client = False
|
||||||
self.rm_client_config = False
|
self.rm_client_config = False
|
||||||
self.backup_mainsail_config_json = False
|
self.backup_mainsail_config_json = False
|
||||||
self.rm_moonraker_conf_section = False
|
|
||||||
self.rm_printer_cfg_section = False
|
|
||||||
|
|
||||||
super().__init__(
|
super().__init__(
|
||||||
header=False,
|
header=False,
|
||||||
@@ -39,12 +37,10 @@ class ClientRemoveMenu(BaseMenu):
|
|||||||
"0": self.toggle_all,
|
"0": self.toggle_all,
|
||||||
"1": self.toggle_rm_client,
|
"1": self.toggle_rm_client,
|
||||||
"2": self.toggle_rm_client_config,
|
"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,
|
"c": self.run_removal_process,
|
||||||
}
|
}
|
||||||
if self.client.get("name") == "mainsail":
|
if self.client.get("name") == "mainsail":
|
||||||
options["5"] = self.toggle_backup_mainsail_config_json
|
options["3"] = self.toggle_backup_mainsail_config_json
|
||||||
|
|
||||||
return options
|
return options
|
||||||
|
|
||||||
@@ -60,8 +56,6 @@ class ClientRemoveMenu(BaseMenu):
|
|||||||
unchecked = "[ ]"
|
unchecked = "[ ]"
|
||||||
o1 = checked if self.rm_client else unchecked
|
o1 = checked if self.rm_client else unchecked
|
||||||
o2 = checked if self.rm_client_config 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(
|
menu = textwrap.dedent(
|
||||||
f"""
|
f"""
|
||||||
/=======================================================\\
|
/=======================================================\\
|
||||||
@@ -74,20 +68,14 @@ class ClientRemoveMenu(BaseMenu):
|
|||||||
|-------------------------------------------------------|
|
|-------------------------------------------------------|
|
||||||
| 1) {o1} Remove {client_name:16} |
|
| 1) {o1} Remove {client_name:16} |
|
||||||
| 2) {o2} Remove {client_config_name:24} |
|
| 2) {o2} Remove {client_config_name:24} |
|
||||||
| |
|
|
||||||
| printer.cfg & moonraker.conf |
|
|
||||||
| 3) {o3} Remove printer.cfg include |
|
|
||||||
| 4) {o4} Remove Moonraker update section |
|
|
||||||
"""
|
"""
|
||||||
)[1:]
|
)[1:]
|
||||||
|
|
||||||
if self.client.get("name") == "mainsail":
|
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(
|
menu += textwrap.dedent(
|
||||||
f"""
|
f"""
|
||||||
| |
|
| 3) {o3} Backup config.json |
|
||||||
| Mainsail config.json |
|
|
||||||
| 5) {o5} Backup config.json |
|
|
||||||
"""
|
"""
|
||||||
)[1:]
|
)[1:]
|
||||||
|
|
||||||
@@ -103,8 +91,6 @@ class ClientRemoveMenu(BaseMenu):
|
|||||||
self.rm_client = True
|
self.rm_client = True
|
||||||
self.rm_client_config = True
|
self.rm_client_config = True
|
||||||
self.backup_mainsail_config_json = 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:
|
def toggle_rm_client(self, **kwargs) -> None:
|
||||||
self.rm_client = not self.rm_client
|
self.rm_client = not self.rm_client
|
||||||
@@ -115,19 +101,11 @@ class ClientRemoveMenu(BaseMenu):
|
|||||||
def toggle_backup_mainsail_config_json(self, **kwargs) -> None:
|
def toggle_backup_mainsail_config_json(self, **kwargs) -> None:
|
||||||
self.backup_mainsail_config_json = not self.backup_mainsail_config_json
|
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:
|
def run_removal_process(self, **kwargs) -> None:
|
||||||
if (
|
if (
|
||||||
not self.rm_client
|
not self.rm_client
|
||||||
and not self.rm_client_config
|
and not self.rm_client_config
|
||||||
and not self.backup_mainsail_config_json
|
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}"
|
error = f"{COLOR_RED}Nothing selected ...{RESET_FORMAT}"
|
||||||
print(error)
|
print(error)
|
||||||
@@ -138,12 +116,8 @@ class ClientRemoveMenu(BaseMenu):
|
|||||||
rm_client=self.rm_client,
|
rm_client=self.rm_client,
|
||||||
rm_client_config=self.rm_client_config,
|
rm_client_config=self.rm_client_config,
|
||||||
backup_ms_config_json=self.backup_mainsail_config_json,
|
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 = False
|
||||||
self.rm_client_config = False
|
self.rm_client_config = False
|
||||||
self.backup_mainsail_config_json = False
|
self.backup_mainsail_config_json = False
|
||||||
self.rm_moonraker_conf_section = False
|
|
||||||
self.rm_printer_cfg_section = False
|
|
||||||
|
|||||||
Reference in New Issue
Block a user