mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-13 02:24:27 +05:00
feat: implement completion message for webclient config remove process
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
@@ -18,6 +18,7 @@ from core.services.message_service import Message
|
|||||||
from core.types.color import Color
|
from core.types.color import Color
|
||||||
from utils.config_utils import remove_config_section
|
from utils.config_utils import remove_config_section
|
||||||
from utils.fs_utils import run_remove_routines
|
from utils.fs_utils import run_remove_routines
|
||||||
|
from utils.instance_type import InstanceType
|
||||||
from utils.instance_utils import get_instances
|
from utils.instance_utils import get_instances
|
||||||
|
|
||||||
|
|
||||||
@@ -34,40 +35,57 @@ def run_client_config_removal(
|
|||||||
if run_remove_routines(client_config.config_dir):
|
if run_remove_routines(client_config.config_dir):
|
||||||
completion_msg.text.append(f"● {client_config.display_name} removed")
|
completion_msg.text.append(f"● {client_config.display_name} removed")
|
||||||
|
|
||||||
instances: List[Klipper] = get_instances(Klipper)
|
completion_msg = remove_moonraker_config_section(
|
||||||
handled_configs = []
|
completion_msg, client_config, mr_instances
|
||||||
for instance in instances:
|
)
|
||||||
if run_remove_routines(
|
|
||||||
instance.base.cfg_dir.joinpath(client_config.config_filename)
|
|
||||||
):
|
|
||||||
handled_configs.append(instance)
|
|
||||||
if handled_configs:
|
|
||||||
instance_names = [i.service_file_path.stem for i in handled_configs]
|
|
||||||
completion_msg.text.append(
|
|
||||||
f"● {client_config.display_name} removed from instances: {', '.join(instance_names)}"
|
|
||||||
)
|
|
||||||
|
|
||||||
mr_section = f"update_manager {client_config.name}"
|
completion_msg = remove_printer_config_section(
|
||||||
handled_mr_instances = remove_config_section(mr_section, mr_instances)
|
completion_msg, client_config, kl_instances
|
||||||
if handled_mr_instances:
|
)
|
||||||
instance_names = [i.service_file_path.stem for i in handled_mr_instances]
|
|
||||||
completion_msg.text.append(
|
|
||||||
f"● Moonraker config section '{mr_section}' removed for instance: {', '.join(instance_names)}"
|
|
||||||
)
|
|
||||||
|
|
||||||
kl_section = client_config.config_section
|
if completion_msg.text:
|
||||||
handled_kl_instances = remove_config_section(kl_section, kl_instances)
|
completion_msg.text.insert(0, "The following actions were performed:")
|
||||||
if handled_kl_instances:
|
else:
|
||||||
instance_names = [i.service_file_path.stem for i in handled_kl_instances]
|
|
||||||
completion_msg.text.append(
|
|
||||||
f"● Klipper config section '{mr_section}' removed for instance: {', '.join(instance_names)}"
|
|
||||||
)
|
|
||||||
|
|
||||||
if not completion_msg.text:
|
|
||||||
completion_msg.color = Color.YELLOW
|
completion_msg.color = Color.YELLOW
|
||||||
completion_msg.centered = True
|
completion_msg.centered = True
|
||||||
completion_msg.text.append("Nothing to remove.")
|
completion_msg.text = ["Nothing to remove."]
|
||||||
else:
|
|
||||||
completion_msg.text.insert(0, "The following actions were performed:")
|
|
||||||
|
|
||||||
return completion_msg
|
return completion_msg
|
||||||
|
|
||||||
|
|
||||||
|
def remove_cfg_symlink(client_config: BaseWebClientConfig, message: Message) -> Message:
|
||||||
|
instances: List[Klipper] = get_instances(Klipper)
|
||||||
|
kl_instances = []
|
||||||
|
for instance in instances:
|
||||||
|
cfg = instance.base.cfg_dir.joinpath(client_config.config_filename)
|
||||||
|
if run_remove_routines(cfg):
|
||||||
|
kl_instances.append(instance)
|
||||||
|
text = f"{client_config.display_name} removed from instance"
|
||||||
|
return update_msg(kl_instances, message, text)
|
||||||
|
|
||||||
|
|
||||||
|
def remove_printer_config_section(
|
||||||
|
message: Message, client_config: BaseWebClientConfig, kl_instances: List[Klipper]
|
||||||
|
) -> Message:
|
||||||
|
kl_section = client_config.config_section
|
||||||
|
kl_instances = remove_config_section(kl_section, kl_instances)
|
||||||
|
text = f"Klipper config section '{kl_section}' removed for instance"
|
||||||
|
return update_msg(kl_instances, message, text)
|
||||||
|
|
||||||
|
|
||||||
|
def remove_moonraker_config_section(
|
||||||
|
message: Message, client_config: BaseWebClientConfig, mr_instances: List[Moonraker]
|
||||||
|
) -> Message:
|
||||||
|
mr_section = f"update_manager {client_config.name}"
|
||||||
|
mr_instances = remove_config_section(mr_section, mr_instances)
|
||||||
|
text = f"Moonraker config section '{mr_section}' removed for instance"
|
||||||
|
return update_msg(mr_instances, message, text)
|
||||||
|
|
||||||
|
|
||||||
|
def update_msg(instances: List[InstanceType], message: Message, text: str) -> Message:
|
||||||
|
if not instances:
|
||||||
|
return message
|
||||||
|
|
||||||
|
instance_names = [i.service_file_path.stem for i in instances]
|
||||||
|
message.text.append(f"● {text}: {', '.join(instance_names)}")
|
||||||
|
return message
|
||||||
|
|||||||
Reference in New Issue
Block a user