mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-24 00:03:42 +05:00
Compare commits
11 Commits
be228210bd
...
9864dd0c7f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9864dd0c7f | ||
|
|
d84adee7f9 | ||
|
|
c17c3e9bd4 | ||
|
|
074344cf7c | ||
|
|
42667ad792 | ||
|
|
9804411d74 | ||
|
|
067a102b6b | ||
|
|
4a5d1a971a | ||
|
|
6407664e3e | ||
|
|
65617ca971 | ||
|
|
e05a42630e |
@@ -17,7 +17,7 @@ from typing import List, Dict, Literal, Union
|
|||||||
from components.crowsnest import CROWSNEST_REPO, CROWSNEST_DIR
|
from components.crowsnest import CROWSNEST_REPO, CROWSNEST_DIR
|
||||||
from components.klipper.klipper import Klipper
|
from components.klipper.klipper import Klipper
|
||||||
from core.instance_manager.instance_manager import InstanceManager
|
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.constants import COLOR_CYAN, RESET_FORMAT, CURRENT_USER
|
||||||
from utils.git_utils import (
|
from utils.git_utils import (
|
||||||
git_clone_wrapper,
|
git_clone_wrapper,
|
||||||
@@ -28,23 +28,18 @@ from utils.git_utils import (
|
|||||||
)
|
)
|
||||||
from utils.input_utils import get_confirm
|
from utils.input_utils import get_confirm
|
||||||
from utils.logger import Logger
|
from utils.logger import Logger
|
||||||
from utils.system_utils import (
|
from utils.sys_utils import (
|
||||||
check_package_install,
|
|
||||||
install_system_packages,
|
|
||||||
parse_packages_from_file,
|
parse_packages_from_file,
|
||||||
update_system_package_lists,
|
|
||||||
control_systemd_service,
|
control_systemd_service,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def install_crowsnest() -> None:
|
def install_crowsnest() -> None:
|
||||||
# Step 1: Clone crowsnest repo
|
# Step 1: Clone crowsnest repo
|
||||||
git_clone_wrapper(CROWSNEST_REPO, "master", CROWSNEST_DIR)
|
git_clone_wrapper(CROWSNEST_REPO, CROWSNEST_DIR, "master")
|
||||||
|
|
||||||
# Step 2: Install dependencies
|
# Step 2: Install dependencies
|
||||||
requirements: List[str] = check_package_install(["make"])
|
check_install_dependencies(["make"])
|
||||||
if requirements:
|
|
||||||
install_system_packages(requirements)
|
|
||||||
|
|
||||||
# Step 3: Check for Multi Instance
|
# Step 3: Check for Multi Instance
|
||||||
im = InstanceManager(Klipper)
|
im = InstanceManager(Klipper)
|
||||||
@@ -106,7 +101,7 @@ def update_crowsnest() -> None:
|
|||||||
control_systemd_service("crowsnest", "stop")
|
control_systemd_service("crowsnest", "stop")
|
||||||
|
|
||||||
if not CROWSNEST_DIR.exists():
|
if not CROWSNEST_DIR.exists():
|
||||||
git_clone_wrapper(CROWSNEST_REPO, "master", CROWSNEST_DIR)
|
git_clone_wrapper(CROWSNEST_REPO, CROWSNEST_DIR, "master")
|
||||||
else:
|
else:
|
||||||
Logger.print_status("Updating Crowsnest ...")
|
Logger.print_status("Updating Crowsnest ...")
|
||||||
|
|
||||||
@@ -114,9 +109,7 @@ def update_crowsnest() -> None:
|
|||||||
|
|
||||||
script = CROWSNEST_DIR.joinpath("tools/install.sh")
|
script = CROWSNEST_DIR.joinpath("tools/install.sh")
|
||||||
deps = parse_packages_from_file(script)
|
deps = parse_packages_from_file(script)
|
||||||
packages = check_package_install(deps)
|
check_install_dependencies(deps)
|
||||||
update_system_package_lists(silent=False)
|
|
||||||
install_system_packages(packages)
|
|
||||||
|
|
||||||
control_systemd_service("crowsnest", "restart")
|
control_systemd_service("crowsnest", "restart")
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ from components.klipper import KLIPPER_DIR, KLIPPER_ENV_DIR
|
|||||||
from components.klipper.klipper import Klipper
|
from components.klipper.klipper import Klipper
|
||||||
from components.klipper.klipper_dialogs import print_instance_overview
|
from components.klipper.klipper_dialogs import print_instance_overview
|
||||||
from core.instance_manager.instance_manager import InstanceManager
|
from core.instance_manager.instance_manager import InstanceManager
|
||||||
from utils.filesystem_utils import remove_file
|
from utils.fs_utils import remove_file
|
||||||
from utils.input_utils import get_selection_input
|
from utils.input_utils import get_selection_input
|
||||||
from utils.logger import Logger
|
from utils.logger import Logger
|
||||||
|
|
||||||
|
|||||||
@@ -36,15 +36,14 @@ from components.klipper.klipper_utils import (
|
|||||||
)
|
)
|
||||||
from components.moonraker.moonraker import Moonraker
|
from components.moonraker.moonraker import Moonraker
|
||||||
from core.instance_manager.instance_manager import InstanceManager
|
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.git_utils import git_clone_wrapper, git_pull_wrapper
|
||||||
from utils.input_utils import get_confirm
|
from utils.input_utils import get_confirm
|
||||||
from utils.logger import Logger
|
from utils.logger import Logger
|
||||||
from utils.system_utils import (
|
from utils.sys_utils import (
|
||||||
parse_packages_from_file,
|
parse_packages_from_file,
|
||||||
create_python_venv,
|
create_python_venv,
|
||||||
install_python_requirements,
|
install_python_requirements,
|
||||||
update_system_package_lists,
|
|
||||||
install_system_packages,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -111,7 +110,7 @@ def setup_klipper_prerequesites() -> None:
|
|||||||
repo = settings.get("klipper", "repo_url")
|
repo = settings.get("klipper", "repo_url")
|
||||||
branch = settings.get("klipper", "branch")
|
branch = settings.get("klipper", "branch")
|
||||||
|
|
||||||
git_clone_wrapper(repo, branch, KLIPPER_DIR)
|
git_clone_wrapper(repo, KLIPPER_DIR, branch)
|
||||||
|
|
||||||
# install klipper dependencies and create python virtualenv
|
# install klipper dependencies and create python virtualenv
|
||||||
try:
|
try:
|
||||||
@@ -134,8 +133,7 @@ def install_klipper_packages(klipper_dir: Path) -> None:
|
|||||||
if Path("/boot/dietpi/.version").exists():
|
if Path("/boot/dietpi/.version").exists():
|
||||||
packages.append("dbus")
|
packages.append("dbus")
|
||||||
|
|
||||||
update_system_package_lists(silent=False)
|
check_install_dependencies(packages)
|
||||||
install_system_packages(packages)
|
|
||||||
|
|
||||||
|
|
||||||
def update_klipper() -> None:
|
def update_klipper() -> None:
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ from utils.constants import CURRENT_USER
|
|||||||
from utils.git_utils import get_repo_name, get_remote_commit, get_local_commit
|
from utils.git_utils import get_repo_name, get_remote_commit, get_local_commit
|
||||||
from utils.input_utils import get_confirm, get_string_input, get_number_input
|
from utils.input_utils import get_confirm, get_string_input, get_number_input
|
||||||
from utils.logger import Logger
|
from utils.logger import Logger
|
||||||
from utils.system_utils import mask_system_service
|
from utils.sys_utils import control_systemd_service
|
||||||
|
|
||||||
|
|
||||||
def get_klipper_status() -> (
|
def get_klipper_status() -> (
|
||||||
@@ -258,10 +258,7 @@ def handle_disruptive_system_packages() -> None:
|
|||||||
|
|
||||||
for service in services if services else []:
|
for service in services if services else []:
|
||||||
try:
|
try:
|
||||||
log = f"{service} service detected! Masking {service} service ..."
|
control_systemd_service(service, "mask")
|
||||||
Logger.print_status(log)
|
|
||||||
mask_system_service(service)
|
|
||||||
Logger.print_ok(f"{service} service masked!")
|
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
warn_msg = textwrap.dedent(
|
warn_msg = textwrap.dedent(
|
||||||
f"""
|
f"""
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ from components.klipper_firmware.flash_options import (
|
|||||||
)
|
)
|
||||||
from core.instance_manager.instance_manager import InstanceManager
|
from core.instance_manager.instance_manager import InstanceManager
|
||||||
from utils.logger import Logger
|
from utils.logger import Logger
|
||||||
from utils.system_utils import log_process
|
from utils.sys_utils import log_process
|
||||||
|
|
||||||
|
|
||||||
def find_firmware_file() -> bool:
|
def find_firmware_file() -> bool:
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ from core.menus import Option
|
|||||||
from core.menus.base_menu import BaseMenu
|
from core.menus.base_menu import BaseMenu
|
||||||
from utils.constants import COLOR_CYAN, RESET_FORMAT, COLOR_GREEN, COLOR_RED
|
from utils.constants import COLOR_CYAN, RESET_FORMAT, COLOR_GREEN, COLOR_RED
|
||||||
from utils.logger import Logger
|
from utils.logger import Logger
|
||||||
from utils.system_utils import (
|
from utils.sys_utils import (
|
||||||
check_package_install,
|
check_package_install,
|
||||||
update_system_package_lists,
|
update_system_package_lists,
|
||||||
install_system_packages,
|
install_system_packages,
|
||||||
@@ -90,7 +90,7 @@ class KlipperBuildFirmwareMenu(BaseMenu):
|
|||||||
install_system_packages(self.missing_deps)
|
install_system_packages(self.missing_deps)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
Logger.print_error(e)
|
Logger.print_error(e)
|
||||||
Logger.print_error("Installding dependencies failed!")
|
Logger.print_error("Installing dependencies failed!")
|
||||||
finally:
|
finally:
|
||||||
# restart this menu
|
# restart this menu
|
||||||
KlipperBuildFirmwareMenu().run()
|
KlipperBuildFirmwareMenu().run()
|
||||||
|
|||||||
16
kiauh/components/klipperscreen/__init__.py
Normal file
16
kiauh/components/klipperscreen/__init__.py
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
# ======================================================================= #
|
||||||
|
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
|
||||||
|
# #
|
||||||
|
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||||
|
# https://github.com/dw-0/kiauh #
|
||||||
|
# #
|
||||||
|
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||||
|
# ======================================================================= #
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from core.backup_manager import BACKUP_ROOT_DIR
|
||||||
|
|
||||||
|
KLIPPERSCREEN_REPO = "https://github.com/KlipperScreen/KlipperScreen.git"
|
||||||
|
KLIPPERSCREEN_DIR = Path.home().joinpath("KlipperScreen")
|
||||||
|
KLIPPERSCREEN_ENV = Path.home().joinpath(".KlipperScreen-env")
|
||||||
|
KLIPPERSCREEN_BACKUP_DIR = BACKUP_ROOT_DIR.joinpath("klipperscreen-backups")
|
||||||
213
kiauh/components/klipperscreen/klipperscreen.py
Normal file
213
kiauh/components/klipperscreen/klipperscreen.py
Normal file
@@ -0,0 +1,213 @@
|
|||||||
|
# ======================================================================= #
|
||||||
|
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
|
||||||
|
# #
|
||||||
|
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||||
|
# https://github.com/dw-0/kiauh #
|
||||||
|
# #
|
||||||
|
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||||
|
# ======================================================================= #
|
||||||
|
import shutil
|
||||||
|
from pathlib import Path
|
||||||
|
from subprocess import run, CalledProcessError
|
||||||
|
from typing import List, Dict, Literal, Union
|
||||||
|
|
||||||
|
from components.klipper.klipper import Klipper
|
||||||
|
from components.klipperscreen import (
|
||||||
|
KLIPPERSCREEN_DIR,
|
||||||
|
KLIPPERSCREEN_REPO,
|
||||||
|
KLIPPERSCREEN_ENV,
|
||||||
|
KLIPPERSCREEN_BACKUP_DIR,
|
||||||
|
)
|
||||||
|
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, 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
|
||||||
|
from utils.git_utils import (
|
||||||
|
git_clone_wrapper,
|
||||||
|
git_pull_wrapper,
|
||||||
|
get_repo_name,
|
||||||
|
get_local_commit,
|
||||||
|
get_remote_commit,
|
||||||
|
)
|
||||||
|
from utils.input_utils import get_confirm
|
||||||
|
from utils.logger import Logger
|
||||||
|
from utils.sys_utils import (
|
||||||
|
check_python_version,
|
||||||
|
control_systemd_service,
|
||||||
|
install_python_requirements,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def install_klipperscreen() -> None:
|
||||||
|
Logger.print_status("Installing KlipperScreen ...")
|
||||||
|
|
||||||
|
if not check_python_version(3, 7):
|
||||||
|
return
|
||||||
|
|
||||||
|
mr_im = InstanceManager(Moonraker)
|
||||||
|
mr_instances = mr_im.instances
|
||||||
|
if not mr_instances:
|
||||||
|
# TODO: add moonraker not found dialog
|
||||||
|
print("Moonraker not found!")
|
||||||
|
if not get_confirm(
|
||||||
|
"Continue KlipperScreen installation?",
|
||||||
|
allow_go_back=True,
|
||||||
|
):
|
||||||
|
return
|
||||||
|
|
||||||
|
package_list = ["wget", "curl", "unzip", "dfu-util"]
|
||||||
|
check_install_dependencies(package_list)
|
||||||
|
|
||||||
|
git_clone_wrapper(KLIPPERSCREEN_REPO, KLIPPERSCREEN_DIR)
|
||||||
|
|
||||||
|
try:
|
||||||
|
script = f"{KLIPPERSCREEN_DIR}/scripts/KlipperScreen-install.sh"
|
||||||
|
run(script, shell=True, check=True)
|
||||||
|
if mr_instances:
|
||||||
|
patch_klipperscreen_update_manager(mr_instances)
|
||||||
|
mr_im.restart_all_instance()
|
||||||
|
else:
|
||||||
|
Logger.print_info(
|
||||||
|
"Moonraker is not installed! Cannot add KlipperScreen to update manager!"
|
||||||
|
)
|
||||||
|
Logger.print_ok("KlipperScreen successfully installed!")
|
||||||
|
except CalledProcessError as e:
|
||||||
|
Logger.print_error(f"Error installing KlipperScreen:\n{e}")
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
def patch_klipperscreen_update_manager(instances: List[Moonraker]) -> None:
|
||||||
|
env_py = f"{KLIPPERSCREEN_ENV}/bin/python"
|
||||||
|
add_config_section(
|
||||||
|
section="update_manager KlipperScreen",
|
||||||
|
instances=instances,
|
||||||
|
options=[
|
||||||
|
("type", "git_repo"),
|
||||||
|
("path", str(KLIPPERSCREEN_DIR)),
|
||||||
|
("orgin", KLIPPERSCREEN_REPO),
|
||||||
|
("env", env_py),
|
||||||
|
("requirements", "scripts/KlipperScreen-requirements.txt"),
|
||||||
|
("install_script", "scripts/KlipperScreen-install.sh"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def update_klipperscreen() -> None:
|
||||||
|
try:
|
||||||
|
control_systemd_service("KlipperScreen", "stop")
|
||||||
|
|
||||||
|
if not KLIPPERSCREEN_DIR.exists():
|
||||||
|
Logger.print_info(
|
||||||
|
"KlipperScreen does not seem to be installed! Skipping ..."
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
|
Logger.print_status("Updating KlipperScreen ...")
|
||||||
|
|
||||||
|
control_systemd_service("KlipperScreen", "stop")
|
||||||
|
|
||||||
|
settings = KiauhSettings()
|
||||||
|
if settings.get("kiauh", "backup_before_update"):
|
||||||
|
backup_klipperscreen_dir()
|
||||||
|
|
||||||
|
git_pull_wrapper(KLIPPERSCREEN_REPO, KLIPPERSCREEN_DIR)
|
||||||
|
|
||||||
|
requirements = KLIPPERSCREEN_DIR.joinpath(
|
||||||
|
"/scripts/KlipperScreen-requirements.txt"
|
||||||
|
)
|
||||||
|
install_python_requirements(KLIPPERSCREEN_ENV, requirements)
|
||||||
|
|
||||||
|
control_systemd_service("KlipperScreen", "start")
|
||||||
|
|
||||||
|
Logger.print_ok("KlipperScreen updated successfully.", end="\n\n")
|
||||||
|
except CalledProcessError as e:
|
||||||
|
Logger.print_error(f"Something went wrong! Please try again...\n{e}")
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
def get_klipperscreen_status() -> (
|
||||||
|
Dict[
|
||||||
|
Literal["status", "status_code", "repo", "local", "remote"],
|
||||||
|
Union[str, int],
|
||||||
|
]
|
||||||
|
):
|
||||||
|
files = [
|
||||||
|
KLIPPERSCREEN_DIR,
|
||||||
|
KLIPPERSCREEN_ENV,
|
||||||
|
SYSTEMD.joinpath("KlipperScreen.service"),
|
||||||
|
]
|
||||||
|
status = get_install_status(KLIPPERSCREEN_DIR, files)
|
||||||
|
return {
|
||||||
|
"status": status.get("status"),
|
||||||
|
"status_code": status.get("status_code"),
|
||||||
|
"repo": get_repo_name(KLIPPERSCREEN_DIR),
|
||||||
|
"local": get_local_commit(KLIPPERSCREEN_DIR),
|
||||||
|
"remote": get_remote_commit(KLIPPERSCREEN_DIR),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def remove_klipperscreen() -> None:
|
||||||
|
Logger.print_status("Removing KlipperScreen ...")
|
||||||
|
try:
|
||||||
|
if KLIPPERSCREEN_DIR.exists():
|
||||||
|
Logger.print_status("Removing KlipperScreen directory ...")
|
||||||
|
shutil.rmtree(KLIPPERSCREEN_DIR)
|
||||||
|
Logger.print_ok("KlipperScreen directory successfully removed!")
|
||||||
|
else:
|
||||||
|
Logger.print_warn("KlipperScreen directory not found!")
|
||||||
|
|
||||||
|
if KLIPPERSCREEN_ENV.exists():
|
||||||
|
Logger.print_status("Removing KlipperScreen environment ...")
|
||||||
|
shutil.rmtree(KLIPPERSCREEN_ENV)
|
||||||
|
Logger.print_ok("KlipperScreen environment successfully removed!")
|
||||||
|
else:
|
||||||
|
Logger.print_warn("KlipperScreen environment not found!")
|
||||||
|
|
||||||
|
service = SYSTEMD.joinpath("KlipperScreen.service")
|
||||||
|
if service.exists():
|
||||||
|
Logger.print_status("Removing KlipperScreen service ...")
|
||||||
|
control_systemd_service(service, "stop")
|
||||||
|
control_systemd_service(service, "disable")
|
||||||
|
remove_with_sudo(service)
|
||||||
|
Logger.print_ok("KlipperScreen service successfully removed!")
|
||||||
|
|
||||||
|
logfile = Path("/tmp/KlipperScreen.log")
|
||||||
|
if logfile.exists():
|
||||||
|
Logger.print_status("Removing KlipperScreen log file ...")
|
||||||
|
remove_with_sudo(logfile)
|
||||||
|
Logger.print_ok("KlipperScreen log file successfully removed!")
|
||||||
|
|
||||||
|
kl_im = InstanceManager(Klipper)
|
||||||
|
kl_instances: List[Klipper] = kl_im.instances
|
||||||
|
for instance in kl_instances:
|
||||||
|
logfile = instance.log_dir.joinpath("KlipperScreen.log")
|
||||||
|
if logfile.exists():
|
||||||
|
Logger.print_status(f"Removing {logfile} ...")
|
||||||
|
Path(logfile).unlink()
|
||||||
|
Logger.print_ok(f"{logfile} successfully removed!")
|
||||||
|
|
||||||
|
mr_im = InstanceManager(Moonraker)
|
||||||
|
mr_instances: List[Moonraker] = mr_im.instances
|
||||||
|
if mr_instances:
|
||||||
|
Logger.print_status("Removing KlipperScreen from update manager ...")
|
||||||
|
remove_config_section("update_manager KlipperScreen", mr_instances)
|
||||||
|
Logger.print_ok("KlipperScreen successfully removed from update manager!")
|
||||||
|
|
||||||
|
Logger.print_ok("KlipperScreen successfully removed!")
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
Logger.print_error(f"Error removing KlipperScreen:\n{e}")
|
||||||
|
|
||||||
|
|
||||||
|
def backup_klipperscreen_dir() -> None:
|
||||||
|
bm = BackupManager()
|
||||||
|
bm.backup_directory(
|
||||||
|
"KlipperScreen", source=KLIPPERSCREEN_DIR, target=KLIPPERSCREEN_BACKUP_DIR
|
||||||
|
)
|
||||||
|
bm.backup_directory(
|
||||||
|
"KlipperScreen-env", source=KLIPPERSCREEN_ENV, target=KLIPPERSCREEN_BACKUP_DIR
|
||||||
|
)
|
||||||
@@ -15,7 +15,7 @@ from components.klipper.klipper_dialogs import print_instance_overview
|
|||||||
from components.moonraker import MOONRAKER_DIR, MOONRAKER_ENV_DIR
|
from components.moonraker import MOONRAKER_DIR, MOONRAKER_ENV_DIR
|
||||||
from components.moonraker.moonraker import Moonraker
|
from components.moonraker.moonraker import Moonraker
|
||||||
from core.instance_manager.instance_manager import InstanceManager
|
from core.instance_manager.instance_manager import InstanceManager
|
||||||
from utils.filesystem_utils import remove_file
|
from utils.fs_utils import remove_file
|
||||||
from utils.input_utils import get_selection_input
|
from utils.input_utils import get_selection_input
|
||||||
from utils.logger import Logger
|
from utils.logger import Logger
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
# ======================================================================= #
|
# ======================================================================= #
|
||||||
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from components.webui_client.client_utils import (
|
from components.webui_client.client_utils import (
|
||||||
@@ -35,19 +34,19 @@ from components.moonraker.moonraker_utils import (
|
|||||||
backup_moonraker_dir,
|
backup_moonraker_dir,
|
||||||
)
|
)
|
||||||
from core.instance_manager.instance_manager import InstanceManager
|
from core.instance_manager.instance_manager import InstanceManager
|
||||||
from utils.filesystem_utils import check_file_exist
|
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.git_utils import git_clone_wrapper, git_pull_wrapper
|
||||||
from utils.input_utils import (
|
from utils.input_utils import (
|
||||||
get_confirm,
|
get_confirm,
|
||||||
get_selection_input,
|
get_selection_input,
|
||||||
)
|
)
|
||||||
from utils.logger import Logger
|
from utils.logger import Logger
|
||||||
from utils.system_utils import (
|
from utils.sys_utils import (
|
||||||
parse_packages_from_file,
|
parse_packages_from_file,
|
||||||
create_python_venv,
|
create_python_venv,
|
||||||
install_python_requirements,
|
install_python_requirements,
|
||||||
update_system_package_lists,
|
check_python_version,
|
||||||
install_system_packages,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -116,18 +115,15 @@ def install_moonraker() -> None:
|
|||||||
|
|
||||||
|
|
||||||
def check_moonraker_install_requirements() -> bool:
|
def check_moonraker_install_requirements() -> bool:
|
||||||
if not (sys.version_info.major >= 3 and sys.version_info.minor >= 7):
|
def check_klipper_instances() -> bool:
|
||||||
Logger.print_error("Versioncheck failed!")
|
if len(InstanceManager(Klipper).instances) >= 1:
|
||||||
Logger.print_error("Python 3.7 or newer required to run Moonraker.")
|
return True
|
||||||
return False
|
|
||||||
|
|
||||||
kl_instance_count = len(InstanceManager(Klipper).instances)
|
|
||||||
if kl_instance_count < 1:
|
|
||||||
Logger.print_warn("Klipper not installed!")
|
Logger.print_warn("Klipper not installed!")
|
||||||
Logger.print_warn("Moonraker cannot be installed! Install Klipper first.")
|
Logger.print_warn("Moonraker cannot be installed! Install Klipper first.")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return check_python_version(3, 7) and check_klipper_instances()
|
||||||
|
|
||||||
|
|
||||||
def setup_moonraker_prerequesites() -> None:
|
def setup_moonraker_prerequesites() -> None:
|
||||||
@@ -135,7 +131,7 @@ def setup_moonraker_prerequesites() -> None:
|
|||||||
repo = settings.get("moonraker", "repo_url")
|
repo = settings.get("moonraker", "repo_url")
|
||||||
branch = settings.get("moonraker", "branch")
|
branch = settings.get("moonraker", "branch")
|
||||||
|
|
||||||
git_clone_wrapper(repo, branch, MOONRAKER_DIR)
|
git_clone_wrapper(repo, MOONRAKER_DIR, branch)
|
||||||
|
|
||||||
# install moonraker dependencies and create python virtualenv
|
# install moonraker dependencies and create python virtualenv
|
||||||
install_moonraker_packages(MOONRAKER_DIR)
|
install_moonraker_packages(MOONRAKER_DIR)
|
||||||
@@ -146,8 +142,7 @@ def setup_moonraker_prerequesites() -> None:
|
|||||||
def install_moonraker_packages(moonraker_dir: Path) -> None:
|
def install_moonraker_packages(moonraker_dir: Path) -> None:
|
||||||
script = moonraker_dir.joinpath("scripts/install-moonraker.sh")
|
script = moonraker_dir.joinpath("scripts/install-moonraker.sh")
|
||||||
packages = parse_packages_from_file(script)
|
packages = parse_packages_from_file(script)
|
||||||
update_system_package_lists(silent=False)
|
check_install_dependencies(packages)
|
||||||
install_system_packages(packages)
|
|
||||||
|
|
||||||
|
|
||||||
def install_moonraker_polkit() -> None:
|
def install_moonraker_polkit() -> None:
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ from core.instance_manager.instance_manager import InstanceManager
|
|||||||
from utils.common import get_install_status_common
|
from utils.common import get_install_status_common
|
||||||
from utils.git_utils import get_repo_name, get_local_commit, get_remote_commit
|
from utils.git_utils import get_repo_name, get_local_commit, get_remote_commit
|
||||||
from utils.logger import Logger
|
from utils.logger import Logger
|
||||||
from utils.system_utils import (
|
from utils.sys_utils import (
|
||||||
get_ipv4_addr,
|
get_ipv4_addr,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ from components.moonraker.moonraker import Moonraker
|
|||||||
from components.webui_client.base_data import BaseWebClientConfig
|
from components.webui_client.base_data import BaseWebClientConfig
|
||||||
from core.instance_manager.instance_manager import InstanceManager
|
from core.instance_manager.instance_manager import InstanceManager
|
||||||
from utils.config_utils import remove_config_section
|
from utils.config_utils import remove_config_section
|
||||||
from utils.filesystem_utils import remove_file
|
from utils.fs_utils import remove_file
|
||||||
from utils.logger import Logger
|
from utils.logger import Logger
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ from components.webui_client.client_utils import (
|
|||||||
from core.instance_manager.instance_manager import InstanceManager
|
from core.instance_manager.instance_manager import InstanceManager
|
||||||
from utils.common import backup_printer_config_dir
|
from utils.common import backup_printer_config_dir
|
||||||
from utils.config_utils import add_config_section, add_config_section_at_top
|
from utils.config_utils import add_config_section, add_config_section_at_top
|
||||||
from utils.filesystem_utils import create_symlink
|
from utils.fs_utils import create_symlink
|
||||||
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
|
from utils.input_utils import get_confirm
|
||||||
from utils.logger import Logger
|
from utils.logger import Logger
|
||||||
@@ -85,7 +85,7 @@ def download_client_config(client_config: BaseWebClientConfig) -> None:
|
|||||||
Logger.print_status(f"Downloading {client_config.display_name} ...")
|
Logger.print_status(f"Downloading {client_config.display_name} ...")
|
||||||
repo = client_config.repo_url
|
repo = client_config.repo_url
|
||||||
target_dir = client_config.config_dir
|
target_dir = client_config.config_dir
|
||||||
git_clone_wrapper(repo, None, target_dir)
|
git_clone_wrapper(repo, target_dir)
|
||||||
except Exception:
|
except Exception:
|
||||||
Logger.print_error(f"Downloading {client_config.display_name} failed!")
|
Logger.print_error(f"Downloading {client_config.display_name} failed!")
|
||||||
raise
|
raise
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ from components.webui_client.client_utils import backup_mainsail_config_json
|
|||||||
|
|
||||||
from core.instance_manager.instance_manager import InstanceManager
|
from core.instance_manager.instance_manager import InstanceManager
|
||||||
from utils.config_utils import remove_config_section
|
from utils.config_utils import remove_config_section
|
||||||
from utils.filesystem_utils import (
|
from utils.fs_utils import (
|
||||||
remove_nginx_config,
|
remove_nginx_config,
|
||||||
remove_nginx_logs,
|
remove_nginx_logs,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ from core.settings.kiauh_settings import KiauhSettings
|
|||||||
from utils import NGINX_SITES_AVAILABLE, NGINX_SITES_ENABLED
|
from utils import NGINX_SITES_AVAILABLE, NGINX_SITES_ENABLED
|
||||||
from utils.common import check_install_dependencies
|
from utils.common import check_install_dependencies
|
||||||
from utils.config_utils import add_config_section
|
from utils.config_utils import add_config_section
|
||||||
from utils.filesystem_utils import (
|
from utils.fs_utils import (
|
||||||
unzip,
|
unzip,
|
||||||
copy_upstream_nginx_cfg,
|
copy_upstream_nginx_cfg,
|
||||||
copy_common_vars_nginx_cfg,
|
copy_common_vars_nginx_cfg,
|
||||||
@@ -51,7 +51,7 @@ from utils.filesystem_utils import (
|
|||||||
)
|
)
|
||||||
from utils.input_utils import get_confirm, get_number_input
|
from utils.input_utils import get_confirm, get_number_input
|
||||||
from utils.logger import Logger
|
from utils.logger import Logger
|
||||||
from utils.system_utils import (
|
from utils.sys_utils import (
|
||||||
download_file,
|
download_file,
|
||||||
set_nginx_permissions,
|
set_nginx_permissions,
|
||||||
get_ipv4_addr,
|
get_ipv4_addr,
|
||||||
|
|||||||
@@ -39,13 +39,15 @@ class BackupManager:
|
|||||||
def ignore_folders(self, value: List[str]):
|
def ignore_folders(self, value: List[str]):
|
||||||
self._ignore_folders = value
|
self._ignore_folders = value
|
||||||
|
|
||||||
def backup_file(self, file: Path = None, target: Path = None, custom_filename=None):
|
def backup_file(self, file: Path, target: Path = None, custom_filename=None):
|
||||||
if not file:
|
Logger.print_status(f"Creating backup of {file} ...")
|
||||||
raise ValueError("Parameter 'file' cannot be None!")
|
|
||||||
|
if not file.exists():
|
||||||
|
Logger.print_info("File does not exist! Skipping ...")
|
||||||
|
return
|
||||||
|
|
||||||
target = self.backup_root_dir if target is None else target
|
target = self.backup_root_dir if target is None else target
|
||||||
|
|
||||||
Logger.print_status(f"Creating backup of {file} ...")
|
|
||||||
if Path(file).is_file():
|
if Path(file).is_file():
|
||||||
date = get_current_date().get("date")
|
date = get_current_date().get("date")
|
||||||
time = get_current_date().get("time")
|
time = get_current_date().get("time")
|
||||||
@@ -61,13 +63,14 @@ class BackupManager:
|
|||||||
Logger.print_info(f"File '{file}' not found ...")
|
Logger.print_info(f"File '{file}' not found ...")
|
||||||
|
|
||||||
def backup_directory(self, name: str, source: Path, target: Path = None) -> None:
|
def backup_directory(self, name: str, source: Path, target: Path = None) -> None:
|
||||||
|
Logger.print_status(f"Creating backup of {name} in {target} ...")
|
||||||
|
|
||||||
if source is None or not Path(source).exists():
|
if source is None or not Path(source).exists():
|
||||||
raise OSError("Parameter 'source' is None or Path does not exist!")
|
Logger.print_info("Source directory does not exist! Skipping ...")
|
||||||
|
return
|
||||||
|
|
||||||
target = self.backup_root_dir if target is None else target
|
target = self.backup_root_dir if target is None else target
|
||||||
try:
|
try:
|
||||||
log = f"Creating backup of {name} in {target} ..."
|
|
||||||
Logger.print_status(log)
|
|
||||||
date = get_current_date().get("date")
|
date = get_current_date().get("date")
|
||||||
time = get_current_date().get("time")
|
time = get_current_date().get("time")
|
||||||
shutil.copytree(
|
shutil.copytree(
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ from typing import List, Optional, Union, TypeVar
|
|||||||
from core.instance_manager.base_instance import BaseInstance
|
from core.instance_manager.base_instance import BaseInstance
|
||||||
from utils.constants import SYSTEMD
|
from utils.constants import SYSTEMD
|
||||||
from utils.logger import Logger
|
from utils.logger import Logger
|
||||||
from utils.system_utils import control_systemd_service
|
from utils.sys_utils import control_systemd_service
|
||||||
|
|
||||||
T = TypeVar(name="T", bound=BaseInstance, covariant=True)
|
T = TypeVar(name="T", bound=BaseInstance, covariant=True)
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import textwrap
|
|||||||
from typing import Type, Optional
|
from typing import Type, Optional
|
||||||
|
|
||||||
from components.klipper.klipper_utils import backup_klipper_dir
|
from components.klipper.klipper_utils import backup_klipper_dir
|
||||||
|
from components.klipperscreen.klipperscreen import backup_klipperscreen_dir
|
||||||
from components.moonraker.moonraker_utils import (
|
from components.moonraker.moonraker_utils import (
|
||||||
backup_moonraker_dir,
|
backup_moonraker_dir,
|
||||||
backup_moonraker_db_dir,
|
backup_moonraker_db_dir,
|
||||||
@@ -104,4 +105,4 @@ class BackupMenu(BaseMenu):
|
|||||||
backup_client_config_data(FluiddData())
|
backup_client_config_data(FluiddData())
|
||||||
|
|
||||||
def backup_klipperscreen(self, **kwargs):
|
def backup_klipperscreen(self, **kwargs):
|
||||||
pass
|
backup_klipperscreen_dir()
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ from typing import Type, Optional
|
|||||||
|
|
||||||
from components.crowsnest.crowsnest import install_crowsnest
|
from components.crowsnest.crowsnest import install_crowsnest
|
||||||
from components.klipper import klipper_setup
|
from components.klipper import klipper_setup
|
||||||
|
from components.klipperscreen.klipperscreen import install_klipperscreen
|
||||||
from components.moonraker import moonraker_setup
|
from components.moonraker import moonraker_setup
|
||||||
from components.webui_client import client_setup
|
from components.webui_client import client_setup
|
||||||
from components.webui_client.client_config import client_config_setup
|
from components.webui_client.client_config import client_config_setup
|
||||||
@@ -45,6 +46,7 @@ class InstallMenu(BaseMenu):
|
|||||||
"4": Option(method=self.install_fluidd, menu=False),
|
"4": Option(method=self.install_fluidd, menu=False),
|
||||||
"5": Option(method=self.install_mainsail_config, menu=False),
|
"5": Option(method=self.install_mainsail_config, menu=False),
|
||||||
"6": Option(method=self.install_fluidd_config, menu=False),
|
"6": Option(method=self.install_fluidd_config, menu=False),
|
||||||
|
"7": Option(method=self.install_klipperscreen, menu=False),
|
||||||
"9": Option(method=self.install_crowsnest, menu=False),
|
"9": Option(method=self.install_crowsnest, menu=False),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,5 +93,8 @@ class InstallMenu(BaseMenu):
|
|||||||
def install_fluidd_config(self, **kwargs):
|
def install_fluidd_config(self, **kwargs):
|
||||||
client_config_setup.install_client_config(FluiddData())
|
client_config_setup.install_client_config(FluiddData())
|
||||||
|
|
||||||
|
def install_klipperscreen(self, **kwargs):
|
||||||
|
install_klipperscreen()
|
||||||
|
|
||||||
def install_crowsnest(self, **kwargs):
|
def install_crowsnest(self, **kwargs):
|
||||||
install_crowsnest()
|
install_crowsnest()
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ from typing import Type, Optional
|
|||||||
|
|
||||||
from components.crowsnest.crowsnest import get_crowsnest_status
|
from components.crowsnest.crowsnest import get_crowsnest_status
|
||||||
from components.klipper.klipper_utils import get_klipper_status
|
from components.klipper.klipper_utils import get_klipper_status
|
||||||
|
from components.klipperscreen.klipperscreen import get_klipperscreen_status
|
||||||
from components.log_uploads.menus.log_upload_menu import LogUploadMenu
|
from components.log_uploads.menus.log_upload_menu import LogUploadMenu
|
||||||
from components.moonraker.moonraker_utils import get_moonraker_status
|
from components.moonraker.moonraker_utils import get_moonraker_status
|
||||||
from components.webui_client.client_utils import (
|
from components.webui_client.client_utils import (
|
||||||
@@ -91,6 +92,7 @@ class MainMenu(BaseMenu):
|
|||||||
self.ms_status = get_client_status(MainsailData())
|
self.ms_status = get_client_status(MainsailData())
|
||||||
self.fl_status = get_client_status(FluiddData())
|
self.fl_status = get_client_status(FluiddData())
|
||||||
self.cc_status = get_current_client_config([MainsailData(), FluiddData()])
|
self.cc_status = get_current_client_config([MainsailData(), FluiddData()])
|
||||||
|
self._update_status("ks", get_klipperscreen_status)
|
||||||
self._update_status("cn", get_crowsnest_status)
|
self._update_status("cn", get_crowsnest_status)
|
||||||
|
|
||||||
def _update_status(self, status_name: str, status_fn: callable) -> None:
|
def _update_status(self, status_name: str, status_fn: callable) -> None:
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ from typing import Type, Optional
|
|||||||
|
|
||||||
from components.crowsnest.crowsnest import remove_crowsnest
|
from components.crowsnest.crowsnest import remove_crowsnest
|
||||||
from components.klipper.menus.klipper_remove_menu import KlipperRemoveMenu
|
from components.klipper.menus.klipper_remove_menu import KlipperRemoveMenu
|
||||||
|
from components.klipperscreen.klipperscreen import remove_klipperscreen
|
||||||
from components.moonraker.menus.moonraker_remove_menu import (
|
from components.moonraker.menus.moonraker_remove_menu import (
|
||||||
MoonrakerRemoveMenu,
|
MoonrakerRemoveMenu,
|
||||||
)
|
)
|
||||||
@@ -43,6 +44,7 @@ class RemoveMenu(BaseMenu):
|
|||||||
"2": Option(method=self.remove_moonraker, menu=True),
|
"2": Option(method=self.remove_moonraker, menu=True),
|
||||||
"3": Option(method=self.remove_mainsail, menu=True),
|
"3": Option(method=self.remove_mainsail, menu=True),
|
||||||
"4": Option(method=self.remove_fluidd, menu=True),
|
"4": Option(method=self.remove_fluidd, menu=True),
|
||||||
|
"5": Option(method=self.remove_klipperscreen, menu=True),
|
||||||
"6": Option(method=self.remove_crowsnest, menu=True),
|
"6": Option(method=self.remove_crowsnest, menu=True),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,5 +83,8 @@ class RemoveMenu(BaseMenu):
|
|||||||
def remove_fluidd(self, **kwargs):
|
def remove_fluidd(self, **kwargs):
|
||||||
ClientRemoveMenu(previous_menu=self.__class__, client=FluiddData()).run()
|
ClientRemoveMenu(previous_menu=self.__class__, client=FluiddData()).run()
|
||||||
|
|
||||||
|
def remove_klipperscreen(self, **kwargs):
|
||||||
|
remove_klipperscreen()
|
||||||
|
|
||||||
def remove_crowsnest(self, **kwargs):
|
def remove_crowsnest(self, **kwargs):
|
||||||
remove_crowsnest()
|
remove_crowsnest()
|
||||||
|
|||||||
@@ -199,7 +199,7 @@ class SettingsMenu(BaseMenu):
|
|||||||
|
|
||||||
repo = self.kiauh_settings.get(name, "repo_url")
|
repo = self.kiauh_settings.get(name, "repo_url")
|
||||||
branch = self.kiauh_settings.get(name, "branch")
|
branch = self.kiauh_settings.get(name, "branch")
|
||||||
git_clone_wrapper(repo, branch, target_dir)
|
git_clone_wrapper(repo, target_dir, branch)
|
||||||
|
|
||||||
im.start_all_instance()
|
im.start_all_instance()
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,10 @@ from components.klipper.klipper_setup import update_klipper
|
|||||||
from components.klipper.klipper_utils import (
|
from components.klipper.klipper_utils import (
|
||||||
get_klipper_status,
|
get_klipper_status,
|
||||||
)
|
)
|
||||||
|
from components.klipperscreen.klipperscreen import (
|
||||||
|
update_klipperscreen,
|
||||||
|
get_klipperscreen_status,
|
||||||
|
)
|
||||||
from components.moonraker.moonraker_setup import update_moonraker
|
from components.moonraker.moonraker_setup import update_moonraker
|
||||||
from components.moonraker.moonraker_utils import get_moonraker_status
|
from components.moonraker.moonraker_utils import get_moonraker_status
|
||||||
from components.webui_client.client_config.client_config_setup import (
|
from components.webui_client.client_config.client_config_setup import (
|
||||||
@@ -58,6 +62,8 @@ class UpdateMenu(BaseMenu):
|
|||||||
self.mc_remote = f"{COLOR_WHITE}{RESET_FORMAT}"
|
self.mc_remote = f"{COLOR_WHITE}{RESET_FORMAT}"
|
||||||
self.fc_local = f"{COLOR_WHITE}{RESET_FORMAT}"
|
self.fc_local = f"{COLOR_WHITE}{RESET_FORMAT}"
|
||||||
self.fc_remote = f"{COLOR_WHITE}{RESET_FORMAT}"
|
self.fc_remote = f"{COLOR_WHITE}{RESET_FORMAT}"
|
||||||
|
self.ks_local = f"{COLOR_WHITE}{RESET_FORMAT}"
|
||||||
|
self.ks_remote = f"{COLOR_WHITE}{RESET_FORMAT}"
|
||||||
self.cn_local = f"{COLOR_WHITE}{RESET_FORMAT}"
|
self.cn_local = f"{COLOR_WHITE}{RESET_FORMAT}"
|
||||||
self.cn_remote = f"{COLOR_WHITE}{RESET_FORMAT}"
|
self.cn_remote = f"{COLOR_WHITE}{RESET_FORMAT}"
|
||||||
|
|
||||||
@@ -112,7 +118,7 @@ class UpdateMenu(BaseMenu):
|
|||||||
| 6) Fluidd-Config | {self.fc_local:<22} | {self.fc_remote:<22} |
|
| 6) Fluidd-Config | {self.fc_local:<22} | {self.fc_remote:<22} |
|
||||||
| | | |
|
| | | |
|
||||||
| Other: |---------------|---------------|
|
| Other: |---------------|---------------|
|
||||||
| 7) KlipperScreen | | |
|
| 7) KlipperScreen | {self.ks_local:<22} | {self.ks_remote:<22} |
|
||||||
| 8) Mobileraker | | |
|
| 8) Mobileraker | | |
|
||||||
| 9) Crowsnest | {self.cn_local:<22} | {self.cn_remote:<22} |
|
| 9) Crowsnest | {self.cn_local:<22} | {self.cn_remote:<22} |
|
||||||
| |-------------------------------|
|
| |-------------------------------|
|
||||||
@@ -142,7 +148,8 @@ class UpdateMenu(BaseMenu):
|
|||||||
def update_fluidd_config(self, **kwargs):
|
def update_fluidd_config(self, **kwargs):
|
||||||
update_client_config(self.fluidd_client)
|
update_client_config(self.fluidd_client)
|
||||||
|
|
||||||
def update_klipperscreen(self, **kwargs): ...
|
def update_klipperscreen(self, **kwargs):
|
||||||
|
update_klipperscreen()
|
||||||
|
|
||||||
def update_mobileraker(self, **kwargs): ...
|
def update_mobileraker(self, **kwargs): ...
|
||||||
|
|
||||||
@@ -193,6 +200,13 @@ class UpdateMenu(BaseMenu):
|
|||||||
)
|
)
|
||||||
self.fc_remote = f"{COLOR_GREEN}{fc_status.get('remote')}{RESET_FORMAT}"
|
self.fc_remote = f"{COLOR_GREEN}{fc_status.get('remote')}{RESET_FORMAT}"
|
||||||
|
|
||||||
|
# klipperscreen
|
||||||
|
ks_status = get_klipperscreen_status()
|
||||||
|
self.ks_local = self.format_local_status(
|
||||||
|
ks_status.get("local"), ks_status.get("remote")
|
||||||
|
)
|
||||||
|
self.ks_remote = f"{COLOR_GREEN}{ks_status.get('remote')}{RESET_FORMAT}"
|
||||||
|
|
||||||
# crowsnest
|
# crowsnest
|
||||||
cn_status = get_crowsnest_status()
|
cn_status = get_crowsnest_status()
|
||||||
self.cn_local = self.format_local_status(
|
self.cn_local = self.format_local_status(
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ from core.config_manager.config_manager import CustomConfigParser
|
|||||||
from kiauh import PROJECT_ROOT
|
from kiauh import PROJECT_ROOT
|
||||||
from utils.constants import RESET_FORMAT, COLOR_RED
|
from utils.constants import RESET_FORMAT, COLOR_RED
|
||||||
from utils.logger import Logger
|
from utils.logger import Logger
|
||||||
from utils.system_utils import kill
|
from utils.sys_utils import kill
|
||||||
|
|
||||||
|
|
||||||
# noinspection PyUnusedLocal
|
# noinspection PyUnusedLocal
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ from extensions.gcode_shell_cmd import (
|
|||||||
EXAMPLE_CFG_SRC,
|
EXAMPLE_CFG_SRC,
|
||||||
KLIPPER_EXTRAS,
|
KLIPPER_EXTRAS,
|
||||||
)
|
)
|
||||||
from utils.filesystem_utils import check_file_exist
|
from utils.fs_utils import check_file_exist
|
||||||
from utils.input_utils import get_confirm
|
from utils.input_utils import get_confirm
|
||||||
from utils.logger import Logger
|
from utils.logger import Logger
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ from extensions.klipper_backup import (
|
|||||||
MOONRAKER_CONF,
|
MOONRAKER_CONF,
|
||||||
)
|
)
|
||||||
|
|
||||||
from utils.filesystem_utils import check_file_exist
|
from utils.fs_utils import check_file_exist
|
||||||
from utils.input_utils import get_confirm
|
from utils.input_utils import get_confirm
|
||||||
from utils.logger import Logger
|
from utils.logger import Logger
|
||||||
|
|
||||||
@@ -167,7 +167,7 @@ class KlipperbackupExtension(BaseExtension):
|
|||||||
Logger.print_error("Unable to remove the Klipper-Backup cron entry")
|
Logger.print_error("Unable to remove the Klipper-Backup cron entry")
|
||||||
|
|
||||||
# Remove Moonraker entry
|
# Remove Moonraker entry
|
||||||
Logger.print_status(f"Check for Klipper-Backup moonraker entry ...")
|
Logger.print_status("Check for Klipper-Backup moonraker entry ...")
|
||||||
try:
|
try:
|
||||||
if remove_moonraker_entry():
|
if remove_moonraker_entry():
|
||||||
Logger.print_ok("Klipper-Backup entry in moonraker.conf removed")
|
Logger.print_ok("Klipper-Backup entry in moonraker.conf removed")
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ class MainsailThemeInstallMenu(BaseMenu):
|
|||||||
return
|
return
|
||||||
|
|
||||||
for printer in printer_list:
|
for printer in printer_list:
|
||||||
git_clone_wrapper(theme_repo_url, None, printer.cfg_dir.joinpath(".theme"))
|
git_clone_wrapper(theme_repo_url, printer.cfg_dir.joinpath(".theme"))
|
||||||
|
|
||||||
if len(theme_data.get("short_note", "")) > 1:
|
if len(theme_data.get("short_note", "")) > 1:
|
||||||
Logger.print_warn("Info from the creator:", prefix=False, start="\n")
|
Logger.print_warn("Info from the creator:", prefix=False, start="\n")
|
||||||
|
|||||||
@@ -22,9 +22,12 @@ from utils.constants import (
|
|||||||
COLOR_GREEN,
|
COLOR_GREEN,
|
||||||
COLOR_RED,
|
COLOR_RED,
|
||||||
)
|
)
|
||||||
from utils.filesystem_utils import check_file_exist
|
|
||||||
from utils.logger import Logger
|
from utils.logger import Logger
|
||||||
from utils.system_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]:
|
def get_current_date() -> Dict[Literal["date", "time"], str]:
|
||||||
@@ -52,6 +55,7 @@ def check_install_dependencies(deps: List[str]) -> None:
|
|||||||
Logger.print_info("The following packages need installation:")
|
Logger.print_info("The following packages need installation:")
|
||||||
for _ in requirements:
|
for _ in requirements:
|
||||||
print(f"{COLOR_CYAN}● {_}{RESET_FORMAT}")
|
print(f"{COLOR_CYAN}● {_}{RESET_FORMAT}")
|
||||||
|
update_system_package_lists(silent=False)
|
||||||
install_system_packages(requirements)
|
install_system_packages(requirements)
|
||||||
|
|
||||||
|
|
||||||
@@ -119,12 +123,8 @@ def get_install_status_webui(
|
|||||||
:param common_cfg: the required common_vars.conf
|
:param common_cfg: the required common_vars.conf
|
||||||
:return: formatted string, containing the status
|
:return: formatted string, containing the status
|
||||||
"""
|
"""
|
||||||
dir_exist = install_dir.exists()
|
status = [install_dir.exists(), nginx_cfg.exists()]
|
||||||
nginx_cfg_exist = check_file_exist(nginx_cfg)
|
general_nginx_status = [upstreams_cfg.exists(), common_cfg.exists()]
|
||||||
upstreams_cfg_exist = check_file_exist(upstreams_cfg)
|
|
||||||
common_cfg_exist = check_file_exist(common_cfg)
|
|
||||||
status = [dir_exist, nginx_cfg_exist]
|
|
||||||
general_nginx_status = [upstreams_cfg_exist, common_cfg_exist]
|
|
||||||
|
|
||||||
if all(status) and all(general_nginx_status):
|
if all(status) and all(general_nginx_status):
|
||||||
return f"{COLOR_GREEN}Installed!{RESET_FORMAT}"
|
return f"{COLOR_GREEN}Installed!{RESET_FORMAT}"
|
||||||
|
|||||||
22
kiauh/utils/decorators.py
Normal file
22
kiauh/utils/decorators.py
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
# ======================================================================= #
|
||||||
|
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
|
||||||
|
# #
|
||||||
|
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||||
|
# https://github.com/dw-0/kiauh #
|
||||||
|
# #
|
||||||
|
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||||
|
# ======================================================================= #
|
||||||
|
import warnings
|
||||||
|
from typing import Callable
|
||||||
|
|
||||||
|
|
||||||
|
def deprecated(info: str = "", replaced_by: Callable = None) -> Callable:
|
||||||
|
def decorator(func):
|
||||||
|
def wrapper(*args, **kwargs):
|
||||||
|
msg = f"{info}{replaced_by.__name__ if replaced_by else ''}"
|
||||||
|
warnings.warn(msg, category=DeprecationWarning, stacklevel=2)
|
||||||
|
return func(*args, **kwargs)
|
||||||
|
|
||||||
|
return wrapper
|
||||||
|
|
||||||
|
return decorator
|
||||||
@@ -24,6 +24,7 @@ from utils import (
|
|||||||
NGINX_CONFD,
|
NGINX_CONFD,
|
||||||
NGINX_SITES_ENABLED,
|
NGINX_SITES_ENABLED,
|
||||||
)
|
)
|
||||||
|
from utils.decorators import deprecated
|
||||||
from utils.logger import Logger
|
from utils.logger import Logger
|
||||||
|
|
||||||
|
|
||||||
@@ -59,6 +60,16 @@ def create_symlink(source: Path, target: Path, sudo=False) -> None:
|
|||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
def remove_with_sudo(file_path: Path) -> None:
|
||||||
|
try:
|
||||||
|
cmd = ["sudo", "rm", "-f", file_path]
|
||||||
|
run(cmd, stderr=PIPE, check=True)
|
||||||
|
except CalledProcessError as e:
|
||||||
|
Logger.print_error(f"Failed to remove file: {e}")
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
@deprecated(info="Use remove_with_sudo instead", replaced_by=remove_with_sudo)
|
||||||
def remove_file(file_path: Path, sudo=False) -> None:
|
def remove_file(file_path: Path, sudo=False) -> None:
|
||||||
try:
|
try:
|
||||||
cmd = f"{'sudo ' if sudo else ''}rm -f {file_path}"
|
cmd = f"{'sudo ' if sudo else ''}rm -f {file_path}"
|
||||||
@@ -13,7 +13,9 @@ from utils.input_utils import get_number_input, get_confirm
|
|||||||
from utils.logger import Logger
|
from utils.logger import Logger
|
||||||
|
|
||||||
|
|
||||||
def git_clone_wrapper(repo: str, branch: Optional[str], target_dir: Path) -> None:
|
def git_clone_wrapper(
|
||||||
|
repo: str, target_dir: Path, branch: Optional[str] = None
|
||||||
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Clones a repository from the given URL and checks out the specified branch if given.
|
Clones a repository from the given URL and checks out the specified branch if given.
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ from typing import List, Literal
|
|||||||
|
|
||||||
import select
|
import select
|
||||||
|
|
||||||
from utils.filesystem_utils import check_file_exist
|
from utils.fs_utils import check_file_exist
|
||||||
from utils.input_utils import get_confirm
|
from utils.input_utils import get_confirm
|
||||||
from utils.logger import Logger
|
from utils.logger import Logger
|
||||||
|
|
||||||
@@ -39,6 +39,20 @@ def kill(opt_err_msg: str = "") -> None:
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def check_python_version(major: int, minor: int) -> bool:
|
||||||
|
"""
|
||||||
|
Checks the python version and returns True if it's at least the given version
|
||||||
|
:param major: the major version to check
|
||||||
|
:param minor: the minor version to check
|
||||||
|
:return: bool
|
||||||
|
"""
|
||||||
|
if not (sys.version_info.major >= major and sys.version_info.minor >= minor):
|
||||||
|
Logger.print_error("Versioncheck failed!")
|
||||||
|
Logger.print_error(f"Python {major}.{minor} or newer required.")
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def parse_packages_from_file(source_file: Path) -> List[str]:
|
def parse_packages_from_file(source_file: Path) -> List[str]:
|
||||||
"""
|
"""
|
||||||
Read the package names from bash scripts, when defined like:
|
Read the package names from bash scripts, when defined like:
|
||||||
@@ -233,20 +247,6 @@ def install_system_packages(packages: List[str]) -> None:
|
|||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
def mask_system_service(service_name: str) -> None:
|
|
||||||
"""
|
|
||||||
Mask a system service to prevent it from starting |
|
|
||||||
:param service_name: name of the service to mask
|
|
||||||
:return: None
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
control_systemd_service(service_name, "mask")
|
|
||||||
except CalledProcessError as e:
|
|
||||||
log = f"Unable to mask system service {service_name}: {e.stderr.decode()}"
|
|
||||||
Logger.print_error(log)
|
|
||||||
raise
|
|
||||||
|
|
||||||
|
|
||||||
# this feels hacky and not quite right, but for now it works
|
# this feels hacky and not quite right, but for now it works
|
||||||
# see: https://stackoverflow.com/questions/166506/finding-local-ip-addresses-using-pythons-stdlib
|
# see: https://stackoverflow.com/questions/166506/finding-local-ip-addresses-using-pythons-stdlib
|
||||||
def get_ipv4_addr() -> str:
|
def get_ipv4_addr() -> str:
|
||||||
Reference in New Issue
Block a user