mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-25 16:53:36 +05:00
fix: disallow installing client config if another client config is installed
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
@@ -20,7 +20,7 @@ from components.webui_client.client_dialogs import (
|
|||||||
)
|
)
|
||||||
from components.webui_client.client_utils import (
|
from components.webui_client.client_utils import (
|
||||||
backup_client_config_data,
|
backup_client_config_data,
|
||||||
config_for_other_client_exist,
|
detect_client_cfg_conflict,
|
||||||
)
|
)
|
||||||
from core.instance_manager.instance_manager import InstanceManager
|
from core.instance_manager.instance_manager import InstanceManager
|
||||||
from core.settings.kiauh_settings import KiauhSettings
|
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
|
client_config: BaseWebClientConfig = client_data.client_config
|
||||||
display_name = client_config.display_name
|
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 ...")
|
Logger.print_info("Another Client-Config is already installed! Skipped ...")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ from components.webui_client.client_dialogs import (
|
|||||||
)
|
)
|
||||||
from components.webui_client.client_utils import (
|
from components.webui_client.client_utils import (
|
||||||
backup_mainsail_config_json,
|
backup_mainsail_config_json,
|
||||||
config_for_other_client_exist,
|
detect_client_cfg_conflict,
|
||||||
enable_mainsail_remotemode,
|
enable_mainsail_remotemode,
|
||||||
restore_mainsail_config_json,
|
restore_mainsail_config_json,
|
||||||
symlink_webui_nginx_log,
|
symlink_webui_nginx_log,
|
||||||
@@ -90,7 +90,7 @@ def install_client(client: BaseWebClient) -> None:
|
|||||||
if (
|
if (
|
||||||
kl_instances
|
kl_instances
|
||||||
and not client_config.config_dir.exists()
|
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)
|
print_install_client_config_dialog(client)
|
||||||
question = f"Download the recommended {client_config.display_name}?"
|
question = f"Download the recommended {client_config.display_name}?"
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
# ======================================================================= #
|
# ======================================================================= #
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import json # noqa: I001
|
import json
|
||||||
import shutil
|
import shutil
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List, get_args
|
from typing import List, get_args
|
||||||
@@ -16,9 +16,9 @@ from typing import List, get_args
|
|||||||
from components.klipper.klipper import Klipper
|
from components.klipper.klipper import Klipper
|
||||||
from components.webui_client.base_data import (
|
from components.webui_client.base_data import (
|
||||||
BaseWebClient,
|
BaseWebClient,
|
||||||
BaseWebClientConfig,
|
|
||||||
WebClientType,
|
WebClientType,
|
||||||
)
|
)
|
||||||
|
from components.webui_client.fluidd_data import FluiddData
|
||||||
from components.webui_client.mainsail_data import MainsailData
|
from components.webui_client.mainsail_data import MainsailData
|
||||||
from core.backup_manager.backup_manager import BackupManager
|
from core.backup_manager.backup_manager import BackupManager
|
||||||
from core.settings.kiauh_settings import KiauhSettings
|
from core.settings.kiauh_settings import KiauhSettings
|
||||||
@@ -187,30 +187,24 @@ def get_existing_clients() -> List[BaseWebClient]:
|
|||||||
return installed_clients
|
return installed_clients
|
||||||
|
|
||||||
|
|
||||||
def get_existing_client_config() -> List[BaseWebClient]:
|
def detect_client_cfg_conflict(curr_client: BaseWebClient) -> bool:
|
||||||
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:
|
|
||||||
"""
|
"""
|
||||||
Check if any other client configs are present on the system.
|
Check if any other client configs are present on the system.
|
||||||
It is usually not harmful, but chances are they can conflict each other.
|
It is usually not harmful, but chances are they can conflict each other.
|
||||||
Multiple client configs are, at least, redundant to have them installed
|
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
|
:return: True, if other client configs were found, else False
|
||||||
"""
|
"""
|
||||||
|
|
||||||
clients = set([c.name for c in get_existing_client_config()])
|
mainsail_cfg_status: ComponentStatus = get_client_config_status(MainsailData())
|
||||||
clients = clients - {client_to_ignore.value}
|
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:
|
def get_download_url(base_url: str, client: BaseWebClient) -> str:
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ from components.webui_client.base_data import (
|
|||||||
WebClientConfigType,
|
WebClientConfigType,
|
||||||
WebClientType,
|
WebClientType,
|
||||||
)
|
)
|
||||||
from components.webui_client.client_utils import get_download_url
|
|
||||||
from core.backup_manager import BACKUP_ROOT_DIR
|
from core.backup_manager import BACKUP_ROOT_DIR
|
||||||
|
|
||||||
|
|
||||||
@@ -47,6 +46,8 @@ class FluiddData(BaseWebClient):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def download_url(self) -> str:
|
def download_url(self) -> str:
|
||||||
|
from components.webui_client.client_utils import get_download_url
|
||||||
|
|
||||||
return get_download_url(self.BASE_DL_URL, self)
|
return get_download_url(self.BASE_DL_URL, self)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|||||||
Reference in New Issue
Block a user