From 9864dd0c7f7c900740c0ce22457a261f50807b51 Mon Sep 17 00:00:00 2001 From: dw-0 Date: Thu, 2 May 2024 23:26:47 +0200 Subject: [PATCH] refactor: use check_install_dependencies at more places where appropriate Signed-off-by: Dominik Willner --- kiauh/components/crowsnest/crowsnest.py | 13 +++---------- kiauh/components/klipper/klipper_setup.py | 6 ++---- kiauh/components/klipperscreen/klipperscreen.py | 8 ++------ kiauh/components/moonraker/moonraker_setup.py | 6 ++---- kiauh/utils/common.py | 7 ++++++- 5 files changed, 15 insertions(+), 25 deletions(-) diff --git a/kiauh/components/crowsnest/crowsnest.py b/kiauh/components/crowsnest/crowsnest.py index e2f022b..a57f3f9 100644 --- a/kiauh/components/crowsnest/crowsnest.py +++ b/kiauh/components/crowsnest/crowsnest.py @@ -17,7 +17,7 @@ from typing import List, Dict, Literal, Union from components.crowsnest import CROWSNEST_REPO, CROWSNEST_DIR from components.klipper.klipper import Klipper from core.instance_manager.instance_manager import InstanceManager -from utils.common import get_install_status +from utils.common import get_install_status, check_install_dependencies from utils.constants import COLOR_CYAN, RESET_FORMAT, CURRENT_USER from utils.git_utils import ( git_clone_wrapper, @@ -29,10 +29,7 @@ from utils.git_utils import ( from utils.input_utils import get_confirm from utils.logger import Logger from utils.sys_utils import ( - check_package_install, - install_system_packages, parse_packages_from_file, - update_system_package_lists, control_systemd_service, ) @@ -42,9 +39,7 @@ def install_crowsnest() -> None: git_clone_wrapper(CROWSNEST_REPO, CROWSNEST_DIR, "master") # Step 2: Install dependencies - requirements: List[str] = check_package_install(["make"]) - if requirements: - install_system_packages(requirements) + check_install_dependencies(["make"]) # Step 3: Check for Multi Instance im = InstanceManager(Klipper) @@ -114,9 +109,7 @@ def update_crowsnest() -> None: script = CROWSNEST_DIR.joinpath("tools/install.sh") deps = parse_packages_from_file(script) - packages = check_package_install(deps) - update_system_package_lists(silent=False) - install_system_packages(packages) + check_install_dependencies(deps) control_systemd_service("crowsnest", "restart") diff --git a/kiauh/components/klipper/klipper_setup.py b/kiauh/components/klipper/klipper_setup.py index d873762..eb280e4 100644 --- a/kiauh/components/klipper/klipper_setup.py +++ b/kiauh/components/klipper/klipper_setup.py @@ -36,6 +36,7 @@ from components.klipper.klipper_utils import ( ) from components.moonraker.moonraker import Moonraker from core.instance_manager.instance_manager import InstanceManager +from utils.common import check_install_dependencies from utils.git_utils import git_clone_wrapper, git_pull_wrapper from utils.input_utils import get_confirm from utils.logger import Logger @@ -43,8 +44,6 @@ from utils.sys_utils import ( parse_packages_from_file, create_python_venv, install_python_requirements, - update_system_package_lists, - install_system_packages, ) @@ -134,8 +133,7 @@ def install_klipper_packages(klipper_dir: Path) -> None: if Path("/boot/dietpi/.version").exists(): packages.append("dbus") - update_system_package_lists(silent=False) - install_system_packages(packages) + check_install_dependencies(packages) def update_klipper() -> None: diff --git a/kiauh/components/klipperscreen/klipperscreen.py b/kiauh/components/klipperscreen/klipperscreen.py index 5e3b44b..bc5ab1f 100644 --- a/kiauh/components/klipperscreen/klipperscreen.py +++ b/kiauh/components/klipperscreen/klipperscreen.py @@ -22,7 +22,7 @@ from components.moonraker.moonraker import Moonraker from core.backup_manager.backup_manager import BackupManager from core.instance_manager.instance_manager import InstanceManager from core.settings.kiauh_settings import KiauhSettings -from utils.common import get_install_status +from utils.common import get_install_status, check_install_dependencies from utils.config_utils import add_config_section, remove_config_section from utils.constants import SYSTEMD from utils.fs_utils import remove_with_sudo @@ -37,8 +37,6 @@ from utils.input_utils import get_confirm from utils.logger import Logger from utils.sys_utils import ( check_python_version, - check_package_install, - install_system_packages, control_systemd_service, install_python_requirements, ) @@ -62,9 +60,7 @@ def install_klipperscreen() -> None: return package_list = ["wget", "curl", "unzip", "dfu-util"] - packages = check_package_install(package_list) - if packages: - install_system_packages(packages) + check_install_dependencies(package_list) git_clone_wrapper(KLIPPERSCREEN_REPO, KLIPPERSCREEN_DIR) diff --git a/kiauh/components/moonraker/moonraker_setup.py b/kiauh/components/moonraker/moonraker_setup.py index 2fd8452..1bc0092 100644 --- a/kiauh/components/moonraker/moonraker_setup.py +++ b/kiauh/components/moonraker/moonraker_setup.py @@ -34,6 +34,7 @@ from components.moonraker.moonraker_utils import ( backup_moonraker_dir, ) from core.instance_manager.instance_manager import InstanceManager +from utils.common import check_install_dependencies from utils.fs_utils import check_file_exist from utils.git_utils import git_clone_wrapper, git_pull_wrapper from utils.input_utils import ( @@ -45,8 +46,6 @@ from utils.sys_utils import ( parse_packages_from_file, create_python_venv, install_python_requirements, - update_system_package_lists, - install_system_packages, check_python_version, ) @@ -143,8 +142,7 @@ def setup_moonraker_prerequesites() -> None: def install_moonraker_packages(moonraker_dir: Path) -> None: script = moonraker_dir.joinpath("scripts/install-moonraker.sh") packages = parse_packages_from_file(script) - update_system_package_lists(silent=False) - install_system_packages(packages) + check_install_dependencies(packages) def install_moonraker_polkit() -> None: diff --git a/kiauh/utils/common.py b/kiauh/utils/common.py index 8b26f61..aae434e 100644 --- a/kiauh/utils/common.py +++ b/kiauh/utils/common.py @@ -23,7 +23,11 @@ from utils.constants import ( COLOR_RED, ) from utils.logger import Logger -from utils.sys_utils import check_package_install, install_system_packages +from utils.sys_utils import ( + check_package_install, + install_system_packages, + update_system_package_lists, +) def get_current_date() -> Dict[Literal["date", "time"], str]: @@ -51,6 +55,7 @@ def check_install_dependencies(deps: List[str]) -> None: Logger.print_info("The following packages need installation:") for _ in requirements: print(f"{COLOR_CYAN}● {_}{RESET_FORMAT}") + update_system_package_lists(silent=False) install_system_packages(requirements)