mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-25 00:33:37 +05:00
refactor: improve config creations and patching
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
@@ -24,6 +24,13 @@ OBICO_DIR = Path.home().joinpath("moonraker-obico")
|
|||||||
OBICO_ENV = Path.home().joinpath("moonraker-obico-env")
|
OBICO_ENV = Path.home().joinpath("moonraker-obico-env")
|
||||||
OBICO_REPO = "https://github.com/TheSpaghettiDetective/moonraker-obico.git"
|
OBICO_REPO = "https://github.com/TheSpaghettiDetective/moonraker-obico.git"
|
||||||
|
|
||||||
|
OBICO_CFG = "moonraker-obico.cfg"
|
||||||
|
OBICO_CFG_SAMPLE = "moonraker-obico.cfg.sample"
|
||||||
|
OBICO_LOG = "moonraker-obico.log"
|
||||||
|
OBICO_UPDATE_CFG = "moonraker-obico-update.cfg"
|
||||||
|
OBICO_UPDATE_CFG_SAMPLE = "moonraker-obico-update.cfg.sample"
|
||||||
|
OBICO_MACROS_CFG = "moonraker_obico_macros.cfg"
|
||||||
|
|
||||||
|
|
||||||
# noinspection PyMethodMayBeStatic
|
# noinspection PyMethodMayBeStatic
|
||||||
class MoonrakerObico(BaseInstance):
|
class MoonrakerObico(BaseInstance):
|
||||||
|
|||||||
@@ -7,7 +7,6 @@
|
|||||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||||
# ======================================================================= #
|
# ======================================================================= #
|
||||||
import shutil
|
import shutil
|
||||||
from subprocess import run
|
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from components.klipper.klipper import Klipper
|
from components.klipper.klipper import Klipper
|
||||||
@@ -18,13 +17,21 @@ from core.submodules.simple_config_parser.src.simple_config_parser.simple_config
|
|||||||
)
|
)
|
||||||
from extensions.base_extension import BaseExtension
|
from extensions.base_extension import BaseExtension
|
||||||
from extensions.obico.moonraker_obico import (
|
from extensions.obico.moonraker_obico import (
|
||||||
|
OBICO_CFG_SAMPLE,
|
||||||
OBICO_DIR,
|
OBICO_DIR,
|
||||||
OBICO_ENV,
|
OBICO_ENV,
|
||||||
|
OBICO_LOG,
|
||||||
|
OBICO_MACROS_CFG,
|
||||||
OBICO_REPO,
|
OBICO_REPO,
|
||||||
|
OBICO_UPDATE_CFG,
|
||||||
|
OBICO_UPDATE_CFG_SAMPLE,
|
||||||
MoonrakerObico,
|
MoonrakerObico,
|
||||||
)
|
)
|
||||||
from utils.common import check_install_dependencies, moonraker_exists
|
from utils.common import check_install_dependencies, moonraker_exists
|
||||||
from utils.config_utils import add_config_section, remove_config_section
|
from utils.config_utils import (
|
||||||
|
add_config_section,
|
||||||
|
remove_config_section,
|
||||||
|
)
|
||||||
from utils.fs_utils import remove_file
|
from utils.fs_utils import remove_file
|
||||||
from utils.git_utils import git_clone_wrapper, git_pull_wrapper
|
from utils.git_utils import git_clone_wrapper, git_pull_wrapper
|
||||||
from utils.input_utils import get_confirm, get_selection_input, get_string_input
|
from utils.input_utils import get_confirm, get_selection_input, get_string_input
|
||||||
@@ -102,16 +109,19 @@ class ObicoExtension(BaseExtension):
|
|||||||
# create obico macros
|
# create obico macros
|
||||||
self._create_obico_macros_cfg(moonraker)
|
self._create_obico_macros_cfg(moonraker)
|
||||||
|
|
||||||
|
# create obico update manager
|
||||||
|
self._create_obico_update_manager_cfg(moonraker)
|
||||||
|
|
||||||
obico_im.start_instance()
|
obico_im.start_instance()
|
||||||
|
|
||||||
cmd_sysctl_manage("daemon-reload")
|
cmd_sysctl_manage("daemon-reload")
|
||||||
|
|
||||||
# add to klippers config
|
# add to klippers config
|
||||||
self._patch_obico_macros(kl_instances)
|
self._patch_printer_cfg(kl_instances)
|
||||||
kl_im.restart_all_instance()
|
kl_im.restart_all_instance()
|
||||||
|
|
||||||
# add to moonraker update manager
|
# add to moonraker update manager
|
||||||
self._patch_update_manager(mr_instances)
|
self._patch_moonraker_conf(mr_instances)
|
||||||
mr_im.restart_all_instance()
|
mr_im.restart_all_instance()
|
||||||
|
|
||||||
# check linking of / ask for linking instances
|
# check linking of / ask for linking instances
|
||||||
@@ -154,9 +164,8 @@ class ObicoExtension(BaseExtension):
|
|||||||
self._remove_obico_instances(ob_im, ob_instances)
|
self._remove_obico_instances(ob_im, ob_instances)
|
||||||
self._remove_obico_dir()
|
self._remove_obico_dir()
|
||||||
self._remove_obico_env()
|
self._remove_obico_env()
|
||||||
remove_config_section("include moonraker_obico_macros.cfg", kl_instances)
|
remove_config_section(f"include {OBICO_MACROS_CFG}", kl_instances)
|
||||||
remove_config_section("update_manager moonraker-obico", mr_instances)
|
remove_config_section(f"include {OBICO_UPDATE_CFG}", mr_instances)
|
||||||
remove_config_section("include moonraker-obico-update.cfg", mr_instances)
|
|
||||||
self._delete_obico_logs(ob_instances)
|
self._delete_obico_logs(ob_instances)
|
||||||
Logger.print_dialog(
|
Logger.print_dialog(
|
||||||
DialogType.SUCCESS,
|
DialogType.SUCCESS,
|
||||||
@@ -236,19 +245,29 @@ class ObicoExtension(BaseExtension):
|
|||||||
install_python_requirements(OBICO_ENV, requirements)
|
install_python_requirements(OBICO_ENV, requirements)
|
||||||
|
|
||||||
def _create_obico_macros_cfg(self, moonraker) -> None:
|
def _create_obico_macros_cfg(self, moonraker) -> None:
|
||||||
macros_cfg = OBICO_DIR.joinpath("include_cfgs/moonraker_obico_macros.cfg")
|
macros_cfg = OBICO_DIR.joinpath(f"include_cfgs/{OBICO_MACROS_CFG}")
|
||||||
macros_target = moonraker.cfg_dir.joinpath("moonraker_obico_macros.cfg")
|
macros_target = moonraker.cfg_dir.joinpath(OBICO_MACROS_CFG)
|
||||||
if not macros_target.exists():
|
if not macros_target.exists():
|
||||||
run(["cp", macros_cfg, macros_target], check=True)
|
shutil.copy(macros_cfg, macros_target)
|
||||||
else:
|
else:
|
||||||
Logger.print_info(
|
Logger.print_info(
|
||||||
f"Obico macros in {moonraker.cfg_dir} already exists! Skipped ..."
|
f"Obico's '{OBICO_MACROS_CFG}' in {moonraker.cfg_dir} already exists! Skipped ..."
|
||||||
|
)
|
||||||
|
|
||||||
|
def _create_obico_update_manager_cfg(self, moonraker) -> None:
|
||||||
|
update_cfg = OBICO_DIR.joinpath(OBICO_UPDATE_CFG_SAMPLE)
|
||||||
|
update_cfg_target = moonraker.cfg_dir.joinpath(OBICO_UPDATE_CFG)
|
||||||
|
if not update_cfg_target.exists():
|
||||||
|
shutil.copy(update_cfg, update_cfg_target)
|
||||||
|
else:
|
||||||
|
Logger.print_info(
|
||||||
|
f"Obico's '{OBICO_UPDATE_CFG}' in {moonraker.cfg_dir} already exists! Skipped ..."
|
||||||
)
|
)
|
||||||
|
|
||||||
def _create_obico_cfg(
|
def _create_obico_cfg(
|
||||||
self, current_instance: MoonrakerObico, moonraker: Moonraker
|
self, current_instance: MoonrakerObico, moonraker: Moonraker
|
||||||
) -> None:
|
) -> None:
|
||||||
cfg_template = OBICO_DIR.joinpath("moonraker-obico.cfg.sample")
|
cfg_template = OBICO_DIR.joinpath(OBICO_CFG_SAMPLE)
|
||||||
cfg_target_file = current_instance.cfg_file
|
cfg_target_file = current_instance.cfg_file
|
||||||
|
|
||||||
if not cfg_template.exists():
|
if not cfg_template.exists():
|
||||||
@@ -258,7 +277,7 @@ class ObicoExtension(BaseExtension):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if not cfg_target_file.exists():
|
if not cfg_target_file.exists():
|
||||||
run(["cp", cfg_template, cfg_target_file], check=True)
|
shutil.copy(cfg_template, cfg_target_file)
|
||||||
self._patch_obico_cfg(moonraker, current_instance)
|
self._patch_obico_cfg(moonraker, current_instance)
|
||||||
else:
|
else:
|
||||||
Logger.print_info(
|
Logger.print_info(
|
||||||
@@ -273,27 +292,11 @@ class ObicoExtension(BaseExtension):
|
|||||||
scp.set("logging", "path", str(obico.log))
|
scp.set("logging", "path", str(obico.log))
|
||||||
scp.write(obico.cfg_file)
|
scp.write(obico.cfg_file)
|
||||||
|
|
||||||
def _patch_obico_macros(self, klipper: List[Klipper]) -> None:
|
def _patch_printer_cfg(self, klipper: List[Klipper]) -> None:
|
||||||
add_config_section(
|
add_config_section(section=f"include {OBICO_MACROS_CFG}", instances=klipper)
|
||||||
section="include moonraker_obico_macros.cfg",
|
|
||||||
instances=klipper,
|
|
||||||
)
|
|
||||||
|
|
||||||
def _patch_update_manager(self, instances: List[Moonraker]) -> None:
|
def _patch_moonraker_conf(self, instances: List[Moonraker]) -> None:
|
||||||
env_py = f"{OBICO_ENV}/bin/python"
|
add_config_section(section=f"include {OBICO_UPDATE_CFG}", instances=instances)
|
||||||
add_config_section(
|
|
||||||
section="update_manager moonraker-obico",
|
|
||||||
instances=instances,
|
|
||||||
options=[
|
|
||||||
("type", "git_repo"),
|
|
||||||
("path", str(OBICO_DIR)),
|
|
||||||
("orgin", OBICO_REPO),
|
|
||||||
("env", env_py),
|
|
||||||
("requirements", "requirements.txt"),
|
|
||||||
("install_script", "install.sh"),
|
|
||||||
("managed_services", "moonraker-obico"),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
|
|
||||||
def _link_obico_instances(self, unlinked_instances):
|
def _link_obico_instances(self, unlinked_instances):
|
||||||
for obico in unlinked_instances:
|
for obico in unlinked_instances:
|
||||||
@@ -373,7 +376,7 @@ class ObicoExtension(BaseExtension):
|
|||||||
Logger.print_status("Removing Obico logs ...")
|
Logger.print_status("Removing Obico logs ...")
|
||||||
all_logfiles = []
|
all_logfiles = []
|
||||||
for instance in instances:
|
for instance in instances:
|
||||||
all_logfiles = list(instance.log_dir.glob("moonraker-obico.log*"))
|
all_logfiles = list(instance.log_dir.glob(f"{OBICO_LOG}*"))
|
||||||
if not all_logfiles:
|
if not all_logfiles:
|
||||||
Logger.print_info("No Obico logs found. Skipped ...")
|
Logger.print_info("No Obico logs found. Skipped ...")
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user