Files
kiauh/kiauh/components/webui_client/client_remove.py
dw-0 231e9d134a refactor: move logger to core
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-08-11 16:09:30 +02:00

67 lines
2.3 KiB
Python

# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/dw-0/kiauh #
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
# ======================================================================= #
from typing import List
from components.klipper.klipper import Klipper
from components.moonraker.moonraker import Moonraker
from components.webui_client.base_data import (
BaseWebClient,
WebClientType,
)
from components.webui_client.client_config.client_config_remove import (
run_client_config_removal,
)
from components.webui_client.client_utils import backup_mainsail_config_json
from core.instance_manager.instance_manager import InstanceManager
from core.logger import Logger
from utils.config_utils import remove_config_section
from utils.fs_utils import (
remove_nginx_config,
remove_nginx_logs,
run_remove_routines,
)
def run_client_removal(
client: BaseWebClient,
remove_client: bool,
remove_client_cfg: bool,
backup_ms_config_json: 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.client == WebClientType.MAINSAIL:
backup_mainsail_config_json()
if remove_client:
client_name = client.name
remove_client_dir(client)
remove_nginx_config(client_name)
remove_nginx_logs(client_name, kl_instances)
section = f"update_manager {client_name}"
remove_config_section(section, mr_instances)
if remove_client_cfg:
run_client_config_removal(
client.client_config,
kl_instances,
mr_instances,
)
def remove_client_dir(client: BaseWebClient) -> None:
Logger.print_status(f"Removing {client.display_name} ...")
run_remove_routines(client.client_dir)