From 01deab7c64b5e30ae330e1bf76b1e888e25feb0e Mon Sep 17 00:00:00 2001 From: dw-0 Date: Sun, 30 Jun 2024 20:51:04 +0200 Subject: [PATCH] fix: disallow installing client config if another client config is installed Signed-off-by: Dominik Willner --- .../client_config/client_config_setup.py | 4 +-- kiauh/components/webui_client/client_setup.py | 4 +-- kiauh/components/webui_client/client_utils.py | 30 ++++++++----------- kiauh/components/webui_client/fluidd_data.py | 3 +- 4 files changed, 18 insertions(+), 23 deletions(-) diff --git a/kiauh/components/webui_client/client_config/client_config_setup.py b/kiauh/components/webui_client/client_config/client_config_setup.py index 05c26bb..e1aadc2 100644 --- a/kiauh/components/webui_client/client_config/client_config_setup.py +++ b/kiauh/components/webui_client/client_config/client_config_setup.py @@ -20,7 +20,7 @@ from components.webui_client.client_dialogs import ( ) from components.webui_client.client_utils import ( backup_client_config_data, - config_for_other_client_exist, + detect_client_cfg_conflict, ) from core.instance_manager.instance_manager import InstanceManager from core.settings.kiauh_settings import KiauhSettings @@ -36,7 +36,7 @@ def install_client_config(client_data: BaseWebClient) -> None: client_config: BaseWebClientConfig = client_data.client_config display_name = client_config.display_name - if config_for_other_client_exist(client_data.client): + if detect_client_cfg_conflict(client_data): Logger.print_info("Another Client-Config is already installed! Skipped ...") return diff --git a/kiauh/components/webui_client/client_setup.py b/kiauh/components/webui_client/client_setup.py index c8f671a..06e2686 100644 --- a/kiauh/components/webui_client/client_setup.py +++ b/kiauh/components/webui_client/client_setup.py @@ -28,7 +28,7 @@ from components.webui_client.client_dialogs import ( ) from components.webui_client.client_utils import ( backup_mainsail_config_json, - config_for_other_client_exist, + detect_client_cfg_conflict, enable_mainsail_remotemode, restore_mainsail_config_json, symlink_webui_nginx_log, @@ -90,7 +90,7 @@ def install_client(client: BaseWebClient) -> None: if ( kl_instances and not client_config.config_dir.exists() - and not config_for_other_client_exist(client_to_ignore=client.client) + and not detect_client_cfg_conflict(client) ): print_install_client_config_dialog(client) question = f"Download the recommended {client_config.display_name}?" diff --git a/kiauh/components/webui_client/client_utils.py b/kiauh/components/webui_client/client_utils.py index 1548876..e964428 100644 --- a/kiauh/components/webui_client/client_utils.py +++ b/kiauh/components/webui_client/client_utils.py @@ -8,7 +8,7 @@ # ======================================================================= # from __future__ import annotations -import json # noqa: I001 +import json import shutil from pathlib import Path from typing import List, get_args @@ -16,9 +16,9 @@ from typing import List, get_args from components.klipper.klipper import Klipper from components.webui_client.base_data import ( BaseWebClient, - BaseWebClientConfig, WebClientType, ) +from components.webui_client.fluidd_data import FluiddData from components.webui_client.mainsail_data import MainsailData from core.backup_manager.backup_manager import BackupManager from core.settings.kiauh_settings import KiauhSettings @@ -187,30 +187,24 @@ def get_existing_clients() -> List[BaseWebClient]: return installed_clients -def get_existing_client_config() -> List[BaseWebClient]: - clients = list(get_args(WebClientType)) - installed_client_configs: List[BaseWebClient] = [] - for client in clients: - c_config_data: BaseWebClientConfig = client.client_config - if c_config_data.config_dir.exists(): - installed_client_configs.append(client) - - return installed_client_configs - - -def config_for_other_client_exist(client_to_ignore: WebClientType) -> bool: +def detect_client_cfg_conflict(curr_client: BaseWebClient) -> bool: """ Check if any other client configs are present on the system. It is usually not harmful, but chances are they can conflict each other. Multiple client configs are, at least, redundant to have them installed - :param client_to_ignore: The client name to ignore for the check + :param curr_client: The client name to check for the conflict :return: True, if other client configs were found, else False """ - clients = set([c.name for c in get_existing_client_config()]) - clients = clients - {client_to_ignore.value} + mainsail_cfg_status: ComponentStatus = get_client_config_status(MainsailData()) + fluidd_cfg_status: ComponentStatus = get_client_config_status(FluiddData()) - return True if len(clients) > 0 else False + if curr_client.client == WebClientType.MAINSAIL and fluidd_cfg_status.status == 2: + return True + if curr_client.client == WebClientType.FLUIDD and mainsail_cfg_status.status == 2: + return True + + return False def get_download_url(base_url: str, client: BaseWebClient) -> str: diff --git a/kiauh/components/webui_client/fluidd_data.py b/kiauh/components/webui_client/fluidd_data.py index 59e75d6..29738c4 100644 --- a/kiauh/components/webui_client/fluidd_data.py +++ b/kiauh/components/webui_client/fluidd_data.py @@ -18,7 +18,6 @@ from components.webui_client.base_data import ( WebClientConfigType, WebClientType, ) -from components.webui_client.client_utils import get_download_url from core.backup_manager import BACKUP_ROOT_DIR @@ -47,6 +46,8 @@ class FluiddData(BaseWebClient): @property def download_url(self) -> str: + from components.webui_client.client_utils import get_download_url + return get_download_url(self.BASE_DL_URL, self) @property