Compare commits

...

5 Commits

Author SHA1 Message Date
dw-0
2acd74cbd9 refactor(webclients): make a backup before modification of config files
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-03-22 22:20:13 +01:00
dw-0
00665109c2 feat: allow sections to be added to the top of a config file
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-03-22 22:11:56 +01:00
dw-0
a5dce136f3 chore: remove shebang from most files because it is not needed
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-03-21 21:55:35 +01:00
dw-0
4ffa057931 chore: improve type hinting
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-03-21 21:50:10 +01:00
dw-0
ed35dc9e03 chore: add mypy config to pyproject.toml
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-03-21 20:38:14 +01:00
54 changed files with 58 additions and 132 deletions

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #
@@ -12,7 +10,6 @@
from pathlib import Path
from components.webui_client.client_utils import (
get_existing_client_config,
get_existing_clients,
)
from kiauh import KIAUH_CFG

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #
@@ -15,7 +13,6 @@ import re
import shutil
import subprocess
import textwrap
from pathlib import Path
from typing import List, Union, Literal, Dict, Optional
from components.klipper import (

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #
@@ -12,13 +10,11 @@
import subprocess
import sys
from pathlib import Path
from typing import List
from components.webui_client import MAINSAIL_DIR
from components.webui_client.client_utils import enable_mainsail_remotemode, get_existing_clients
from kiauh import KIAUH_CFG
from components.klipper.klipper import Klipper
from components.klipper.klipper_dialogs import print_instance_overview
from components.moonraker import (
EXIT_MOONRAKER_SETUP,
DEFAULT_MOONRAKER_REPO_URL,

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #
@@ -21,15 +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.common import backup_printer_config_dir
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
@@ -59,6 +59,9 @@ def install_client_config(client_name: ClientName) -> None:
try:
download_client_config(client_config)
create_client_config_symlink(client_config, kl_instances)
backup_printer_config_dir()
add_config_section(
section=f"update_manager {client_config.get('name')}",
instances=mr_instances,
@@ -70,7 +73,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,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #
@@ -32,7 +30,8 @@ from components.webui_client.client_utils import (
restore_mainsail_config_json,
enable_mainsail_remotemode,
symlink_webui_nginx_log,
load_client_data, config_for_other_client_exist,
load_client_data,
config_for_other_client_exist,
)
from core.config_manager.config_manager import ConfigManager
from core.instance_manager.instance_manager import InstanceManager

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #
@@ -9,14 +7,13 @@
# This file may be distributed under the terms of the GNU GPLv3 license #
# ======================================================================= #
from __future__ import annotations
from abc import abstractmethod, ABC
from pathlib import Path
from typing import List, Type, TypeVar
from typing import List, Optional
from utils.constants import SYSTEMD, CURRENT_USER
B = TypeVar(name="B", bound="BaseInstance", covariant=True)
class BaseInstance(ABC):
@classmethod
@@ -26,7 +23,7 @@ class BaseInstance(ABC):
def __init__(
self,
suffix: str,
instance_type: B = B,
instance_type: BaseInstance,
):
self._instance_type = instance_type
self._suffix = suffix
@@ -40,11 +37,11 @@ class BaseInstance(ABC):
self._gcodes_dir = self.data_dir.joinpath("gcodes")
@property
def instance_type(self) -> Type["BaseInstance"]:
def instance_type(self) -> BaseInstance:
return self._instance_type
@instance_type.setter
def instance_type(self, value: Type["BaseInstance"]) -> None:
def instance_type(self, value: BaseInstance) -> None:
self._instance_type = value
@property
@@ -76,7 +73,7 @@ class BaseInstance(ABC):
return self._data_dir
@data_dir.setter
def data_dir(self, value: str) -> None:
def data_dir(self, value: Path) -> None:
self._data_dir = value
@property
@@ -84,7 +81,7 @@ class BaseInstance(ABC):
return self._cfg_dir
@cfg_dir.setter
def cfg_dir(self, value: str) -> None:
def cfg_dir(self, value: Path) -> None:
self._cfg_dir = value
@property
@@ -92,7 +89,7 @@ class BaseInstance(ABC):
return self._log_dir
@log_dir.setter
def log_dir(self, value: str) -> None:
def log_dir(self, value: Path) -> None:
self._log_dir = value
@property
@@ -100,7 +97,7 @@ class BaseInstance(ABC):
return self._comms_dir
@comms_dir.setter
def comms_dir(self, value: str) -> None:
def comms_dir(self, value: Path) -> None:
self._comms_dir = value
@property
@@ -108,7 +105,7 @@ class BaseInstance(ABC):
return self._sysd_dir
@sysd_dir.setter
def sysd_dir(self, value: str) -> None:
def sysd_dir(self, value: Path) -> None:
self._sysd_dir = value
@property
@@ -116,7 +113,7 @@ class BaseInstance(ABC):
return self._gcodes_dir
@gcodes_dir.setter
def gcodes_dir(self, value: str) -> None:
def gcodes_dir(self, value: Path) -> None:
self._gcodes_dir = value
@abstractmethod
@@ -127,7 +124,7 @@ class BaseInstance(ABC):
def delete(self) -> None:
raise NotImplementedError("Subclasses must implement the delete method")
def create_folders(self, add_dirs: List[Path] = None) -> None:
def create_folders(self, add_dirs: Optional[List[Path]] = None) -> None:
dirs = [
self.data_dir,
self.cfg_dir,

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #

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:

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #

View File

@@ -11,3 +11,5 @@ exclude = '''
| scripts/
)
'''
[tool.mypy]
mypy_path = "./kiauh"