mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-25 08:43:36 +05:00
refactor: use global deps list to check for generally required dependencies
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
@@ -70,8 +70,7 @@ def install_mobileraker() -> None:
|
|||||||
):
|
):
|
||||||
return
|
return
|
||||||
|
|
||||||
package_list = ["git", "wget", "curl", "unzip", "dfu-util"]
|
check_install_dependencies()
|
||||||
check_install_dependencies(package_list)
|
|
||||||
|
|
||||||
git_clone_wrapper(MOBILERAKER_REPO, MOBILERAKER_DIR)
|
git_clone_wrapper(MOBILERAKER_REPO, MOBILERAKER_DIR)
|
||||||
|
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ def install_moonraker() -> None:
|
|||||||
create_example_cfg = get_confirm("Create example moonraker.conf?")
|
create_example_cfg = get_confirm("Create example moonraker.conf?")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
check_install_dependencies(["git"])
|
check_install_dependencies()
|
||||||
setup_moonraker_prerequesites()
|
setup_moonraker_prerequesites()
|
||||||
install_moonraker_polkit()
|
install_moonraker_polkit()
|
||||||
|
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ def install_client(client: BaseWebClient) -> None:
|
|||||||
)
|
)
|
||||||
valid_port = is_valid_port(port, ports_in_use)
|
valid_port = is_valid_port(port, ports_in_use)
|
||||||
|
|
||||||
check_install_dependencies(["nginx", "unzip"])
|
check_install_dependencies(["nginx"])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
download_client(client)
|
download_client(client)
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ MODULE_PATH = Path(__file__).resolve().parent
|
|||||||
INVALID_CHOICE = "Invalid choice. Please select a valid value."
|
INVALID_CHOICE = "Invalid choice. Please select a valid value."
|
||||||
PRINTER_CFG_BACKUP_DIR = BACKUP_ROOT_DIR.joinpath("printer-cfg-backups")
|
PRINTER_CFG_BACKUP_DIR = BACKUP_ROOT_DIR.joinpath("printer-cfg-backups")
|
||||||
|
|
||||||
|
GLOBAL_DEPS = ["git", "wget", "curl", "unzip", "dfu-util", "python3-virtualenv"]
|
||||||
|
|
||||||
# ================== NGINX =====================#
|
# ================== NGINX =====================#
|
||||||
NGINX_SITES_AVAILABLE = Path("/etc/nginx/sites-available")
|
NGINX_SITES_AVAILABLE = Path("/etc/nginx/sites-available")
|
||||||
NGINX_SITES_ENABLED = Path("/etc/nginx/sites-enabled")
|
NGINX_SITES_ENABLED = Path("/etc/nginx/sites-enabled")
|
||||||
|
|||||||
@@ -6,6 +6,8 @@
|
|||||||
# #
|
# #
|
||||||
# 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 #
|
||||||
# ======================================================================= #
|
# ======================================================================= #
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import re
|
import re
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@@ -14,7 +16,7 @@ from typing import Dict, List, Literal, Optional, Type
|
|||||||
from components.klipper.klipper import Klipper
|
from components.klipper.klipper import Klipper
|
||||||
from core.instance_manager.base_instance import BaseInstance
|
from core.instance_manager.base_instance import BaseInstance
|
||||||
from core.instance_manager.instance_manager import InstanceManager
|
from core.instance_manager.instance_manager import InstanceManager
|
||||||
from utils import PRINTER_CFG_BACKUP_DIR
|
from utils import GLOBAL_DEPS, PRINTER_CFG_BACKUP_DIR
|
||||||
from utils.constants import (
|
from utils.constants import (
|
||||||
COLOR_CYAN,
|
COLOR_CYAN,
|
||||||
RESET_FORMAT,
|
RESET_FORMAT,
|
||||||
@@ -45,19 +47,22 @@ def get_current_date() -> Dict[Literal["date", "time"], str]:
|
|||||||
return {"date": date, "time": time}
|
return {"date": date, "time": time}
|
||||||
|
|
||||||
|
|
||||||
def check_install_dependencies(deps: List[str]) -> None:
|
def check_install_dependencies(deps: List[str] | None = None) -> None:
|
||||||
"""
|
"""
|
||||||
Common helper method to check if dependencies are installed
|
Common helper method to check if dependencies are installed
|
||||||
and if not, install them automatically |
|
and if not, install them automatically |
|
||||||
:param deps: List of strings of package names to check if installed
|
:param deps: List of strings of package names to check if installed
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
requirements = check_package_install(deps)
|
if deps is None:
|
||||||
|
deps = []
|
||||||
|
|
||||||
|
requirements = check_package_install({*GLOBAL_DEPS, *deps})
|
||||||
if requirements:
|
if requirements:
|
||||||
Logger.print_status("Installing dependencies ...")
|
Logger.print_status("Installing dependencies ...")
|
||||||
Logger.print_info("The following packages need installation:")
|
Logger.print_info("The following packages need installation:")
|
||||||
for _ in requirements:
|
for r in requirements:
|
||||||
print(f"{COLOR_CYAN}● {_}{RESET_FORMAT}")
|
print(f"{COLOR_CYAN}● {r}{RESET_FORMAT}")
|
||||||
update_system_package_lists(silent=False)
|
update_system_package_lists(silent=False)
|
||||||
install_system_packages(requirements)
|
install_system_packages(requirements)
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import urllib.error
|
|||||||
import urllib.request
|
import urllib.request
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from subprocess import DEVNULL, PIPE, CalledProcessError, Popen, run
|
from subprocess import DEVNULL, PIPE, CalledProcessError, Popen, run
|
||||||
from typing import List, Literal
|
from typing import List, Literal, Set
|
||||||
|
|
||||||
from utils.constants import SYSTEMD
|
from utils.constants import SYSTEMD
|
||||||
from utils.fs_utils import check_file_exist, remove_with_sudo
|
from utils.fs_utils import check_file_exist, remove_with_sudo
|
||||||
@@ -217,7 +217,7 @@ def update_system_package_lists(silent: bool, rls_info_change=False) -> None:
|
|||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
def check_package_install(packages: List[str]) -> List[str]:
|
def check_package_install(packages: Set[str]) -> List[str]:
|
||||||
"""
|
"""
|
||||||
Checks the system for installed packages |
|
Checks the system for installed packages |
|
||||||
:param packages: List of strings of package names
|
:param packages: List of strings of package names
|
||||||
|
|||||||
Reference in New Issue
Block a user