mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-11 17:44:28 +05:00
fix(moonraker): correctly install ubuntu 24.10 dependencies (#630)
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
@@ -8,7 +8,6 @@
|
|||||||
# ======================================================================= #
|
# ======================================================================= #
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import json
|
|
||||||
import subprocess
|
import subprocess
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
@@ -31,6 +30,7 @@ from components.moonraker.moonraker_dialogs import print_moonraker_overview
|
|||||||
from components.moonraker.moonraker_utils import (
|
from components.moonraker.moonraker_utils import (
|
||||||
backup_moonraker_dir,
|
backup_moonraker_dir,
|
||||||
create_example_moonraker_conf,
|
create_example_moonraker_conf,
|
||||||
|
parse_sysdeps_file,
|
||||||
)
|
)
|
||||||
from components.webui_client.client_utils import (
|
from components.webui_client.client_utils import (
|
||||||
enable_mainsail_remotemode,
|
enable_mainsail_remotemode,
|
||||||
@@ -53,6 +53,8 @@ from utils.sys_utils import (
|
|||||||
cmd_sysctl_manage,
|
cmd_sysctl_manage,
|
||||||
cmd_sysctl_service,
|
cmd_sysctl_service,
|
||||||
create_python_venv,
|
create_python_venv,
|
||||||
|
get_distro_name,
|
||||||
|
get_distro_version,
|
||||||
install_python_requirements,
|
install_python_requirements,
|
||||||
parse_packages_from_file,
|
parse_packages_from_file,
|
||||||
)
|
)
|
||||||
@@ -157,9 +159,35 @@ def install_moonraker_packages() -> None:
|
|||||||
moonraker_deps = []
|
moonraker_deps = []
|
||||||
|
|
||||||
if MOONRAKER_DEPS_JSON_FILE.exists():
|
if MOONRAKER_DEPS_JSON_FILE.exists():
|
||||||
with open(MOONRAKER_DEPS_JSON_FILE, "r") as deps:
|
Logger.print_status(
|
||||||
moonraker_deps = json.load(deps).get("debian", [])
|
f"Parsing system dependencies from {MOONRAKER_DEPS_JSON_FILE.name} ..."
|
||||||
|
)
|
||||||
|
parsed_sysdeps = parse_sysdeps_file(MOONRAKER_DEPS_JSON_FILE)
|
||||||
|
distro_name = get_distro_name().lower()
|
||||||
|
distro_version = get_distro_version()
|
||||||
|
|
||||||
|
for dep in parsed_sysdeps.get(distro_name, []):
|
||||||
|
pkg = dep[0].strip()
|
||||||
|
comparator = dep[1].strip()
|
||||||
|
req_version = dep[2].strip()
|
||||||
|
|
||||||
|
comparisons = {
|
||||||
|
"": lambda x, y: True,
|
||||||
|
"<": lambda x, y: x < y,
|
||||||
|
">": lambda x, y: x > y,
|
||||||
|
"<=": lambda x, y: x <= y,
|
||||||
|
">=": lambda x, y: x >= y,
|
||||||
|
"==": lambda x, y: x == y,
|
||||||
|
"!=": lambda x, y: x != y,
|
||||||
|
}
|
||||||
|
|
||||||
|
if comparisons[comparator](float(distro_version), float(req_version or 0)):
|
||||||
|
moonraker_deps.append(pkg)
|
||||||
|
|
||||||
elif MOONRAKER_INSTALL_SCRIPT.exists():
|
elif MOONRAKER_INSTALL_SCRIPT.exists():
|
||||||
|
Logger.print_status(
|
||||||
|
f"Parsing system dependencies from {MOONRAKER_INSTALL_SCRIPT.name} ..."
|
||||||
|
)
|
||||||
moonraker_deps = parse_packages_from_file(MOONRAKER_INSTALL_SCRIPT)
|
moonraker_deps = parse_packages_from_file(MOONRAKER_INSTALL_SCRIPT)
|
||||||
|
|
||||||
if not moonraker_deps:
|
if not moonraker_deps:
|
||||||
|
|||||||
@@ -6,9 +6,11 @@
|
|||||||
# #
|
# #
|
||||||
# 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 json
|
||||||
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
from typing import Dict, List, Optional
|
from pathlib import Path
|
||||||
|
from typing import Dict, List, Optional, Tuple
|
||||||
|
|
||||||
from components.moonraker import (
|
from components.moonraker import (
|
||||||
MODULE_PATH,
|
MODULE_PATH,
|
||||||
@@ -138,3 +140,34 @@ def backup_moonraker_db_dir() -> None:
|
|||||||
bm.backup_directory(
|
bm.backup_directory(
|
||||||
name, source=instance.db_dir, target=MOONRAKER_DB_BACKUP_DIR
|
name, source=instance.db_dir, target=MOONRAKER_DB_BACKUP_DIR
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# This function is from sync_dependencies.py script from the Moonraker project on GitHub:
|
||||||
|
# https://github.com/Arksine/moonraker/blob/master/scripts/sync_dependencies.py
|
||||||
|
# Thanks to Arksine for his work on this project!
|
||||||
|
def parse_sysdeps_file(sysdeps_file: Path) -> Dict[str, List[Tuple[str, str, str]]]:
|
||||||
|
"""
|
||||||
|
Parses the system dependencies file and returns a dictionary with the parsed dependencies.
|
||||||
|
:param sysdeps_file: The path to the system dependencies file.
|
||||||
|
:return: A dictionary with the parsed dependencies in the format {distro: [(package, comparator, version)]}.
|
||||||
|
"""
|
||||||
|
base_deps: Dict[str, List[str]] = json.loads(sysdeps_file.read_bytes())
|
||||||
|
parsed_deps: Dict[str, List[Tuple[str, str, str]]] = {}
|
||||||
|
|
||||||
|
for distro, pkgs in base_deps.items():
|
||||||
|
parsed_deps[distro] = []
|
||||||
|
for dep in pkgs:
|
||||||
|
parts = dep.split(";", maxsplit=1)
|
||||||
|
if len(parts) == 1:
|
||||||
|
parsed_deps[distro].append((dep.strip(), "", ""))
|
||||||
|
else:
|
||||||
|
pkg_name = parts[0].strip()
|
||||||
|
dep_parts = re.split(r"(==|!=|<=|>=|<|>)", parts[1].strip())
|
||||||
|
comp_var = dep_parts[0].strip().lower()
|
||||||
|
if len(dep_parts) != 3 or comp_var != "distro_version":
|
||||||
|
continue
|
||||||
|
operator = dep_parts[1].strip()
|
||||||
|
req_version = dep_parts[2].strip()
|
||||||
|
parsed_deps[distro].append((pkg_name, operator, req_version))
|
||||||
|
|
||||||
|
return parsed_deps
|
||||||
|
|||||||
@@ -539,3 +539,10 @@ def get_service_file_path(instance_type: type, suffix: str) -> Path:
|
|||||||
file_path: Path = SYSTEMD.joinpath(f"{name}.service")
|
file_path: Path = SYSTEMD.joinpath(f"{name}.service")
|
||||||
|
|
||||||
return file_path
|
return file_path
|
||||||
|
|
||||||
|
def get_distro_name() -> str:
|
||||||
|
return check_output(["lsb_release", "-is"]).decode().strip()
|
||||||
|
|
||||||
|
|
||||||
|
def get_distro_version() -> str:
|
||||||
|
return check_output(["lsb_release", "-rs"]).decode().strip()
|
||||||
|
|||||||
Reference in New Issue
Block a user