mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-23 15:53:36 +05:00
Compare commits
3 Commits
8df75dc8d0
...
655b781aef
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
655b781aef | ||
|
|
14aafd558a | ||
|
|
bd1aa1ae2b |
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
from components.webui_client.client_utils import get_existing_client_config
|
||||||
from kiauh import KIAUH_CFG
|
from kiauh import KIAUH_CFG
|
||||||
from components.klipper import (
|
from components.klipper import (
|
||||||
EXIT_KLIPPER_SETUP,
|
EXIT_KLIPPER_SETUP,
|
||||||
@@ -180,5 +181,7 @@ def create_klipper_instance(name: str, create_example_cfg: bool) -> None:
|
|||||||
kl_im.create_instance()
|
kl_im.create_instance()
|
||||||
kl_im.enable_instance()
|
kl_im.enable_instance()
|
||||||
if create_example_cfg:
|
if create_example_cfg:
|
||||||
create_example_printer_cfg(new_instance)
|
# if a client-config is installed, include it in the new example cfg
|
||||||
|
client_configs = get_existing_client_config()
|
||||||
|
create_example_printer_cfg(new_instance, client_configs)
|
||||||
kl_im.start_instance()
|
kl_im.start_instance()
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import shutil
|
|||||||
import subprocess
|
import subprocess
|
||||||
import textwrap
|
import textwrap
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List, Union, Literal, Dict
|
from typing import List, Union, Literal, Dict, Optional
|
||||||
|
|
||||||
from components.klipper import (
|
from components.klipper import (
|
||||||
MODULE_PATH,
|
MODULE_PATH,
|
||||||
@@ -33,6 +33,7 @@ from components.klipper.klipper_dialogs import (
|
|||||||
)
|
)
|
||||||
from components.moonraker.moonraker import Moonraker
|
from components.moonraker.moonraker import Moonraker
|
||||||
from components.moonraker.moonraker_utils import moonraker_to_multi_conversion
|
from components.moonraker.moonraker_utils import moonraker_to_multi_conversion
|
||||||
|
from components.webui_client import ClientData
|
||||||
from core.backup_manager.backup_manager import BackupManager
|
from core.backup_manager.backup_manager import BackupManager
|
||||||
from core.config_manager.config_manager import ConfigManager
|
from core.config_manager.config_manager import ConfigManager
|
||||||
from core.instance_manager.base_instance import BaseInstance
|
from core.instance_manager.base_instance import BaseInstance
|
||||||
@@ -261,7 +262,9 @@ def get_highest_index(instance_list: List[Klipper]) -> int:
|
|||||||
return max(indices)
|
return max(indices)
|
||||||
|
|
||||||
|
|
||||||
def create_example_printer_cfg(instance: Klipper) -> None:
|
def create_example_printer_cfg(
|
||||||
|
instance: Klipper, client_configs: Optional[List[ClientData]] = None
|
||||||
|
) -> None:
|
||||||
Logger.print_status(f"Creating example printer.cfg in '{instance.cfg_dir}'")
|
Logger.print_status(f"Creating example printer.cfg in '{instance.cfg_dir}'")
|
||||||
if instance.cfg_file.is_file():
|
if instance.cfg_file.is_file():
|
||||||
Logger.print_info(f"'{instance.cfg_file}' already exists.")
|
Logger.print_info(f"'{instance.cfg_file}' already exists.")
|
||||||
@@ -277,7 +280,15 @@ def create_example_printer_cfg(instance: Klipper) -> None:
|
|||||||
|
|
||||||
cm = ConfigManager(target)
|
cm = ConfigManager(target)
|
||||||
cm.set_value("virtual_sdcard", "path", str(instance.gcodes_dir))
|
cm.set_value("virtual_sdcard", "path", str(instance.gcodes_dir))
|
||||||
|
|
||||||
|
# include existing client configs in the example config
|
||||||
|
if client_configs is not None and len(client_configs) > 0:
|
||||||
|
for c in client_configs:
|
||||||
|
section = c.get("client_config").get("printer_cfg_section")
|
||||||
|
cm.config.add_section(section=section)
|
||||||
|
|
||||||
cm.write_config()
|
cm.write_config()
|
||||||
|
|
||||||
Logger.print_ok(f"Example printer.cfg created in '{instance.cfg_dir}'")
|
Logger.print_ok(f"Example printer.cfg created in '{instance.cfg_dir}'")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ from pathlib import Path
|
|||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from components.webui_client import MAINSAIL_DIR
|
from components.webui_client import MAINSAIL_DIR
|
||||||
from components.webui_client.client_utils import enable_mainsail_remotemode
|
from components.webui_client.client_utils import enable_mainsail_remotemode, get_existing_clients
|
||||||
from kiauh import KIAUH_CFG
|
from kiauh import KIAUH_CFG
|
||||||
from components.klipper.klipper import Klipper
|
from components.klipper.klipper import Klipper
|
||||||
from components.klipper.klipper_dialogs import print_instance_overview
|
from components.klipper.klipper_dialogs import print_instance_overview
|
||||||
@@ -104,7 +104,9 @@ def install_moonraker() -> None:
|
|||||||
mr_im.enable_instance()
|
mr_im.enable_instance()
|
||||||
|
|
||||||
if create_example_cfg:
|
if create_example_cfg:
|
||||||
create_example_moonraker_conf(current_instance, used_ports_map)
|
# if a webclient and/or it's config is installed, patch its update section to the config
|
||||||
|
clients = get_existing_clients()
|
||||||
|
create_example_moonraker_conf(current_instance, used_ports_map, clients)
|
||||||
|
|
||||||
mr_im.start_instance()
|
mr_im.start_instance()
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
# ======================================================================= #
|
# ======================================================================= #
|
||||||
|
|
||||||
import shutil
|
import shutil
|
||||||
from typing import Dict, Literal, List, Union
|
from typing import Dict, Literal, List, Union, Optional
|
||||||
|
|
||||||
from components.moonraker import (
|
from components.moonraker import (
|
||||||
DEFAULT_MOONRAKER_PORT,
|
DEFAULT_MOONRAKER_PORT,
|
||||||
@@ -21,7 +21,7 @@ from components.moonraker import (
|
|||||||
MOONRAKER_DB_BACKUP_DIR,
|
MOONRAKER_DB_BACKUP_DIR,
|
||||||
)
|
)
|
||||||
from components.moonraker.moonraker import Moonraker
|
from components.moonraker.moonraker import Moonraker
|
||||||
from components.webui_client import MAINSAIL_DIR
|
from components.webui_client import MAINSAIL_DIR, ClientData
|
||||||
from components.webui_client.client_utils import enable_mainsail_remotemode
|
from components.webui_client.client_utils import enable_mainsail_remotemode
|
||||||
from core.backup_manager.backup_manager import BackupManager
|
from core.backup_manager.backup_manager import BackupManager
|
||||||
from core.config_manager.config_manager import ConfigManager
|
from core.config_manager.config_manager import ConfigManager
|
||||||
@@ -50,7 +50,9 @@ def get_moonraker_status() -> Dict[
|
|||||||
|
|
||||||
|
|
||||||
def create_example_moonraker_conf(
|
def create_example_moonraker_conf(
|
||||||
instance: Moonraker, ports_map: Dict[str, int]
|
instance: Moonraker,
|
||||||
|
ports_map: Dict[str, int],
|
||||||
|
clients: Optional[List[ClientData]] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
Logger.print_status(f"Creating example moonraker.conf in '{instance.cfg_dir}'")
|
Logger.print_status(f"Creating example moonraker.conf in '{instance.cfg_dir}'")
|
||||||
if instance.cfg_file.is_file():
|
if instance.cfg_file.is_file():
|
||||||
@@ -94,6 +96,36 @@ def create_example_moonraker_conf(
|
|||||||
cm.set_value("server", "klippy_uds_address", str(uds))
|
cm.set_value("server", "klippy_uds_address", str(uds))
|
||||||
cm.set_value("authorization", "trusted_clients", trusted_clients)
|
cm.set_value("authorization", "trusted_clients", trusted_clients)
|
||||||
|
|
||||||
|
# add existing client and client configs in the update section
|
||||||
|
if clients is not None and len(clients) > 0:
|
||||||
|
for c in clients:
|
||||||
|
# client part
|
||||||
|
c_section = f"update_manager {c.get('name')}"
|
||||||
|
c_options = [
|
||||||
|
("type", "web"),
|
||||||
|
("channel", "stable"),
|
||||||
|
("repo", c.get("mr_conf_repo")),
|
||||||
|
("path", c.get("mr_conf_path")),
|
||||||
|
]
|
||||||
|
cm.config.add_section(section=c_section)
|
||||||
|
for option in c_options:
|
||||||
|
cm.config.set(c_section, option[0], option[1])
|
||||||
|
|
||||||
|
# client config part
|
||||||
|
c_config = c.get("client_config")
|
||||||
|
if c_config.get("dir").exists():
|
||||||
|
c_config_section = f"update_manager {c_config.get('name')}"
|
||||||
|
c_config_options = [
|
||||||
|
("type", "git_repo"),
|
||||||
|
("primary_branch", "master"),
|
||||||
|
("path", c_config.get("mr_conf_path")),
|
||||||
|
("origin", c_config.get("mr_conf_origin")),
|
||||||
|
("managed_services", "klipper"),
|
||||||
|
]
|
||||||
|
cm.config.add_section(section=c_config_section)
|
||||||
|
for option in c_config_options:
|
||||||
|
cm.config.set(c_config_section, option[0], option[1])
|
||||||
|
|
||||||
cm.write_config()
|
cm.write_config()
|
||||||
Logger.print_ok(f"Example moonraker.conf created in '{instance.cfg_dir}'")
|
Logger.print_ok(f"Example moonraker.conf created in '{instance.cfg_dir}'")
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List, get_args
|
from typing import List
|
||||||
|
|
||||||
from kiauh import KIAUH_CFG
|
from kiauh import KIAUH_CFG
|
||||||
from components.klipper.klipper import Klipper
|
from components.klipper.klipper import Klipper
|
||||||
@@ -21,8 +21,8 @@ from components.webui_client import ClientConfigData, ClientName, ClientData
|
|||||||
from components.webui_client.client_dialogs import print_client_already_installed_dialog
|
from components.webui_client.client_dialogs import print_client_already_installed_dialog
|
||||||
from components.webui_client.client_utils import (
|
from components.webui_client.client_utils import (
|
||||||
load_client_data,
|
load_client_data,
|
||||||
backup_client_config_data,
|
backup_client_config_data, config_for_other_client_exist,
|
||||||
)
|
)
|
||||||
from core.config_manager.config_manager import ConfigManager
|
from core.config_manager.config_manager import ConfigManager
|
||||||
|
|
||||||
from core.instance_manager.instance_manager import InstanceManager
|
from core.instance_manager.instance_manager import InstanceManager
|
||||||
@@ -40,7 +40,7 @@ def install_client_config(client_name: ClientName) -> None:
|
|||||||
client_config: ClientConfigData = client.get("client_config")
|
client_config: ClientConfigData = client.get("client_config")
|
||||||
d_name = client_config.get("display_name")
|
d_name = client_config.get("display_name")
|
||||||
|
|
||||||
if check_existing_client_config_install(client_name):
|
if config_for_other_client_exist(client_name):
|
||||||
Logger.print_info("Another Client-Config is already installed! Skipped ...")
|
Logger.print_info("Another Client-Config is already installed! Skipped ...")
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -80,21 +80,6 @@ def install_client_config(client_name: ClientName) -> None:
|
|||||||
Logger.print_ok(f"{d_name} installation complete!", start="\n")
|
Logger.print_ok(f"{d_name} installation complete!", start="\n")
|
||||||
|
|
||||||
|
|
||||||
def check_existing_client_config_install(client_name: ClientName) -> bool:
|
|
||||||
# check if any other client-configs are present
|
|
||||||
# as they can conflict each other, or are at least
|
|
||||||
# redundant to have, so we skip the installation
|
|
||||||
client_list = list(get_args(ClientName))
|
|
||||||
client_list.remove(client_name)
|
|
||||||
for c in client_list:
|
|
||||||
c_data: ClientData = load_client_data(c)
|
|
||||||
c_config_data: ClientConfigData = c_data.get("client_config")
|
|
||||||
if c_config_data.get("dir").exists():
|
|
||||||
return True
|
|
||||||
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def download_client_config(client_config: ClientConfigData) -> None:
|
def download_client_config(client_config: ClientConfigData) -> None:
|
||||||
try:
|
try:
|
||||||
Logger.print_status(f"Downloading {client_config.get('display_name')} ...")
|
Logger.print_status(f"Downloading {client_config.get('display_name')} ...")
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ from components.webui_client import (
|
|||||||
from components.moonraker.moonraker import Moonraker
|
from components.moonraker.moonraker import Moonraker
|
||||||
from components.webui_client.client_config.client_config_setup import (
|
from components.webui_client.client_config.client_config_setup import (
|
||||||
install_client_config,
|
install_client_config,
|
||||||
check_existing_client_config_install,
|
|
||||||
)
|
)
|
||||||
from components.webui_client.client_dialogs import (
|
from components.webui_client.client_dialogs import (
|
||||||
print_moonraker_not_found_dialog,
|
print_moonraker_not_found_dialog,
|
||||||
@@ -33,8 +32,8 @@ from components.webui_client.client_utils import (
|
|||||||
restore_mainsail_config_json,
|
restore_mainsail_config_json,
|
||||||
enable_mainsail_remotemode,
|
enable_mainsail_remotemode,
|
||||||
symlink_webui_nginx_log,
|
symlink_webui_nginx_log,
|
||||||
load_client_data,
|
load_client_data, config_for_other_client_exist,
|
||||||
)
|
)
|
||||||
from core.config_manager.config_manager import ConfigManager
|
from core.config_manager.config_manager import ConfigManager
|
||||||
from core.instance_manager.instance_manager import InstanceManager
|
from core.instance_manager.instance_manager import InstanceManager
|
||||||
from kiauh import KIAUH_CFG
|
from kiauh import KIAUH_CFG
|
||||||
@@ -100,7 +99,7 @@ def install_client(client_name: ClientName) -> None:
|
|||||||
if (
|
if (
|
||||||
kl_instances
|
kl_instances
|
||||||
and not client_config.get("dir").exists()
|
and not client_config.get("dir").exists()
|
||||||
and not check_existing_client_config_install(client.get("name"))
|
and not config_for_other_client_exist(client_to_ignore=client.get("name"))
|
||||||
):
|
):
|
||||||
print_install_client_config_dialog(client)
|
print_install_client_config_dialog(client)
|
||||||
question = f"Download the recommended {client_config.get('display_name')}?"
|
question = f"Download the recommended {client_config.get('display_name')}?"
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import json
|
|||||||
import shutil
|
import shutil
|
||||||
from json import JSONDecodeError
|
from json import JSONDecodeError
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List, Optional, Dict, Literal, Union
|
from typing import List, Optional, Dict, Literal, Union, get_args
|
||||||
|
|
||||||
import urllib.request
|
import urllib.request
|
||||||
|
|
||||||
@@ -43,7 +43,7 @@ from components.webui_client import (
|
|||||||
from core.backup_manager.backup_manager import BackupManager
|
from core.backup_manager.backup_manager import BackupManager
|
||||||
from core.repo_manager.repo_manager import RepoManager
|
from core.repo_manager.repo_manager import RepoManager
|
||||||
from utils import NGINX_SITES_AVAILABLE, NGINX_CONFD
|
from utils import NGINX_SITES_AVAILABLE, NGINX_CONFD
|
||||||
from utils.common import get_install_status_webui, get_install_status_common
|
from utils.common import get_install_status_webui
|
||||||
from utils.constants import COLOR_CYAN, RESET_FORMAT, COLOR_YELLOW
|
from utils.constants import COLOR_CYAN, RESET_FORMAT, COLOR_YELLOW
|
||||||
from utils.logger import Logger
|
from utils.logger import Logger
|
||||||
|
|
||||||
@@ -235,3 +235,41 @@ def backup_client_config_data(client: ClientData) -> None:
|
|||||||
target = client_config.get("backup_dir")
|
target = client_config.get("backup_dir")
|
||||||
bm = BackupManager()
|
bm = BackupManager()
|
||||||
bm.backup_directory(name, source, target)
|
bm.backup_directory(name, source, target)
|
||||||
|
|
||||||
|
|
||||||
|
def get_existing_clients() -> List[ClientData]:
|
||||||
|
clients = list(get_args(ClientName))
|
||||||
|
installed_clients: List[ClientData] = []
|
||||||
|
for c in clients:
|
||||||
|
c_data: ClientData = load_client_data(c)
|
||||||
|
if c_data.get("dir").exists():
|
||||||
|
installed_clients.append(c_data)
|
||||||
|
|
||||||
|
return installed_clients
|
||||||
|
|
||||||
|
|
||||||
|
def get_existing_client_config() -> List[ClientData]:
|
||||||
|
clients = list(get_args(ClientName))
|
||||||
|
installed_client_configs: List[ClientData] = []
|
||||||
|
for c in clients:
|
||||||
|
c_data: ClientData = load_client_data(c)
|
||||||
|
c_config_data: ClientConfigData = c_data.get("client_config")
|
||||||
|
if c_config_data.get("dir").exists():
|
||||||
|
installed_client_configs.append(c_data)
|
||||||
|
|
||||||
|
return installed_client_configs
|
||||||
|
|
||||||
|
|
||||||
|
def config_for_other_client_exist(client_to_ignore: ClientName) -> 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
|
||||||
|
: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}
|
||||||
|
|
||||||
|
return True if len(clients) > 0 else False
|
||||||
|
|||||||
Reference in New Issue
Block a user