feat: KIAUH v6 - full rewrite of KIAUH in Python #428

Open
dw-0 wants to merge 242 commits from kiauh-v6-dev into master
2 changed files with 37 additions and 11 deletions
Showing only changes of commit 00665109c2 - Show all commits

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #
@@ -21,16 +19,17 @@ 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_utils import (
load_client_data,
backup_client_config_data, config_for_other_client_exist,
)
backup_client_config_data,
config_for_other_client_exist,
)
from core.config_manager.config_manager import ConfigManager
from core.instance_manager.instance_manager import InstanceManager
from core.repo_manager.repo_manager import RepoManager
from utils.filesystem_utils import (
create_symlink,
add_config_section,
)
add_config_section, add_config_section_at_top,
)
from utils.input_utils import get_confirm
from utils.logger import Logger
@@ -70,7 +69,9 @@ def install_client_config(client_name: ClientName) -> None:
("managed_services", "klipper"),
],
)
add_config_section(client_config.get("printer_cfg_section"), kl_instances)
add_config_section_at_top(
client_config.get("printer_cfg_section"), kl_instances
)
kl_im.restart_all_instance()
except Exception as e:

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env python3
import os
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
@@ -12,15 +13,15 @@
import re
import shutil
import subprocess
import tempfile
from pathlib import Path
from zipfile import ZipFile
from typing import List, Type, TypeVar, Union, Tuple
from typing import List, TypeVar, Tuple, Optional
from components.klipper.klipper import Klipper
from components.moonraker.moonraker import Moonraker
from core.config_manager.config_manager import ConfigManager
from core.instance_manager.base_instance import BaseInstance
from core.instance_manager.instance_manager import InstanceManager
from utils import (
NGINX_SITES_AVAILABLE,
@@ -31,7 +32,7 @@ from utils import (
from utils.logger import Logger
B = TypeVar('B', bound='BaseInstance')
B = TypeVar("B", Klipper, Moonraker)
ConfigOption = Tuple[str, str]
@@ -182,7 +183,11 @@ def get_next_free_port(ports_in_use: List[str]) -> str:
return str(min(valid_ports - used_ports))
def add_config_section(section: str, instances: List[B], options: List[ConfigOption] = None) -> None:
def add_config_section(
section: str,
instances: List[B],
options: Optional[List[ConfigOption]] = None,
) -> None:
for instance in instances:
cfg_file = instance.cfg_file
Logger.print_status(f"Add section '[{section}]' to '{cfg_file}' ...")
@@ -204,6 +209,26 @@ def add_config_section(section: str, instances: List[B], options: List[ConfigOpt
cm.write_config()
def add_config_section_at_top(
section: str,
instances: List[B]):
for instance in instances:
tmp_cfg = tempfile.NamedTemporaryFile(mode="w" ,delete=False)
tmp_cfg_path = Path(tmp_cfg.name)
cmt = ConfigManager(tmp_cfg_path)
cmt.config.add_section(section)
cmt.write_config()
tmp_cfg.close()
cfg_file = instance.cfg_file
with open(cfg_file, "r") as org:
org_content = org.readlines()
with open(tmp_cfg_path, "a") as tmp:
tmp.writelines(org_content)
cfg_file.unlink()
tmp_cfg_path.rename(cfg_file)
def remove_config_section(section: str, instances: List[B]) -> None:
for instance in instances: