mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-29 02:33:37 +05:00
Compare commits
5 Commits
v6.0.0-alp
...
b604d93d0c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b604d93d0c | ||
|
|
7e87f8af32 | ||
|
|
29b5ab00cd | ||
|
|
694a4c20c5 | ||
|
|
a54514c400 |
@@ -17,8 +17,8 @@ from core.constants import (
|
|||||||
COLOR_YELLOW,
|
COLOR_YELLOW,
|
||||||
RESET_FORMAT,
|
RESET_FORMAT,
|
||||||
)
|
)
|
||||||
from core.instance_type import InstanceType
|
|
||||||
from core.menus.base_menu import print_back_footer
|
from core.menus.base_menu import print_back_footer
|
||||||
|
from utils.instance_type import InstanceType
|
||||||
|
|
||||||
|
|
||||||
@unique
|
@unique
|
||||||
|
|||||||
@@ -30,9 +30,10 @@ def find_firmware_file() -> bool:
|
|||||||
f1 = "klipper.elf.hex"
|
f1 = "klipper.elf.hex"
|
||||||
f2 = "klipper.elf"
|
f2 = "klipper.elf"
|
||||||
f3 = "klipper.bin"
|
f3 = "klipper.bin"
|
||||||
|
f4 = "klipper.uf2"
|
||||||
fw_file_exists: bool = (
|
fw_file_exists: bool = (
|
||||||
target.joinpath(f1).exists() and target.joinpath(f2).exists()
|
target.joinpath(f1).exists() and target.joinpath(f2).exists()
|
||||||
) or target.joinpath(f3).exists()
|
) or target.joinpath(f3).exists() or target.joinpath(f4).exists()
|
||||||
|
|
||||||
return target_exists and fw_file_exists
|
return target_exists and fw_file_exists
|
||||||
|
|
||||||
|
|||||||
@@ -103,8 +103,8 @@ def patch_klipperscreen_update_manager(instances: List[Moonraker]) -> None:
|
|||||||
options=[
|
options=[
|
||||||
("type", "git_repo"),
|
("type", "git_repo"),
|
||||||
("path", KLIPPERSCREEN_DIR.as_posix()),
|
("path", KLIPPERSCREEN_DIR.as_posix()),
|
||||||
("orgin", KLIPPERSCREEN_REPO),
|
("origin", KLIPPERSCREEN_REPO),
|
||||||
("manages_servcies", "KlipperScreen"),
|
("managed_services", "KlipperScreen"),
|
||||||
("env", f"{KLIPPERSCREEN_ENV_DIR}/bin/python"),
|
("env", f"{KLIPPERSCREEN_ENV_DIR}/bin/python"),
|
||||||
("requirements", KLIPPERSCREEN_REQ_FILE.as_posix()),
|
("requirements", KLIPPERSCREEN_REQ_FILE.as_posix()),
|
||||||
("install_script", KLIPPERSCREEN_INSTALL_SCRIPT.as_posix()),
|
("install_script", KLIPPERSCREEN_INSTALL_SCRIPT.as_posix()),
|
||||||
|
|||||||
@@ -1,201 +0,0 @@
|
|||||||
# ======================================================================= #
|
|
||||||
# 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 CalledProcessError, run
|
|
||||||
from typing import List
|
|
||||||
|
|
||||||
from components.klipper.klipper import Klipper
|
|
||||||
from components.mobileraker import (
|
|
||||||
MOBILERAKER_BACKUP_DIR,
|
|
||||||
MOBILERAKER_DIR,
|
|
||||||
MOBILERAKER_ENV_DIR,
|
|
||||||
MOBILERAKER_INSTALL_SCRIPT,
|
|
||||||
MOBILERAKER_LOG_NAME,
|
|
||||||
MOBILERAKER_REPO,
|
|
||||||
MOBILERAKER_REQ_FILE,
|
|
||||||
MOBILERAKER_SERVICE_FILE,
|
|
||||||
MOBILERAKER_SERVICE_NAME,
|
|
||||||
MOBILERAKER_UPDATER_SECTION_NAME,
|
|
||||||
)
|
|
||||||
from components.moonraker.moonraker import Moonraker
|
|
||||||
from core.backup_manager.backup_manager import BackupManager
|
|
||||||
from core.instance_manager.instance_manager import InstanceManager
|
|
||||||
from core.logger import DialogType, Logger
|
|
||||||
from core.settings.kiauh_settings import KiauhSettings
|
|
||||||
from core.types import ComponentStatus
|
|
||||||
from utils.common import check_install_dependencies, get_install_status
|
|
||||||
from utils.config_utils import add_config_section, remove_config_section
|
|
||||||
from utils.git_utils import (
|
|
||||||
git_clone_wrapper,
|
|
||||||
git_pull_wrapper,
|
|
||||||
)
|
|
||||||
from utils.input_utils import get_confirm
|
|
||||||
from utils.instance_utils import get_instances
|
|
||||||
from utils.sys_utils import (
|
|
||||||
check_python_version,
|
|
||||||
cmd_sysctl_service,
|
|
||||||
install_python_requirements,
|
|
||||||
remove_system_service,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def install_mobileraker() -> None:
|
|
||||||
Logger.print_status("Installing Mobileraker's companion ...")
|
|
||||||
|
|
||||||
if not check_python_version(3, 7):
|
|
||||||
return
|
|
||||||
|
|
||||||
mr_instances = get_instances(Moonraker)
|
|
||||||
if not mr_instances:
|
|
||||||
Logger.print_dialog(
|
|
||||||
DialogType.WARNING,
|
|
||||||
[
|
|
||||||
"Moonraker not found! Mobileraker's companion will not properly work "
|
|
||||||
"without a working Moonraker installation.",
|
|
||||||
"Mobileraker's companion's update manager configuration for Moonraker "
|
|
||||||
"will not be added to any moonraker.conf.",
|
|
||||||
],
|
|
||||||
)
|
|
||||||
if not get_confirm(
|
|
||||||
"Continue Mobileraker's companion installation?",
|
|
||||||
default_choice=False,
|
|
||||||
allow_go_back=True,
|
|
||||||
):
|
|
||||||
return
|
|
||||||
|
|
||||||
check_install_dependencies()
|
|
||||||
|
|
||||||
git_clone_wrapper(MOBILERAKER_REPO, MOBILERAKER_DIR)
|
|
||||||
|
|
||||||
try:
|
|
||||||
run(MOBILERAKER_INSTALL_SCRIPT.as_posix(), shell=True, check=True)
|
|
||||||
if mr_instances:
|
|
||||||
patch_mobileraker_update_manager(mr_instances)
|
|
||||||
InstanceManager.restart_all(mr_instances)
|
|
||||||
else:
|
|
||||||
Logger.print_info(
|
|
||||||
"Moonraker is not installed! Cannot add Mobileraker's "
|
|
||||||
"companion to update manager!"
|
|
||||||
)
|
|
||||||
Logger.print_ok("Mobileraker's companion successfully installed!")
|
|
||||||
except CalledProcessError as e:
|
|
||||||
Logger.print_error(f"Error installing Mobileraker's companion:\n{e}")
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
def patch_mobileraker_update_manager(instances: List[Moonraker]) -> None:
|
|
||||||
add_config_section(
|
|
||||||
section=MOBILERAKER_UPDATER_SECTION_NAME,
|
|
||||||
instances=instances,
|
|
||||||
options=[
|
|
||||||
("type", "git_repo"),
|
|
||||||
("path", MOBILERAKER_DIR.as_posix()),
|
|
||||||
("origin", MOBILERAKER_REPO),
|
|
||||||
("primary_branch", "main"),
|
|
||||||
("managed_services", "mobileraker"),
|
|
||||||
("env", f"{MOBILERAKER_ENV_DIR}/bin/python"),
|
|
||||||
("requirements", MOBILERAKER_REQ_FILE.as_posix()),
|
|
||||||
("install_script", MOBILERAKER_INSTALL_SCRIPT.as_posix()),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def update_mobileraker() -> None:
|
|
||||||
try:
|
|
||||||
if not MOBILERAKER_DIR.exists():
|
|
||||||
Logger.print_info(
|
|
||||||
"Mobileraker's companion does not seem to be installed! Skipping ..."
|
|
||||||
)
|
|
||||||
return
|
|
||||||
|
|
||||||
Logger.print_status("Updating Mobileraker's companion ...")
|
|
||||||
|
|
||||||
cmd_sysctl_service(MOBILERAKER_SERVICE_NAME, "stop")
|
|
||||||
|
|
||||||
settings = KiauhSettings()
|
|
||||||
if settings.kiauh.backup_before_update:
|
|
||||||
backup_mobileraker_dir()
|
|
||||||
|
|
||||||
git_pull_wrapper(MOBILERAKER_REPO, MOBILERAKER_DIR)
|
|
||||||
|
|
||||||
install_python_requirements(MOBILERAKER_ENV_DIR, MOBILERAKER_REQ_FILE)
|
|
||||||
|
|
||||||
cmd_sysctl_service(MOBILERAKER_SERVICE_NAME, "start")
|
|
||||||
|
|
||||||
Logger.print_ok("Mobileraker's companion updated successfully.", end="\n\n")
|
|
||||||
except CalledProcessError as e:
|
|
||||||
Logger.print_error(f"Error updating Mobileraker's companion:\n{e}")
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
def get_mobileraker_status() -> ComponentStatus:
|
|
||||||
return get_install_status(
|
|
||||||
MOBILERAKER_DIR,
|
|
||||||
MOBILERAKER_ENV_DIR,
|
|
||||||
files=[MOBILERAKER_SERVICE_FILE],
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def remove_mobileraker() -> None:
|
|
||||||
Logger.print_status("Removing Mobileraker's companion ...")
|
|
||||||
try:
|
|
||||||
if MOBILERAKER_DIR.exists():
|
|
||||||
Logger.print_status("Removing Mobileraker's companion directory ...")
|
|
||||||
shutil.rmtree(MOBILERAKER_DIR)
|
|
||||||
Logger.print_ok("Mobileraker's companion directory successfully removed!")
|
|
||||||
else:
|
|
||||||
Logger.print_warn("Mobileraker's companion directory not found!")
|
|
||||||
|
|
||||||
if MOBILERAKER_ENV_DIR.exists():
|
|
||||||
Logger.print_status("Removing Mobileraker's companion environment ...")
|
|
||||||
shutil.rmtree(MOBILERAKER_ENV_DIR)
|
|
||||||
Logger.print_ok("Mobileraker's companion environment successfully removed!")
|
|
||||||
else:
|
|
||||||
Logger.print_warn("Mobileraker's companion environment not found!")
|
|
||||||
|
|
||||||
if MOBILERAKER_SERVICE_FILE.exists():
|
|
||||||
remove_system_service(MOBILERAKER_SERVICE_NAME)
|
|
||||||
|
|
||||||
kl_instances: List[Klipper] = get_instances(Klipper)
|
|
||||||
for instance in kl_instances:
|
|
||||||
logfile = instance.base.log_dir.joinpath(MOBILERAKER_LOG_NAME)
|
|
||||||
if logfile.exists():
|
|
||||||
Logger.print_status(f"Removing {logfile} ...")
|
|
||||||
Path(logfile).unlink()
|
|
||||||
Logger.print_ok(f"{logfile} successfully removed!")
|
|
||||||
|
|
||||||
mr_instances: List[Moonraker] = get_instances(Moonraker)
|
|
||||||
if mr_instances:
|
|
||||||
Logger.print_status(
|
|
||||||
"Removing Mobileraker's companion from update manager ..."
|
|
||||||
)
|
|
||||||
remove_config_section(MOBILERAKER_UPDATER_SECTION_NAME, mr_instances)
|
|
||||||
Logger.print_ok(
|
|
||||||
"Mobileraker's companion successfully removed from update manager!"
|
|
||||||
)
|
|
||||||
|
|
||||||
Logger.print_ok("Mobileraker's companion successfully removed!")
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
Logger.print_error(f"Error removing Mobileraker's companion:\n{e}")
|
|
||||||
|
|
||||||
|
|
||||||
def backup_mobileraker_dir() -> None:
|
|
||||||
bm = BackupManager()
|
|
||||||
bm.backup_directory(
|
|
||||||
MOBILERAKER_DIR.name,
|
|
||||||
source=MOBILERAKER_DIR,
|
|
||||||
target=MOBILERAKER_BACKUP_DIR,
|
|
||||||
)
|
|
||||||
bm.backup_directory(
|
|
||||||
MOBILERAKER_ENV_DIR.name,
|
|
||||||
source=MOBILERAKER_ENV_DIR,
|
|
||||||
target=MOBILERAKER_BACKUP_DIR,
|
|
||||||
)
|
|
||||||
@@ -1,197 +0,0 @@
|
|||||||
# ======================================================================= #
|
|
||||||
# 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 json
|
|
||||||
from typing import List
|
|
||||||
|
|
||||||
from components.moonraker.moonraker import Moonraker
|
|
||||||
from components.octoeverywhere import (
|
|
||||||
OE_DEPS_JSON_FILE,
|
|
||||||
OE_DIR,
|
|
||||||
OE_ENV_DIR,
|
|
||||||
OE_INSTALL_SCRIPT,
|
|
||||||
OE_INSTALLER_LOG_FILE,
|
|
||||||
OE_REPO,
|
|
||||||
OE_REQ_FILE,
|
|
||||||
OE_SYS_CFG_NAME,
|
|
||||||
)
|
|
||||||
from components.octoeverywhere.octoeverywhere import Octoeverywhere
|
|
||||||
from core.instance_manager.instance_manager import InstanceManager
|
|
||||||
from core.logger import DialogType, Logger
|
|
||||||
from core.types import ComponentStatus
|
|
||||||
from utils.common import (
|
|
||||||
check_install_dependencies,
|
|
||||||
get_install_status,
|
|
||||||
moonraker_exists,
|
|
||||||
)
|
|
||||||
from utils.config_utils import (
|
|
||||||
remove_config_section,
|
|
||||||
)
|
|
||||||
from utils.fs_utils import run_remove_routines
|
|
||||||
from utils.git_utils import git_clone_wrapper
|
|
||||||
from utils.input_utils import get_confirm
|
|
||||||
from utils.instance_utils import get_instances
|
|
||||||
from utils.sys_utils import (
|
|
||||||
install_python_requirements,
|
|
||||||
parse_packages_from_file,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def get_octoeverywhere_status() -> ComponentStatus:
|
|
||||||
return get_install_status(OE_DIR, OE_ENV_DIR, Octoeverywhere)
|
|
||||||
|
|
||||||
|
|
||||||
def install_octoeverywhere() -> None:
|
|
||||||
Logger.print_status("Installing OctoEverywhere for Klipper ...")
|
|
||||||
|
|
||||||
# check if moonraker is installed. if not, notify the user and exit
|
|
||||||
if not moonraker_exists():
|
|
||||||
return
|
|
||||||
|
|
||||||
force_clone = False
|
|
||||||
oe_instances: List[Octoeverywhere] = get_instances(Octoeverywhere)
|
|
||||||
if oe_instances:
|
|
||||||
Logger.print_dialog(
|
|
||||||
DialogType.INFO,
|
|
||||||
[
|
|
||||||
"OctoEverywhere is already installed!",
|
|
||||||
"It is safe to run the installer again to link your "
|
|
||||||
"printer or repair any issues.",
|
|
||||||
],
|
|
||||||
)
|
|
||||||
if not get_confirm("Re-run OctoEverywhere installation?"):
|
|
||||||
Logger.print_info("Exiting OctoEverywhere for Klipper installation ...")
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
Logger.print_status("Re-Installing OctoEverywhere for Klipper ...")
|
|
||||||
force_clone = True
|
|
||||||
|
|
||||||
mr_instances: List[Moonraker] = get_instances(Moonraker)
|
|
||||||
|
|
||||||
mr_names = [f"● {moonraker.data_dir.name}" for moonraker in mr_instances]
|
|
||||||
if len(mr_names) > 1:
|
|
||||||
Logger.print_dialog(
|
|
||||||
DialogType.INFO,
|
|
||||||
[
|
|
||||||
"The following Moonraker instances were found:",
|
|
||||||
*mr_names,
|
|
||||||
"\n\n",
|
|
||||||
"The setup will apply the same names to OctoEverywhere!",
|
|
||||||
],
|
|
||||||
)
|
|
||||||
|
|
||||||
if not get_confirm(
|
|
||||||
"Continue OctoEverywhere for Klipper installation?",
|
|
||||||
default_choice=True,
|
|
||||||
allow_go_back=True,
|
|
||||||
):
|
|
||||||
Logger.print_info("Exiting OctoEverywhere for Klipper installation ...")
|
|
||||||
return
|
|
||||||
|
|
||||||
try:
|
|
||||||
git_clone_wrapper(OE_REPO, OE_DIR, force=force_clone)
|
|
||||||
|
|
||||||
for moonraker in mr_instances:
|
|
||||||
instance = Octoeverywhere(suffix=moonraker.suffix)
|
|
||||||
instance.create()
|
|
||||||
|
|
||||||
InstanceManager.restart_all(mr_instances)
|
|
||||||
|
|
||||||
Logger.print_dialog(
|
|
||||||
DialogType.SUCCESS,
|
|
||||||
["OctoEverywhere for Klipper successfully installed!"],
|
|
||||||
center_content=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
Logger.print_error(
|
|
||||||
f"Error during OctoEverywhere for Klipper installation:\n{e}"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def update_octoeverywhere() -> None:
|
|
||||||
Logger.print_status("Updating OctoEverywhere for Klipper ...")
|
|
||||||
try:
|
|
||||||
Octoeverywhere.update()
|
|
||||||
Logger.print_dialog(
|
|
||||||
DialogType.SUCCESS,
|
|
||||||
["OctoEverywhere for Klipper successfully updated!"],
|
|
||||||
center_content=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
Logger.print_error(f"Error during OctoEverywhere for Klipper update:\n{e}")
|
|
||||||
|
|
||||||
|
|
||||||
def remove_octoeverywhere() -> None:
|
|
||||||
Logger.print_status("Removing OctoEverywhere for Klipper ...")
|
|
||||||
|
|
||||||
mr_instances: List[Moonraker] = get_instances(Moonraker)
|
|
||||||
ob_instances: List[Octoeverywhere] = get_instances(Octoeverywhere)
|
|
||||||
|
|
||||||
try:
|
|
||||||
remove_oe_instances(ob_instances)
|
|
||||||
remove_oe_dir()
|
|
||||||
remove_oe_env()
|
|
||||||
remove_config_section(f"include {OE_SYS_CFG_NAME}", mr_instances)
|
|
||||||
run_remove_routines(OE_INSTALLER_LOG_FILE)
|
|
||||||
Logger.print_dialog(
|
|
||||||
DialogType.SUCCESS,
|
|
||||||
["OctoEverywhere for Klipper successfully removed!"],
|
|
||||||
center_content=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
Logger.print_error(f"Error during OctoEverywhere for Klipper removal:\n{e}")
|
|
||||||
|
|
||||||
|
|
||||||
def install_oe_dependencies() -> None:
|
|
||||||
oe_deps = []
|
|
||||||
if OE_DEPS_JSON_FILE.exists():
|
|
||||||
with open(OE_DEPS_JSON_FILE, "r") as deps:
|
|
||||||
oe_deps = json.load(deps).get("debian", [])
|
|
||||||
elif OE_INSTALL_SCRIPT.exists():
|
|
||||||
oe_deps = parse_packages_from_file(OE_INSTALL_SCRIPT)
|
|
||||||
|
|
||||||
if not oe_deps:
|
|
||||||
raise ValueError("Error reading OctoEverywhere dependencies!")
|
|
||||||
|
|
||||||
check_install_dependencies({*oe_deps})
|
|
||||||
install_python_requirements(OE_ENV_DIR, OE_REQ_FILE)
|
|
||||||
|
|
||||||
|
|
||||||
def remove_oe_instances(
|
|
||||||
instance_list: List[Octoeverywhere],
|
|
||||||
) -> None:
|
|
||||||
if not instance_list:
|
|
||||||
Logger.print_info("No OctoEverywhere instances found. Skipped ...")
|
|
||||||
return
|
|
||||||
|
|
||||||
for instance in instance_list:
|
|
||||||
Logger.print_status(f"Removing instance {instance.service_file_path.stem} ...")
|
|
||||||
InstanceManager.remove(instance)
|
|
||||||
|
|
||||||
|
|
||||||
def remove_oe_dir() -> None:
|
|
||||||
Logger.print_status("Removing OctoEverywhere for Klipper directory ...")
|
|
||||||
|
|
||||||
if not OE_DIR.exists():
|
|
||||||
Logger.print_info(f"'{OE_DIR}' does not exist. Skipped ...")
|
|
||||||
return
|
|
||||||
|
|
||||||
run_remove_routines(OE_DIR)
|
|
||||||
|
|
||||||
|
|
||||||
def remove_oe_env() -> None:
|
|
||||||
Logger.print_status("Removing OctoEverywhere for Klipper environment ...")
|
|
||||||
|
|
||||||
if not OE_ENV_DIR.exists():
|
|
||||||
Logger.print_info(f"'{OE_ENV_DIR}' does not exist. Skipped ...")
|
|
||||||
return
|
|
||||||
|
|
||||||
run_remove_routines(OE_ENV_DIR)
|
|
||||||
@@ -17,6 +17,10 @@ from core.logger import Logger
|
|||||||
from utils.common import get_current_date
|
from utils.common import get_current_date
|
||||||
|
|
||||||
|
|
||||||
|
class BackupManagerException(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
# noinspection PyUnusedLocal
|
# noinspection PyUnusedLocal
|
||||||
# noinspection PyMethodMayBeStatic
|
# noinspection PyMethodMayBeStatic
|
||||||
class BackupManager:
|
class BackupManager:
|
||||||
@@ -65,7 +69,7 @@ class BackupManager:
|
|||||||
|
|
||||||
def backup_directory(
|
def backup_directory(
|
||||||
self, name: str, source: Path, target: Path | None = None
|
self, name: str, source: Path, target: Path | None = None
|
||||||
) -> None:
|
) -> Path | None:
|
||||||
Logger.print_status(f"Creating backup of {name} in {target} ...")
|
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():
|
||||||
@@ -76,15 +80,15 @@ class BackupManager:
|
|||||||
try:
|
try:
|
||||||
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(
|
backup_target = target.joinpath(f"{name.lower()}-{date}-{time}")
|
||||||
source,
|
shutil.copytree(source, backup_target, ignore=self.ignore_folders_func)
|
||||||
target.joinpath(f"{name.lower()}-{date}-{time}"),
|
|
||||||
ignore=self.ignore_folders_func,
|
|
||||||
)
|
|
||||||
Logger.print_ok("Backup successful!")
|
Logger.print_ok("Backup successful!")
|
||||||
|
|
||||||
|
return backup_target
|
||||||
|
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
Logger.print_error(f"Unable to backup directory '{source}':\n{e}")
|
Logger.print_error(f"Unable to backup directory '{source}':\n{e}")
|
||||||
return
|
raise BackupManagerException(f"Unable to backup directory '{source}':\n{e}")
|
||||||
|
|
||||||
def ignore_folders_func(self, dirpath, filenames) -> List[str]:
|
def ignore_folders_func(self, dirpath, filenames) -> List[str]:
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ from pathlib import Path
|
|||||||
from subprocess import CalledProcessError
|
from subprocess import CalledProcessError
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from core.instance_type import InstanceType
|
|
||||||
from core.logger import Logger
|
from core.logger import Logger
|
||||||
|
from utils.instance_type import InstanceType
|
||||||
from utils.sys_utils import cmd_sysctl_service
|
from utils.sys_utils import cmd_sysctl_service
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -14,9 +14,7 @@ from typing import Type
|
|||||||
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.klipperscreen.klipperscreen import install_klipperscreen
|
||||||
from components.mobileraker.mobileraker import install_mobileraker
|
|
||||||
from components.moonraker import moonraker_setup
|
from components.moonraker import moonraker_setup
|
||||||
from components.octoeverywhere.octoeverywhere_setup import install_octoeverywhere
|
|
||||||
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
|
||||||
from components.webui_client.fluidd_data import FluiddData
|
from components.webui_client.fluidd_data import FluiddData
|
||||||
@@ -47,9 +45,7 @@ class InstallMenu(BaseMenu):
|
|||||||
"5": Option(method=self.install_mainsail_config),
|
"5": Option(method=self.install_mainsail_config),
|
||||||
"6": Option(method=self.install_fluidd_config),
|
"6": Option(method=self.install_fluidd_config),
|
||||||
"7": Option(method=self.install_klipperscreen),
|
"7": Option(method=self.install_klipperscreen),
|
||||||
"8": Option(method=self.install_mobileraker),
|
"8": Option(method=self.install_crowsnest),
|
||||||
"9": Option(method=self.install_crowsnest),
|
|
||||||
"10": Option(method=self.install_octoeverywhere),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def print_menu(self) -> None:
|
def print_menu(self) -> None:
|
||||||
@@ -64,15 +60,14 @@ class InstallMenu(BaseMenu):
|
|||||||
║ Firmware & API: │ Touchscreen GUI: ║
|
║ Firmware & API: │ Touchscreen GUI: ║
|
||||||
║ 1) [Klipper] │ 7) [KlipperScreen] ║
|
║ 1) [Klipper] │ 7) [KlipperScreen] ║
|
||||||
║ 2) [Moonraker] │ ║
|
║ 2) [Moonraker] │ ║
|
||||||
║ │ Android / iOS: ║
|
║ │ Webcam Streamer: ║
|
||||||
║ Webinterface: │ 8) [Mobileraker] ║
|
║ Webinterface: │ 8) [Crowsnest] ║
|
||||||
║ 3) [Mainsail] │ ║
|
║ 3) [Mainsail] │ ║
|
||||||
║ 4) [Fluidd] │ Webcam Streamer: ║
|
║ 4) [Fluidd] │ ║
|
||||||
║ │ 9) [Crowsnest] ║
|
|
||||||
║ Client-Config: │ ║
|
|
||||||
║ 5) [Mainsail-Config] │ Remote Access: ║
|
|
||||||
║ 6) [Fluidd-Config] │ 10) [OctoEverywhere] ║
|
|
||||||
║ │ ║
|
║ │ ║
|
||||||
|
║ Client-Config: │ ║
|
||||||
|
║ 5) [Mainsail-Config] │ ║
|
||||||
|
║ 6) [Fluidd-Config] │ ║
|
||||||
╟───────────────────────────┴───────────────────────────╢
|
╟───────────────────────────┴───────────────────────────╢
|
||||||
"""
|
"""
|
||||||
)[1:]
|
)[1:]
|
||||||
@@ -99,11 +94,5 @@ class InstallMenu(BaseMenu):
|
|||||||
def install_klipperscreen(self, **kwargs) -> None:
|
def install_klipperscreen(self, **kwargs) -> None:
|
||||||
install_klipperscreen()
|
install_klipperscreen()
|
||||||
|
|
||||||
def install_mobileraker(self, **kwargs) -> None:
|
|
||||||
install_mobileraker()
|
|
||||||
|
|
||||||
def install_crowsnest(self, **kwargs) -> None:
|
def install_crowsnest(self, **kwargs) -> None:
|
||||||
install_crowsnest()
|
install_crowsnest()
|
||||||
|
|
||||||
def install_octoeverywhere(self, **kwargs) -> None:
|
|
||||||
install_octoeverywhere()
|
|
||||||
|
|||||||
@@ -16,9 +16,7 @@ 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.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.mobileraker.mobileraker import get_mobileraker_status
|
|
||||||
from components.moonraker.moonraker_utils import get_moonraker_status
|
from components.moonraker.moonraker_utils import get_moonraker_status
|
||||||
from components.octoeverywhere.octoeverywhere_setup import get_octoeverywhere_status
|
|
||||||
from components.webui_client.client_utils import (
|
from components.webui_client.client_utils import (
|
||||||
get_client_status,
|
get_client_status,
|
||||||
get_current_client_config,
|
get_current_client_config,
|
||||||
@@ -57,9 +55,10 @@ class MainMenu(BaseMenu):
|
|||||||
self.footer_type: FooterType = FooterType.QUIT
|
self.footer_type: FooterType = FooterType.QUIT
|
||||||
|
|
||||||
self.version = ""
|
self.version = ""
|
||||||
self.kl_status = self.kl_repo = self.mr_status = self.mr_repo = ""
|
self.kl_status = self.kl_owner = self.kl_repo = ""
|
||||||
self.ms_status = self.fl_status = self.ks_status = self.mb_status = ""
|
self.mr_status = self.mr_owner = self.mr_repo = ""
|
||||||
self.cn_status = self.cc_status = self.oe_status = ""
|
self.ms_status = self.fl_status = self.ks_status = ""
|
||||||
|
self.cn_status = self.cc_status = ""
|
||||||
self._init_status()
|
self._init_status()
|
||||||
|
|
||||||
def set_previous_menu(self, previous_menu: Type[BaseMenu] | None) -> None:
|
def set_previous_menu(self, previous_menu: Type[BaseMenu] | None) -> None:
|
||||||
@@ -79,7 +78,7 @@ class MainMenu(BaseMenu):
|
|||||||
}
|
}
|
||||||
|
|
||||||
def _init_status(self) -> None:
|
def _init_status(self) -> None:
|
||||||
status_vars = ["kl", "mr", "ms", "fl", "ks", "mb", "cn", "oe"]
|
status_vars = ["kl", "mr", "ms", "fl", "ks", "cn"]
|
||||||
for var in status_vars:
|
for var in status_vars:
|
||||||
setattr(
|
setattr(
|
||||||
self,
|
self,
|
||||||
@@ -95,14 +94,13 @@ class MainMenu(BaseMenu):
|
|||||||
self._get_component_status("fl", get_client_status, FluiddData())
|
self._get_component_status("fl", get_client_status, FluiddData())
|
||||||
self.cc_status = get_current_client_config([MainsailData(), FluiddData()])
|
self.cc_status = get_current_client_config([MainsailData(), FluiddData()])
|
||||||
self._get_component_status("ks", get_klipperscreen_status)
|
self._get_component_status("ks", get_klipperscreen_status)
|
||||||
self._get_component_status("mb", get_mobileraker_status)
|
|
||||||
self._get_component_status("cn", get_crowsnest_status)
|
self._get_component_status("cn", get_crowsnest_status)
|
||||||
self._get_component_status("oe", get_octoeverywhere_status)
|
|
||||||
|
|
||||||
def _get_component_status(self, name: str, status_fn: Callable, *args) -> None:
|
def _get_component_status(self, name: str, status_fn: Callable, *args) -> None:
|
||||||
status_data: ComponentStatus = status_fn(*args)
|
status_data: ComponentStatus = status_fn(*args)
|
||||||
code: int = status_data.status
|
code: int = status_data.status
|
||||||
status: StatusText = StatusMap[code]
|
status: StatusText = StatusMap[code]
|
||||||
|
owner: str = status_data.owner
|
||||||
repo: str = status_data.repo
|
repo: str = status_data.repo
|
||||||
instance_count: int = status_data.instances
|
instance_count: int = status_data.instances
|
||||||
|
|
||||||
@@ -111,6 +109,7 @@ class MainMenu(BaseMenu):
|
|||||||
count_txt = f": {instance_count}"
|
count_txt = f": {instance_count}"
|
||||||
|
|
||||||
setattr(self, f"{name}_status", self._format_by_code(code, status, count_txt))
|
setattr(self, f"{name}_status", self._format_by_code(code, status, count_txt))
|
||||||
|
setattr(self, f"{name}_owner", f"{COLOR_CYAN}{owner}{RESET_FORMAT}")
|
||||||
setattr(self, f"{name}_repo", f"{COLOR_CYAN}{repo}{RESET_FORMAT}")
|
setattr(self, f"{name}_repo", f"{COLOR_CYAN}{repo}{RESET_FORMAT}")
|
||||||
|
|
||||||
def _format_by_code(self, code: int, status: str, count: str) -> str:
|
def _format_by_code(self, code: int, status: str, count: str) -> str:
|
||||||
@@ -140,18 +139,18 @@ class MainMenu(BaseMenu):
|
|||||||
║ {color}{header:~^{count}}{RESET_FORMAT} ║
|
║ {color}{header:~^{count}}{RESET_FORMAT} ║
|
||||||
╟──────────────────┬────────────────────────────────────╢
|
╟──────────────────┬────────────────────────────────────╢
|
||||||
║ 0) [Log-Upload] │ Klipper: {self.kl_status:<{pad1}} ║
|
║ 0) [Log-Upload] │ Klipper: {self.kl_status:<{pad1}} ║
|
||||||
║ │ Repo: {self.kl_repo:<{pad1}} ║
|
║ │ Owner: {self.kl_owner:<{pad1}} ║
|
||||||
║ 1) [Install] ├────────────────────────────────────╢
|
║ 1) [Install] │ Repo: {self.kl_repo:<{pad1}} ║
|
||||||
║ 2) [Update] │ Moonraker: {self.mr_status:<{pad1}} ║
|
║ 2) [Update] ├────────────────────────────────────╢
|
||||||
║ 3) [Remove] │ Repo: {self.mr_repo:<{pad1}} ║
|
║ 3) [Remove] │ Moonraker: {self.mr_status:<{pad1}} ║
|
||||||
║ 4) [Advanced] ├────────────────────────────────────╢
|
║ 4) [Advanced] │ Owner: {self.mr_owner:<{pad1}} ║
|
||||||
║ 5) [Backup] │ Mainsail: {self.ms_status:<{pad2}} ║
|
║ 5) [Backup] │ Repo: {self.mr_repo:<{pad1}} ║
|
||||||
|
║ ├────────────────────────────────────╢
|
||||||
|
║ S) [Settings] │ Mainsail: {self.ms_status:<{pad2}} ║
|
||||||
║ │ Fluidd: {self.fl_status:<{pad2}} ║
|
║ │ Fluidd: {self.fl_status:<{pad2}} ║
|
||||||
║ S) [Settings] │ Client-Config: {self.cc_status:<{pad2}} ║
|
║ Community: │ Client-Config: {self.cc_status:<{pad2}} ║
|
||||||
║ │ ║
|
║ E) [Extensions] │ ║
|
||||||
║ Community: │ KlipperScreen: {self.ks_status:<{pad2}} ║
|
║ │ KlipperScreen: {self.ks_status:<{pad2}} ║
|
||||||
║ E) [Extensions] │ Mobileraker: {self.mb_status:<{pad2}} ║
|
|
||||||
║ │ OctoEverywhere: {self.oe_status:<{pad2}} ║
|
|
||||||
║ │ Crowsnest: {self.cn_status:<{pad2}} ║
|
║ │ Crowsnest: {self.cn_status:<{pad2}} ║
|
||||||
╟──────────────────┼────────────────────────────────────╢
|
╟──────────────────┼────────────────────────────────────╢
|
||||||
║ {footer1:^25} │ {footer2:^43} ║
|
║ {footer1:^25} │ {footer2:^43} ║
|
||||||
|
|||||||
@@ -14,11 +14,9 @@ from typing import Type
|
|||||||
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.klipperscreen.klipperscreen import remove_klipperscreen
|
||||||
from components.mobileraker.mobileraker import remove_mobileraker
|
|
||||||
from components.moonraker.menus.moonraker_remove_menu import (
|
from components.moonraker.menus.moonraker_remove_menu import (
|
||||||
MoonrakerRemoveMenu,
|
MoonrakerRemoveMenu,
|
||||||
)
|
)
|
||||||
from components.octoeverywhere.octoeverywhere_setup import remove_octoeverywhere
|
|
||||||
from components.webui_client.fluidd_data import FluiddData
|
from components.webui_client.fluidd_data import FluiddData
|
||||||
from components.webui_client.mainsail_data import MainsailData
|
from components.webui_client.mainsail_data import MainsailData
|
||||||
from components.webui_client.menus.client_remove_menu import ClientRemoveMenu
|
from components.webui_client.menus.client_remove_menu import ClientRemoveMenu
|
||||||
@@ -46,9 +44,8 @@ class RemoveMenu(BaseMenu):
|
|||||||
"3": Option(method=self.remove_mainsail),
|
"3": Option(method=self.remove_mainsail),
|
||||||
"4": Option(method=self.remove_fluidd),
|
"4": Option(method=self.remove_fluidd),
|
||||||
"5": Option(method=self.remove_klipperscreen),
|
"5": Option(method=self.remove_klipperscreen),
|
||||||
"6": Option(method=self.remove_mobileraker),
|
"6": Option(method=self.remove_crowsnest),
|
||||||
"7": Option(method=self.remove_crowsnest),
|
"7": Option(method=self.remove_octoeverywhere),
|
||||||
"8": Option(method=self.remove_octoeverywhere),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def print_menu(self) -> None:
|
def print_menu(self) -> None:
|
||||||
@@ -62,16 +59,13 @@ class RemoveMenu(BaseMenu):
|
|||||||
╟───────────────────────────────────────────────────────╢
|
╟───────────────────────────────────────────────────────╢
|
||||||
║ INFO: Configurations and/or any backups will be kept! ║
|
║ INFO: Configurations and/or any backups will be kept! ║
|
||||||
╟───────────────────────────┬───────────────────────────╢
|
╟───────────────────────────┬───────────────────────────╢
|
||||||
║ Firmware & API: │ Android / iOS: ║
|
║ Firmware & API: │ Touchscreen GUI: ║
|
||||||
║ 1) [Klipper] │ 6) [Mobileraker] ║
|
║ 1) [Klipper] │ 5) [KlipperScreen] ║
|
||||||
║ 2) [Moonraker] │ ║
|
║ 2) [Moonraker] │ ║
|
||||||
║ │ Webcam Streamer: ║
|
║ │ Webcam Streamer: ║
|
||||||
║ Klipper Webinterface: │ 7) [Crowsnest] ║
|
║ Klipper Webinterface: │ 6) [Crowsnest] ║
|
||||||
║ 3) [Mainsail] │ ║
|
║ 3) [Mainsail] │ ║
|
||||||
║ 4) [Fluidd] │ Remote Access: ║
|
║ 4) [Fluidd] │ ║
|
||||||
║ │ 8) [OctoEverywhere] ║
|
|
||||||
║ Touchscreen GUI: │ ║
|
|
||||||
║ 5) [KlipperScreen] │ ║
|
|
||||||
╟───────────────────────────┴───────────────────────────╢
|
╟───────────────────────────┴───────────────────────────╢
|
||||||
"""
|
"""
|
||||||
)[1:]
|
)[1:]
|
||||||
@@ -92,11 +86,5 @@ class RemoveMenu(BaseMenu):
|
|||||||
def remove_klipperscreen(self, **kwargs) -> None:
|
def remove_klipperscreen(self, **kwargs) -> None:
|
||||||
remove_klipperscreen()
|
remove_klipperscreen()
|
||||||
|
|
||||||
def remove_mobileraker(self, **kwargs) -> None:
|
|
||||||
remove_mobileraker()
|
|
||||||
|
|
||||||
def remove_crowsnest(self, **kwargs) -> None:
|
def remove_crowsnest(self, **kwargs) -> None:
|
||||||
remove_crowsnest()
|
remove_crowsnest()
|
||||||
|
|
||||||
def remove_octoeverywhere(self, **kwargs) -> None:
|
|
||||||
remove_octoeverywhere()
|
|
||||||
|
|||||||
@@ -8,24 +8,16 @@
|
|||||||
# ======================================================================= #
|
# ======================================================================= #
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import shutil
|
|
||||||
import textwrap
|
import textwrap
|
||||||
from pathlib import Path
|
from typing import Literal, Tuple, Type
|
||||||
from typing import Tuple, Type
|
|
||||||
|
|
||||||
from components.klipper import KLIPPER_DIR
|
|
||||||
from components.klipper.klipper import Klipper
|
|
||||||
from components.moonraker import MOONRAKER_DIR
|
|
||||||
from components.moonraker.moonraker import Moonraker
|
|
||||||
from core.constants import COLOR_CYAN, COLOR_GREEN, RESET_FORMAT
|
from core.constants import COLOR_CYAN, COLOR_GREEN, RESET_FORMAT
|
||||||
from core.instance_manager.instance_manager import InstanceManager
|
|
||||||
from core.logger import DialogType, Logger
|
from core.logger import DialogType, Logger
|
||||||
from core.menus import Option
|
from core.menus import Option
|
||||||
from core.menus.base_menu import BaseMenu
|
from core.menus.base_menu import BaseMenu
|
||||||
from core.settings.kiauh_settings import KiauhSettings
|
from core.settings.kiauh_settings import KiauhSettings, RepoSettings
|
||||||
from utils.git_utils import git_clone_wrapper
|
from procedures.switch_repo import run_switch_repo_routine
|
||||||
from utils.input_utils import get_confirm, get_string_input
|
from utils.input_utils import get_confirm, get_string_input
|
||||||
from utils.instance_utils import get_instances
|
|
||||||
|
|
||||||
|
|
||||||
# noinspection PyUnusedLocal
|
# noinspection PyUnusedLocal
|
||||||
@@ -105,22 +97,28 @@ class SettingsMenu(BaseMenu):
|
|||||||
self.mainsail_unstable = self.settings.mainsail.unstable_releases
|
self.mainsail_unstable = self.settings.mainsail.unstable_releases
|
||||||
self.fluidd_unstable = self.settings.fluidd.unstable_releases
|
self.fluidd_unstable = self.settings.fluidd.unstable_releases
|
||||||
|
|
||||||
def _format_repo_str(self, repo_name: str) -> None:
|
def _format_repo_str(self, repo_name: Literal["klipper", "moonraker"]) -> None:
|
||||||
repo = self.settings.get(repo_name, "repo_url")
|
repo: RepoSettings = self.settings[repo_name]
|
||||||
repo = f"{'/'.join(repo.rsplit('/', 2)[-2:])}"
|
repo_str = f"{'/'.join(repo.repo_url.rsplit('/', 2)[-2:])}"
|
||||||
branch = self.settings.get(repo_name, "branch")
|
branch_str = f"({COLOR_CYAN}@ {repo.branch}{RESET_FORMAT})"
|
||||||
branch = f"({COLOR_CYAN}@ {branch}{RESET_FORMAT})"
|
|
||||||
setattr(self, f"{repo_name}_repo", f"{COLOR_CYAN}{repo}{RESET_FORMAT} {branch}")
|
setattr(
|
||||||
|
self,
|
||||||
|
f"{repo_name}_repo",
|
||||||
|
f"{COLOR_CYAN}{repo_str}{RESET_FORMAT} {branch_str}",
|
||||||
|
)
|
||||||
|
|
||||||
def _gather_input(self) -> Tuple[str, str]:
|
def _gather_input(self) -> Tuple[str, str]:
|
||||||
Logger.print_dialog(
|
Logger.print_dialog(
|
||||||
DialogType.ATTENTION,
|
DialogType.ATTENTION,
|
||||||
[
|
[
|
||||||
"There is no input validation in place! Make sure your"
|
"There is no input validation in place! Make sure your the input is "
|
||||||
" input is valid and has no typos! For any change to"
|
"valid and has no typos or invalid characters! For the change to take "
|
||||||
" take effect, the repository must be cloned again. "
|
"effect, the new repository will be cloned. A backup of the old "
|
||||||
"Make sure you don't have any ongoing prints running, "
|
"repository will be created.",
|
||||||
"as the services will be restarted!"
|
"\n\n",
|
||||||
|
"Make sure you don't have any ongoing prints running, as the services "
|
||||||
|
"will be restarted during this process! You will loose any ongoing print!",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
repo = get_string_input(
|
repo = get_string_input(
|
||||||
@@ -134,7 +132,7 @@ class SettingsMenu(BaseMenu):
|
|||||||
|
|
||||||
return repo, branch
|
return repo, branch
|
||||||
|
|
||||||
def _set_repo(self, repo_name: str) -> None:
|
def _set_repo(self, repo_name: Literal["klipper", "moonraker"]) -> None:
|
||||||
repo_url, branch = self._gather_input()
|
repo_url, branch = self._gather_input()
|
||||||
display_name = repo_name.capitalize()
|
display_name = repo_name.capitalize()
|
||||||
Logger.print_dialog(
|
Logger.print_dialog(
|
||||||
@@ -148,10 +146,13 @@ class SettingsMenu(BaseMenu):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if get_confirm("Apply changes?", allow_go_back=True):
|
if get_confirm("Apply changes?", allow_go_back=True):
|
||||||
self.settings.set(repo_name, "repo_url", repo_url)
|
repo: RepoSettings = self.settings[repo_name]
|
||||||
self.settings.set(repo_name, "branch", branch)
|
repo.repo_url = repo_url
|
||||||
|
repo.branch = branch
|
||||||
|
|
||||||
self.settings.save()
|
self.settings.save()
|
||||||
self._load_settings()
|
self._load_settings()
|
||||||
|
|
||||||
Logger.print_ok("Changes saved!")
|
Logger.print_ok("Changes saved!")
|
||||||
else:
|
else:
|
||||||
Logger.print_info(
|
Logger.print_info(
|
||||||
@@ -161,31 +162,10 @@ class SettingsMenu(BaseMenu):
|
|||||||
|
|
||||||
Logger.print_status(f"Switching to {display_name}'s new source repository ...")
|
Logger.print_status(f"Switching to {display_name}'s new source repository ...")
|
||||||
self._switch_repo(repo_name)
|
self._switch_repo(repo_name)
|
||||||
Logger.print_ok(f"Switched to {repo_url} at branch {branch}!")
|
|
||||||
|
|
||||||
def _switch_repo(self, name: str) -> None:
|
def _switch_repo(self, name: Literal["klipper", "moonraker"]) -> None:
|
||||||
target_dir: Path
|
repo: RepoSettings = self.settings[name]
|
||||||
if name == "klipper":
|
run_switch_repo_routine(name, repo)
|
||||||
target_dir = KLIPPER_DIR
|
|
||||||
_type = Klipper
|
|
||||||
elif name == "moonraker":
|
|
||||||
target_dir = MOONRAKER_DIR
|
|
||||||
_type = Moonraker
|
|
||||||
else:
|
|
||||||
Logger.print_error("Invalid repository name!")
|
|
||||||
return
|
|
||||||
|
|
||||||
if target_dir.exists():
|
|
||||||
shutil.rmtree(target_dir)
|
|
||||||
|
|
||||||
instances = get_instances(_type)
|
|
||||||
InstanceManager.stop_all(instances)
|
|
||||||
|
|
||||||
repo = self.settings.get(name, "repo_url")
|
|
||||||
branch = self.settings.get(name, "branch")
|
|
||||||
git_clone_wrapper(repo, target_dir, branch)
|
|
||||||
|
|
||||||
InstanceManager.start_all(instances)
|
|
||||||
|
|
||||||
def set_klipper_repo(self, **kwargs) -> None:
|
def set_klipper_repo(self, **kwargs) -> None:
|
||||||
self._set_repo("klipper")
|
self._set_repo("klipper")
|
||||||
|
|||||||
@@ -20,16 +20,8 @@ from components.klipperscreen.klipperscreen import (
|
|||||||
get_klipperscreen_status,
|
get_klipperscreen_status,
|
||||||
update_klipperscreen,
|
update_klipperscreen,
|
||||||
)
|
)
|
||||||
from components.mobileraker.mobileraker import (
|
|
||||||
get_mobileraker_status,
|
|
||||||
update_mobileraker,
|
|
||||||
)
|
|
||||||
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.octoeverywhere.octoeverywhere_setup import (
|
|
||||||
get_octoeverywhere_status,
|
|
||||||
update_octoeverywhere,
|
|
||||||
)
|
|
||||||
from components.webui_client.client_config.client_config_setup import (
|
from components.webui_client.client_config.client_config_setup import (
|
||||||
update_client_config,
|
update_client_config,
|
||||||
)
|
)
|
||||||
@@ -76,9 +68,7 @@ class UpdateMenu(BaseMenu):
|
|||||||
self.fluidd_local = self.fluidd_remote = ""
|
self.fluidd_local = self.fluidd_remote = ""
|
||||||
self.fluidd_config_local = self.fluidd_config_remote = ""
|
self.fluidd_config_local = self.fluidd_config_remote = ""
|
||||||
self.klipperscreen_local = self.klipperscreen_remote = ""
|
self.klipperscreen_local = self.klipperscreen_remote = ""
|
||||||
self.mobileraker_local = self.mobileraker_remote = ""
|
|
||||||
self.crowsnest_local = self.crowsnest_remote = ""
|
self.crowsnest_local = self.crowsnest_remote = ""
|
||||||
self.octoeverywhere_local = self.octoeverywhere_remote = ""
|
|
||||||
|
|
||||||
self.mainsail_data = MainsailData()
|
self.mainsail_data = MainsailData()
|
||||||
self.fluidd_data = FluiddData()
|
self.fluidd_data = FluiddData()
|
||||||
@@ -89,10 +79,8 @@ class UpdateMenu(BaseMenu):
|
|||||||
"mainsail_config": {"installed": False, "local": None, "remote": None},
|
"mainsail_config": {"installed": False, "local": None, "remote": None},
|
||||||
"fluidd": {"installed": False, "local": None, "remote": None},
|
"fluidd": {"installed": False, "local": None, "remote": None},
|
||||||
"fluidd_config": {"installed": False, "local": None, "remote": None},
|
"fluidd_config": {"installed": False, "local": None, "remote": None},
|
||||||
"mobileraker": {"installed": False, "local": None, "remote": None},
|
|
||||||
"klipperscreen": {"installed": False, "local": None, "remote": None},
|
"klipperscreen": {"installed": False, "local": None, "remote": None},
|
||||||
"crowsnest": {"installed": False, "local": None, "remote": None},
|
"crowsnest": {"installed": False, "local": None, "remote": None},
|
||||||
"octoeverywhere": {"installed": False, "local": None, "remote": None},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def set_previous_menu(self, previous_menu: Type[BaseMenu] | None) -> None:
|
def set_previous_menu(self, previous_menu: Type[BaseMenu] | None) -> None:
|
||||||
@@ -110,10 +98,8 @@ class UpdateMenu(BaseMenu):
|
|||||||
"5": Option(self.update_mainsail_config),
|
"5": Option(self.update_mainsail_config),
|
||||||
"6": Option(self.update_fluidd_config),
|
"6": Option(self.update_fluidd_config),
|
||||||
"7": Option(self.update_klipperscreen),
|
"7": Option(self.update_klipperscreen),
|
||||||
"8": Option(self.update_mobileraker),
|
"8": Option(self.update_crowsnest),
|
||||||
"9": Option(self.update_crowsnest),
|
"9": Option(self.upgrade_system_packages),
|
||||||
"10": Option(self.update_octoeverywhere),
|
|
||||||
"11": Option(self.upgrade_system_packages),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def print_menu(self) -> None:
|
def print_menu(self) -> None:
|
||||||
@@ -157,11 +143,9 @@ class UpdateMenu(BaseMenu):
|
|||||||
║ │ │ ║
|
║ │ │ ║
|
||||||
║ Other: ├───────────────┼───────────────╢
|
║ Other: ├───────────────┼───────────────╢
|
||||||
║ 7) KlipperScreen │ {self.klipperscreen_local:<22} │ {self.klipperscreen_remote:<22} ║
|
║ 7) KlipperScreen │ {self.klipperscreen_local:<22} │ {self.klipperscreen_remote:<22} ║
|
||||||
║ 8) Mobileraker │ {self.mobileraker_local:<22} │ {self.mobileraker_remote:<22} ║
|
║ 8) Crowsnest │ {self.crowsnest_local:<22} │ {self.crowsnest_remote:<22} ║
|
||||||
║ 9) Crowsnest │ {self.crowsnest_local:<22} │ {self.crowsnest_remote:<22} ║
|
|
||||||
║ 10) OctoEverywhere │ {self.octoeverywhere_local:<22} │ {self.octoeverywhere_remote:<22} ║
|
|
||||||
║ ├───────────────┴───────────────╢
|
║ ├───────────────┴───────────────╢
|
||||||
║ 11) System │ {sysupgrades:^{padding}} ║
|
║ 9) System │ {sysupgrades:^{padding}} ║
|
||||||
╟───────────────────────┴───────────────────────────────╢
|
╟───────────────────────┴───────────────────────────────╢
|
||||||
"""
|
"""
|
||||||
)[1:]
|
)[1:]
|
||||||
@@ -198,18 +182,10 @@ class UpdateMenu(BaseMenu):
|
|||||||
if self._check_is_installed("klipperscreen"):
|
if self._check_is_installed("klipperscreen"):
|
||||||
update_klipperscreen()
|
update_klipperscreen()
|
||||||
|
|
||||||
def update_mobileraker(self, **kwargs) -> None:
|
|
||||||
if self._check_is_installed("mobileraker"):
|
|
||||||
update_mobileraker()
|
|
||||||
|
|
||||||
def update_crowsnest(self, **kwargs) -> None:
|
def update_crowsnest(self, **kwargs) -> None:
|
||||||
if self._check_is_installed("crowsnest"):
|
if self._check_is_installed("crowsnest"):
|
||||||
update_crowsnest()
|
update_crowsnest()
|
||||||
|
|
||||||
def update_octoeverywhere(self, **kwargs) -> None:
|
|
||||||
if self._check_is_installed("octoeverywhere"):
|
|
||||||
update_octoeverywhere()
|
|
||||||
|
|
||||||
def upgrade_system_packages(self, **kwargs) -> None:
|
def upgrade_system_packages(self, **kwargs) -> None:
|
||||||
self._run_system_updates()
|
self._run_system_updates()
|
||||||
|
|
||||||
@@ -225,9 +201,7 @@ class UpdateMenu(BaseMenu):
|
|||||||
"fluidd_config", get_client_config_status, self.fluidd_data
|
"fluidd_config", get_client_config_status, self.fluidd_data
|
||||||
)
|
)
|
||||||
self._set_status_data("klipperscreen", get_klipperscreen_status)
|
self._set_status_data("klipperscreen", get_klipperscreen_status)
|
||||||
self._set_status_data("mobileraker", get_mobileraker_status)
|
|
||||||
self._set_status_data("crowsnest", get_crowsnest_status)
|
self._set_status_data("crowsnest", get_crowsnest_status)
|
||||||
self._set_status_data("octoeverywhere", get_octoeverywhere_status)
|
|
||||||
|
|
||||||
update_system_package_lists(silent=True)
|
update_system_package_lists(silent=True)
|
||||||
self.packages = get_upgradable_packages()
|
self.packages = get_upgradable_packages()
|
||||||
|
|||||||
@@ -8,6 +8,9 @@
|
|||||||
# ======================================================================= #
|
# ======================================================================= #
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from dataclasses import dataclass, field
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from core.logger import DialogType, Logger
|
from core.logger import DialogType, Logger
|
||||||
from core.submodules.simple_config_parser.src.simple_config_parser.simple_config_parser import (
|
from core.submodules.simple_config_parser.src.simple_config_parser.simple_config_parser import (
|
||||||
NoOptionError,
|
NoOptionError,
|
||||||
@@ -22,33 +25,21 @@ DEFAULT_CFG = PROJECT_ROOT.joinpath("default.kiauh.cfg")
|
|||||||
CUSTOM_CFG = PROJECT_ROOT.joinpath("kiauh.cfg")
|
CUSTOM_CFG = PROJECT_ROOT.joinpath("kiauh.cfg")
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
class AppSettings:
|
class AppSettings:
|
||||||
def __init__(self) -> None:
|
backup_before_update: bool | None = field(default=None)
|
||||||
self.backup_before_update = None
|
|
||||||
|
|
||||||
|
|
||||||
class KlipperSettings:
|
@dataclass
|
||||||
def __init__(self) -> None:
|
class RepoSettings:
|
||||||
self.repo_url = None
|
repo_url: str | None = field(default=None)
|
||||||
self.branch = None
|
branch: str | None = field(default=None)
|
||||||
|
|
||||||
|
|
||||||
class MoonrakerSettings:
|
@dataclass
|
||||||
def __init__(self) -> None:
|
class WebUiSettings:
|
||||||
self.repo_url = None
|
port: str | None = field(default=None)
|
||||||
self.branch = None
|
unstable_releases: bool | None = field(default=None)
|
||||||
|
|
||||||
|
|
||||||
class MainsailSettings:
|
|
||||||
def __init__(self) -> None:
|
|
||||||
self.port = None
|
|
||||||
self.unstable_releases = None
|
|
||||||
|
|
||||||
|
|
||||||
class FluiddSettings:
|
|
||||||
def __init__(self) -> None:
|
|
||||||
self.port = None
|
|
||||||
self.unstable_releases = None
|
|
||||||
|
|
||||||
|
|
||||||
# noinspection PyUnusedLocal
|
# noinspection PyUnusedLocal
|
||||||
@@ -61,6 +52,12 @@ class KiauhSettings:
|
|||||||
cls._instance = super(KiauhSettings, cls).__new__(cls, *args, **kwargs)
|
cls._instance = super(KiauhSettings, cls).__new__(cls, *args, **kwargs)
|
||||||
return cls._instance
|
return cls._instance
|
||||||
|
|
||||||
|
def __repr__(self) -> str:
|
||||||
|
return f"KiauhSettings(kiauh={self.kiauh}, klipper={self.klipper}, moonraker={self.moonraker}, mainsail={self.mainsail}, fluidd={self.fluidd})"
|
||||||
|
|
||||||
|
def __getitem__(self, item: str) -> Any:
|
||||||
|
return getattr(self, item)
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
if not hasattr(self, "__initialized"):
|
if not hasattr(self, "__initialized"):
|
||||||
self.__initialized = False
|
self.__initialized = False
|
||||||
@@ -69,20 +66,10 @@ class KiauhSettings:
|
|||||||
self.__initialized = True
|
self.__initialized = True
|
||||||
self.config = SimpleConfigParser()
|
self.config = SimpleConfigParser()
|
||||||
self.kiauh = AppSettings()
|
self.kiauh = AppSettings()
|
||||||
self.klipper = KlipperSettings()
|
self.klipper = RepoSettings()
|
||||||
self.moonraker = MoonrakerSettings()
|
self.moonraker = RepoSettings()
|
||||||
self.mainsail = MainsailSettings()
|
self.mainsail = WebUiSettings()
|
||||||
self.fluidd = FluiddSettings()
|
self.fluidd = WebUiSettings()
|
||||||
|
|
||||||
self.kiauh.backup_before_update = None
|
|
||||||
self.klipper.repo_url = None
|
|
||||||
self.klipper.branch = None
|
|
||||||
self.moonraker.repo_url = None
|
|
||||||
self.moonraker.branch = None
|
|
||||||
self.mainsail.port = None
|
|
||||||
self.mainsail.unstable_releases = None
|
|
||||||
self.fluidd.port = None
|
|
||||||
self.fluidd.unstable_releases = None
|
|
||||||
|
|
||||||
self._load_config()
|
self._load_config()
|
||||||
|
|
||||||
@@ -102,22 +89,8 @@ class KiauhSettings:
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def set(self, section: str, option: str, value: str | int | bool) -> None:
|
|
||||||
"""
|
|
||||||
Set a value in the settings state by providing the section and option name as strings.
|
|
||||||
Prefer direct access to the properties, as it is usually safer!
|
|
||||||
:param section: The section name as string.
|
|
||||||
:param option: The option name as string.
|
|
||||||
:param value: The value to set as string, int or bool.
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
section = getattr(self, section)
|
|
||||||
section.option = value # type: ignore
|
|
||||||
except AttributeError:
|
|
||||||
raise
|
|
||||||
|
|
||||||
def save(self) -> None:
|
def save(self) -> None:
|
||||||
self._set_config_options()
|
self._set_config_options_state()
|
||||||
self.config.write(CUSTOM_CFG)
|
self.config.write(CUSTOM_CFG)
|
||||||
self._load_config()
|
self._load_config()
|
||||||
|
|
||||||
@@ -129,7 +102,7 @@ class KiauhSettings:
|
|||||||
self.config.read(cfg)
|
self.config.read(cfg)
|
||||||
|
|
||||||
self._validate_cfg()
|
self._validate_cfg()
|
||||||
self._read_settings()
|
self._apply_settings_from_file()
|
||||||
|
|
||||||
def _validate_cfg(self) -> None:
|
def _validate_cfg(self) -> None:
|
||||||
try:
|
try:
|
||||||
@@ -171,7 +144,7 @@ class KiauhSettings:
|
|||||||
if v.isdigit() or v.lower() == "true" or v.lower() == "false":
|
if v.isdigit() or v.lower() == "true" or v.lower() == "false":
|
||||||
raise ValueError
|
raise ValueError
|
||||||
|
|
||||||
def _read_settings(self) -> None:
|
def _apply_settings_from_file(self) -> None:
|
||||||
self.kiauh.backup_before_update = self.config.getboolean(
|
self.kiauh.backup_before_update = self.config.getboolean(
|
||||||
"kiauh", "backup_before_update"
|
"kiauh", "backup_before_update"
|
||||||
)
|
)
|
||||||
@@ -188,7 +161,7 @@ class KiauhSettings:
|
|||||||
"fluidd", "unstable_releases"
|
"fluidd", "unstable_releases"
|
||||||
)
|
)
|
||||||
|
|
||||||
def _set_config_options(self) -> None:
|
def _set_config_options_state(self) -> None:
|
||||||
self.config.set(
|
self.config.set(
|
||||||
"kiauh",
|
"kiauh",
|
||||||
"backup_before_update",
|
"backup_before_update",
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ StatusMap: Dict[StatusCode, StatusText] = {
|
|||||||
@dataclass
|
@dataclass
|
||||||
class ComponentStatus:
|
class ComponentStatus:
|
||||||
status: StatusCode
|
status: StatusCode
|
||||||
|
owner: str | None = None
|
||||||
repo: str | None = None
|
repo: str | None = None
|
||||||
local: str | None = None
|
local: str | None = None
|
||||||
remote: str | None = None
|
remote: str | None = None
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"index": 3,
|
"index": 4,
|
||||||
"module": "klipper_backup_extension",
|
"module": "klipper_backup_extension",
|
||||||
"maintained_by": "Staubgeborener",
|
"maintained_by": "Staubgeborener",
|
||||||
"display_name": "Klipper-Backup",
|
"display_name": "Klipper-Backup",
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import shutil
|
|||||||
import textwrap
|
import textwrap
|
||||||
import urllib.request
|
import urllib.request
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Any, Dict, List, Type, Union
|
from typing import Any, Dict, List, Type
|
||||||
|
|
||||||
from components.klipper.klipper import Klipper
|
from components.klipper.klipper import Klipper
|
||||||
from components.klipper.klipper_dialogs import (
|
from components.klipper.klipper_dialogs import (
|
||||||
@@ -21,14 +21,13 @@ from components.klipper.klipper_dialogs import (
|
|||||||
print_instance_overview,
|
print_instance_overview,
|
||||||
)
|
)
|
||||||
from core.constants import COLOR_CYAN, COLOR_YELLOW, RESET_FORMAT
|
from core.constants import COLOR_CYAN, COLOR_YELLOW, RESET_FORMAT
|
||||||
from core.instance_manager.base_instance import BaseInstance
|
|
||||||
from core.instance_type import InstanceType
|
|
||||||
from core.logger import Logger
|
from core.logger import Logger
|
||||||
from core.menus import Option
|
from core.menus import Option
|
||||||
from core.menus.base_menu import BaseMenu
|
from core.menus.base_menu import BaseMenu
|
||||||
from extensions.base_extension import BaseExtension
|
from extensions.base_extension import BaseExtension
|
||||||
from utils.git_utils import git_clone_wrapper
|
from utils.git_utils import git_clone_wrapper
|
||||||
from utils.input_utils import get_selection_input
|
from utils.input_utils import get_selection_input
|
||||||
|
from utils.instance_type import InstanceType
|
||||||
from utils.instance_utils import get_instances
|
from utils.instance_utils import get_instances
|
||||||
|
|
||||||
|
|
||||||
@@ -60,8 +59,8 @@ class MainsailThemeInstallerExtension(BaseExtension):
|
|||||||
return
|
return
|
||||||
|
|
||||||
for printer in printer_list:
|
for printer in printer_list:
|
||||||
Logger.print_status(f"Uninstalling theme from {printer.cfg_dir} ...")
|
Logger.print_status(f"Uninstalling theme from {printer.base.cfg_dir} ...")
|
||||||
theme_dir = printer.cfg_dir.joinpath(".theme")
|
theme_dir = printer.base.cfg_dir.joinpath(".theme")
|
||||||
if not theme_dir.exists():
|
if not theme_dir.exists():
|
||||||
Logger.print_info(f"{theme_dir} not found. Skipping ...")
|
Logger.print_info(f"{theme_dir} not found. Skipping ...")
|
||||||
continue
|
continue
|
||||||
@@ -116,6 +115,7 @@ class MainsailThemeInstallMenu(BaseMenu):
|
|||||||
j: str = f" {i}" if i < 10 else f"{i}"
|
j: str = f" {i}" if i < 10 else f"{i}"
|
||||||
row: str = f"{j}) [{theme.name}]"
|
row: str = f"{j}) [{theme.name}]"
|
||||||
menu += f"║ {row:<53} ║\n"
|
menu += f"║ {row:<53} ║\n"
|
||||||
|
menu += "╟───────────────────────────────────────────────────────╢\n"
|
||||||
print(menu, end="")
|
print(menu, end="")
|
||||||
|
|
||||||
def load_themes(self) -> List[ThemeData]:
|
def load_themes(self) -> List[ThemeData]:
|
||||||
@@ -158,7 +158,7 @@ class MainsailThemeInstallMenu(BaseMenu):
|
|||||||
return
|
return
|
||||||
|
|
||||||
for printer in printer_list:
|
for printer in printer_list:
|
||||||
git_clone_wrapper(theme_repo_url, printer.cfg_dir.joinpath(".theme"))
|
git_clone_wrapper(theme_repo_url, printer.base.cfg_dir.joinpath(".theme"))
|
||||||
|
|
||||||
if len(theme_data.short_note) > 1:
|
if len(theme_data.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")
|
||||||
@@ -167,7 +167,7 @@ class MainsailThemeInstallMenu(BaseMenu):
|
|||||||
|
|
||||||
def get_printer_selection(
|
def get_printer_selection(
|
||||||
instances: List[InstanceType], is_install: bool
|
instances: List[InstanceType], is_install: bool
|
||||||
) -> Union[List[BaseInstance], None]:
|
) -> List[InstanceType] | None:
|
||||||
options = [str(i) for i in range(len(instances))]
|
options = [str(i) for i in range(len(instances))]
|
||||||
options.extend(["a", "b"])
|
options.extend(["a", "b"])
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
# #
|
# #
|
||||||
# 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 pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from core.backup_manager import BACKUP_ROOT_DIR
|
from core.backup_manager import BACKUP_ROOT_DIR
|
||||||
12
kiauh/extensions/mobileraker/metadata.json
Normal file
12
kiauh/extensions/mobileraker/metadata.json
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"metadata": {
|
||||||
|
"index": 3,
|
||||||
|
"module": "mobileraker_extension",
|
||||||
|
"maintained_by": "Clon1998",
|
||||||
|
"display_name": "Mobileraker",
|
||||||
|
"description": [
|
||||||
|
"Companion for Mobileraker, enabling push notification for Klipper using Moonraker."
|
||||||
|
],
|
||||||
|
"updates": true
|
||||||
|
}
|
||||||
|
}
|
||||||
192
kiauh/extensions/mobileraker/mobileraker_extension.py
Normal file
192
kiauh/extensions/mobileraker/mobileraker_extension.py
Normal file
@@ -0,0 +1,192 @@
|
|||||||
|
# ======================================================================= #
|
||||||
|
# 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 CalledProcessError, run
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
from components.klipper.klipper import Klipper
|
||||||
|
from components.moonraker.moonraker import Moonraker
|
||||||
|
from core.backup_manager.backup_manager import BackupManager
|
||||||
|
from core.instance_manager.instance_manager import InstanceManager
|
||||||
|
from core.logger import DialogType, Logger
|
||||||
|
from core.settings.kiauh_settings import KiauhSettings
|
||||||
|
from extensions.base_extension import BaseExtension
|
||||||
|
from extensions.mobileraker import (
|
||||||
|
MOBILERAKER_BACKUP_DIR,
|
||||||
|
MOBILERAKER_DIR,
|
||||||
|
MOBILERAKER_ENV_DIR,
|
||||||
|
MOBILERAKER_INSTALL_SCRIPT,
|
||||||
|
MOBILERAKER_LOG_NAME,
|
||||||
|
MOBILERAKER_REPO,
|
||||||
|
MOBILERAKER_REQ_FILE,
|
||||||
|
MOBILERAKER_SERVICE_FILE,
|
||||||
|
MOBILERAKER_SERVICE_NAME,
|
||||||
|
MOBILERAKER_UPDATER_SECTION_NAME,
|
||||||
|
)
|
||||||
|
from utils.common import check_install_dependencies
|
||||||
|
from utils.config_utils import add_config_section, remove_config_section
|
||||||
|
from utils.git_utils import git_clone_wrapper, git_pull_wrapper
|
||||||
|
from utils.input_utils import get_confirm
|
||||||
|
from utils.instance_utils import get_instances
|
||||||
|
from utils.sys_utils import (
|
||||||
|
check_python_version,
|
||||||
|
cmd_sysctl_service,
|
||||||
|
install_python_requirements,
|
||||||
|
remove_system_service,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# noinspection PyMethodMayBeStatic
|
||||||
|
class MobilerakerExtension(BaseExtension):
|
||||||
|
def install_extension(self, **kwargs) -> None:
|
||||||
|
Logger.print_status("Installing Mobileraker's companion ...")
|
||||||
|
|
||||||
|
if not check_python_version(3, 7):
|
||||||
|
return
|
||||||
|
|
||||||
|
mr_instances = get_instances(Moonraker)
|
||||||
|
if not mr_instances:
|
||||||
|
Logger.print_dialog(
|
||||||
|
DialogType.WARNING,
|
||||||
|
[
|
||||||
|
"Moonraker not found! Mobileraker's companion will not properly "
|
||||||
|
"work without a working Moonraker installation.",
|
||||||
|
"Mobileraker's companion's update manager configuration for "
|
||||||
|
"Moonraker will not be added to any moonraker.conf.",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
if not get_confirm(
|
||||||
|
"Continue Mobileraker's companion installation?",
|
||||||
|
default_choice=False,
|
||||||
|
allow_go_back=True,
|
||||||
|
):
|
||||||
|
return
|
||||||
|
|
||||||
|
check_install_dependencies()
|
||||||
|
|
||||||
|
git_clone_wrapper(MOBILERAKER_REPO, MOBILERAKER_DIR)
|
||||||
|
|
||||||
|
try:
|
||||||
|
run(MOBILERAKER_INSTALL_SCRIPT.as_posix(), shell=True, check=True)
|
||||||
|
if mr_instances:
|
||||||
|
self._patch_mobileraker_update_manager(mr_instances)
|
||||||
|
InstanceManager.restart_all(mr_instances)
|
||||||
|
else:
|
||||||
|
Logger.print_info(
|
||||||
|
"Moonraker is not installed! Cannot add Mobileraker's "
|
||||||
|
"companion to update manager!"
|
||||||
|
)
|
||||||
|
Logger.print_ok("Mobileraker's companion successfully installed!")
|
||||||
|
except CalledProcessError as e:
|
||||||
|
Logger.print_error(f"Error installing Mobileraker's companion:\n{e}")
|
||||||
|
return
|
||||||
|
|
||||||
|
def update_extension(self, **kwargs) -> None:
|
||||||
|
try:
|
||||||
|
if not MOBILERAKER_DIR.exists():
|
||||||
|
Logger.print_info(
|
||||||
|
"Mobileraker's companion doesn't seem to be installed! Skipping ..."
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
|
Logger.print_status("Updating Mobileraker's companion ...")
|
||||||
|
|
||||||
|
cmd_sysctl_service(MOBILERAKER_SERVICE_NAME, "stop")
|
||||||
|
|
||||||
|
settings = KiauhSettings()
|
||||||
|
if settings.kiauh.backup_before_update:
|
||||||
|
self._backup_mobileraker_dir()
|
||||||
|
|
||||||
|
git_pull_wrapper(MOBILERAKER_REPO, MOBILERAKER_DIR)
|
||||||
|
|
||||||
|
install_python_requirements(MOBILERAKER_ENV_DIR, MOBILERAKER_REQ_FILE)
|
||||||
|
|
||||||
|
cmd_sysctl_service(MOBILERAKER_SERVICE_NAME, "start")
|
||||||
|
|
||||||
|
Logger.print_ok("Mobileraker's companion updated successfully.", end="\n\n")
|
||||||
|
except CalledProcessError as e:
|
||||||
|
Logger.print_error(f"Error updating Mobileraker's companion:\n{e}")
|
||||||
|
return
|
||||||
|
|
||||||
|
def remove_extension(self, **kwargs) -> None:
|
||||||
|
Logger.print_status("Removing Mobileraker's companion ...")
|
||||||
|
try:
|
||||||
|
if MOBILERAKER_DIR.exists():
|
||||||
|
Logger.print_status("Removing Mobileraker's companion directory ...")
|
||||||
|
shutil.rmtree(MOBILERAKER_DIR)
|
||||||
|
Logger.print_ok(
|
||||||
|
"Mobileraker's companion directory successfully removed!"
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
Logger.print_warn("Mobileraker's companion directory not found!")
|
||||||
|
|
||||||
|
if MOBILERAKER_ENV_DIR.exists():
|
||||||
|
Logger.print_status("Removing Mobileraker's companion environment ...")
|
||||||
|
shutil.rmtree(MOBILERAKER_ENV_DIR)
|
||||||
|
Logger.print_ok(
|
||||||
|
"Mobileraker's companion environment successfully removed!"
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
Logger.print_warn("Mobileraker's companion environment not found!")
|
||||||
|
|
||||||
|
if MOBILERAKER_SERVICE_FILE.exists():
|
||||||
|
remove_system_service(MOBILERAKER_SERVICE_NAME)
|
||||||
|
|
||||||
|
kl_instances: List[Klipper] = get_instances(Klipper)
|
||||||
|
for instance in kl_instances:
|
||||||
|
logfile = instance.base.log_dir.joinpath(MOBILERAKER_LOG_NAME)
|
||||||
|
if logfile.exists():
|
||||||
|
Logger.print_status(f"Removing {logfile} ...")
|
||||||
|
Path(logfile).unlink()
|
||||||
|
Logger.print_ok(f"{logfile} successfully removed!")
|
||||||
|
|
||||||
|
mr_instances: List[Moonraker] = get_instances(Moonraker)
|
||||||
|
if mr_instances:
|
||||||
|
Logger.print_status(
|
||||||
|
"Removing Mobileraker's companion from update manager ..."
|
||||||
|
)
|
||||||
|
remove_config_section(MOBILERAKER_UPDATER_SECTION_NAME, mr_instances)
|
||||||
|
Logger.print_ok(
|
||||||
|
"Mobileraker's companion successfully removed from update manager!"
|
||||||
|
)
|
||||||
|
|
||||||
|
Logger.print_ok("Mobileraker's companion successfully removed!")
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
Logger.print_error(f"Error removing Mobileraker's companion:\n{e}")
|
||||||
|
|
||||||
|
def _patch_mobileraker_update_manager(self, instances: List[Moonraker]) -> None:
|
||||||
|
add_config_section(
|
||||||
|
section=MOBILERAKER_UPDATER_SECTION_NAME,
|
||||||
|
instances=instances,
|
||||||
|
options=[
|
||||||
|
("type", "git_repo"),
|
||||||
|
("path", MOBILERAKER_DIR.as_posix()),
|
||||||
|
("origin", MOBILERAKER_REPO),
|
||||||
|
("primary_branch", "main"),
|
||||||
|
("managed_services", "mobileraker"),
|
||||||
|
("env", f"{MOBILERAKER_ENV_DIR}/bin/python"),
|
||||||
|
("requirements", MOBILERAKER_REQ_FILE.as_posix()),
|
||||||
|
("install_script", MOBILERAKER_INSTALL_SCRIPT.as_posix()),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
def _backup_mobileraker_dir(self) -> None:
|
||||||
|
bm = BackupManager()
|
||||||
|
bm.backup_directory(
|
||||||
|
MOBILERAKER_DIR.name,
|
||||||
|
source=MOBILERAKER_DIR,
|
||||||
|
target=MOBILERAKER_BACKUP_DIR,
|
||||||
|
)
|
||||||
|
bm.backup_directory(
|
||||||
|
MOBILERAKER_ENV_DIR.name,
|
||||||
|
source=MOBILERAKER_ENV_DIR,
|
||||||
|
target=MOBILERAKER_BACKUP_DIR,
|
||||||
|
)
|
||||||
16
kiauh/extensions/octoeverywhere/metadata.json
Normal file
16
kiauh/extensions/octoeverywhere/metadata.json
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"metadata": {
|
||||||
|
"index": 7,
|
||||||
|
"module": "octoeverywhere_extension",
|
||||||
|
"maintained_by": "QuinnDamerell",
|
||||||
|
"display_name": "OctoEverywhere for Klipper",
|
||||||
|
"description": [
|
||||||
|
"Cloud Empower Your Klipper 3D Printers With:",
|
||||||
|
"- Free, Private, And Secure Remote Access",
|
||||||
|
"- AI Print Failure Detection",
|
||||||
|
"- Real-time Notifications",
|
||||||
|
"- Live Streaming, and More!"
|
||||||
|
],
|
||||||
|
"updates": true
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,7 +14,9 @@ from subprocess import CalledProcessError, run
|
|||||||
|
|
||||||
from components.moonraker import MOONRAKER_CFG_NAME
|
from components.moonraker import MOONRAKER_CFG_NAME
|
||||||
from components.moonraker.moonraker import Moonraker
|
from components.moonraker.moonraker import Moonraker
|
||||||
from components.octoeverywhere import (
|
from core.instance_manager.base_instance import BaseInstance
|
||||||
|
from core.logger import Logger
|
||||||
|
from extensions.octoeverywhere import (
|
||||||
OE_CFG_NAME,
|
OE_CFG_NAME,
|
||||||
OE_DIR,
|
OE_DIR,
|
||||||
OE_ENV_DIR,
|
OE_ENV_DIR,
|
||||||
@@ -23,8 +25,6 @@ from components.octoeverywhere import (
|
|||||||
OE_SYS_CFG_NAME,
|
OE_SYS_CFG_NAME,
|
||||||
OE_UPDATE_SCRIPT,
|
OE_UPDATE_SCRIPT,
|
||||||
)
|
)
|
||||||
from core.instance_manager.base_instance import BaseInstance
|
|
||||||
from core.logger import Logger
|
|
||||||
from utils.sys_utils import get_service_file_path
|
from utils.sys_utils import get_service_file_path
|
||||||
|
|
||||||
|
|
||||||
191
kiauh/extensions/octoeverywhere/octoeverywhere_extension.py
Normal file
191
kiauh/extensions/octoeverywhere/octoeverywhere_extension.py
Normal file
@@ -0,0 +1,191 @@
|
|||||||
|
# ======================================================================= #
|
||||||
|
# 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 json
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
from components.moonraker.moonraker import Moonraker
|
||||||
|
from core.instance_manager.instance_manager import InstanceManager
|
||||||
|
from core.logger import DialogType, Logger
|
||||||
|
from extensions.base_extension import BaseExtension
|
||||||
|
from extensions.octoeverywhere import (
|
||||||
|
OE_DEPS_JSON_FILE,
|
||||||
|
OE_DIR,
|
||||||
|
OE_ENV_DIR,
|
||||||
|
OE_INSTALL_SCRIPT,
|
||||||
|
OE_INSTALLER_LOG_FILE,
|
||||||
|
OE_REPO,
|
||||||
|
OE_REQ_FILE,
|
||||||
|
OE_SYS_CFG_NAME,
|
||||||
|
)
|
||||||
|
from extensions.octoeverywhere.octoeverywhere import Octoeverywhere
|
||||||
|
from utils.common import (
|
||||||
|
check_install_dependencies,
|
||||||
|
moonraker_exists,
|
||||||
|
)
|
||||||
|
from utils.config_utils import (
|
||||||
|
remove_config_section,
|
||||||
|
)
|
||||||
|
from utils.fs_utils import run_remove_routines
|
||||||
|
from utils.git_utils import git_clone_wrapper
|
||||||
|
from utils.input_utils import get_confirm
|
||||||
|
from utils.instance_utils import get_instances
|
||||||
|
from utils.sys_utils import (
|
||||||
|
install_python_requirements,
|
||||||
|
parse_packages_from_file,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# noinspection PyMethodMayBeStatic
|
||||||
|
class OctoeverywhereExtension(BaseExtension):
|
||||||
|
def install_extension(self, **kwargs) -> None:
|
||||||
|
Logger.print_status("Installing OctoEverywhere for Klipper ...")
|
||||||
|
|
||||||
|
# check if moonraker is installed. if not, notify the user and exit
|
||||||
|
if not moonraker_exists():
|
||||||
|
return
|
||||||
|
|
||||||
|
force_clone = False
|
||||||
|
oe_instances: List[Octoeverywhere] = get_instances(Octoeverywhere)
|
||||||
|
if oe_instances:
|
||||||
|
Logger.print_dialog(
|
||||||
|
DialogType.INFO,
|
||||||
|
[
|
||||||
|
"OctoEverywhere is already installed!",
|
||||||
|
"It is safe to run the installer again to link your "
|
||||||
|
"printer or repair any issues.",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
if not get_confirm("Re-run OctoEverywhere installation?"):
|
||||||
|
Logger.print_info("Exiting OctoEverywhere for Klipper installation ...")
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
Logger.print_status("Re-Installing OctoEverywhere for Klipper ...")
|
||||||
|
force_clone = True
|
||||||
|
|
||||||
|
mr_instances: List[Moonraker] = get_instances(Moonraker)
|
||||||
|
|
||||||
|
mr_names = [f"● {moonraker.data_dir.name}" for moonraker in mr_instances]
|
||||||
|
if len(mr_names) > 1:
|
||||||
|
Logger.print_dialog(
|
||||||
|
DialogType.INFO,
|
||||||
|
[
|
||||||
|
"The following Moonraker instances were found:",
|
||||||
|
*mr_names,
|
||||||
|
"\n\n",
|
||||||
|
"The setup will apply the same names to OctoEverywhere!",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
if not get_confirm(
|
||||||
|
"Continue OctoEverywhere for Klipper installation?",
|
||||||
|
default_choice=True,
|
||||||
|
allow_go_back=True,
|
||||||
|
):
|
||||||
|
Logger.print_info("Exiting OctoEverywhere for Klipper installation ...")
|
||||||
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
|
git_clone_wrapper(OE_REPO, OE_DIR, force=force_clone)
|
||||||
|
|
||||||
|
for moonraker in mr_instances:
|
||||||
|
instance = Octoeverywhere(suffix=moonraker.suffix)
|
||||||
|
instance.create()
|
||||||
|
|
||||||
|
InstanceManager.restart_all(mr_instances)
|
||||||
|
|
||||||
|
Logger.print_dialog(
|
||||||
|
DialogType.SUCCESS,
|
||||||
|
["OctoEverywhere for Klipper successfully installed!"],
|
||||||
|
center_content=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
Logger.print_error(
|
||||||
|
f"Error during OctoEverywhere for Klipper installation:\n{e}"
|
||||||
|
)
|
||||||
|
|
||||||
|
def update_extension(self, **kwargs) -> None:
|
||||||
|
Logger.print_status("Updating OctoEverywhere for Klipper ...")
|
||||||
|
try:
|
||||||
|
Octoeverywhere.update()
|
||||||
|
Logger.print_dialog(
|
||||||
|
DialogType.SUCCESS,
|
||||||
|
["OctoEverywhere for Klipper successfully updated!"],
|
||||||
|
center_content=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
Logger.print_error(f"Error during OctoEverywhere for Klipper update:\n{e}")
|
||||||
|
|
||||||
|
def remove_extension(self, **kwargs) -> None:
|
||||||
|
Logger.print_status("Removing OctoEverywhere for Klipper ...")
|
||||||
|
|
||||||
|
mr_instances: List[Moonraker] = get_instances(Moonraker)
|
||||||
|
ob_instances: List[Octoeverywhere] = get_instances(Octoeverywhere)
|
||||||
|
|
||||||
|
try:
|
||||||
|
self._remove_oe_instances(ob_instances)
|
||||||
|
self._remove_oe_dir()
|
||||||
|
self._remove_oe_env()
|
||||||
|
remove_config_section(f"include {OE_SYS_CFG_NAME}", mr_instances)
|
||||||
|
run_remove_routines(OE_INSTALLER_LOG_FILE)
|
||||||
|
Logger.print_dialog(
|
||||||
|
DialogType.SUCCESS,
|
||||||
|
["OctoEverywhere for Klipper successfully removed!"],
|
||||||
|
center_content=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
Logger.print_error(f"Error during OctoEverywhere for Klipper removal:\n{e}")
|
||||||
|
|
||||||
|
def _install_oe_dependencies(self) -> None:
|
||||||
|
oe_deps = []
|
||||||
|
if OE_DEPS_JSON_FILE.exists():
|
||||||
|
with open(OE_DEPS_JSON_FILE, "r") as deps:
|
||||||
|
oe_deps = json.load(deps).get("debian", [])
|
||||||
|
elif OE_INSTALL_SCRIPT.exists():
|
||||||
|
oe_deps = parse_packages_from_file(OE_INSTALL_SCRIPT)
|
||||||
|
|
||||||
|
if not oe_deps:
|
||||||
|
raise ValueError("Error reading OctoEverywhere dependencies!")
|
||||||
|
|
||||||
|
check_install_dependencies({*oe_deps})
|
||||||
|
install_python_requirements(OE_ENV_DIR, OE_REQ_FILE)
|
||||||
|
|
||||||
|
def _remove_oe_instances(
|
||||||
|
self,
|
||||||
|
instance_list: List[Octoeverywhere],
|
||||||
|
) -> None:
|
||||||
|
if not instance_list:
|
||||||
|
Logger.print_info("No OctoEverywhere instances found. Skipped ...")
|
||||||
|
return
|
||||||
|
|
||||||
|
for instance in instance_list:
|
||||||
|
Logger.print_status(
|
||||||
|
f"Removing instance {instance.service_file_path.stem} ..."
|
||||||
|
)
|
||||||
|
InstanceManager.remove(instance)
|
||||||
|
|
||||||
|
def _remove_oe_dir(self) -> None:
|
||||||
|
Logger.print_status("Removing OctoEverywhere for Klipper directory ...")
|
||||||
|
|
||||||
|
if not OE_DIR.exists():
|
||||||
|
Logger.print_info(f"'{OE_DIR}' does not exist. Skipped ...")
|
||||||
|
return
|
||||||
|
|
||||||
|
run_remove_routines(OE_DIR)
|
||||||
|
|
||||||
|
def _remove_oe_env(self) -> None:
|
||||||
|
Logger.print_status("Removing OctoEverywhere for Klipper environment ...")
|
||||||
|
|
||||||
|
if not OE_ENV_DIR.exists():
|
||||||
|
Logger.print_info(f"'{OE_ENV_DIR}' does not exist. Skipped ...")
|
||||||
|
return
|
||||||
|
|
||||||
|
run_remove_routines(OE_ENV_DIR)
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"index": 5,
|
"index": 8,
|
||||||
"module": "pretty_gcode_extension",
|
"module": "pretty_gcode_extension",
|
||||||
"maintained_by": "Kragrathea",
|
"maintained_by": "Kragrathea",
|
||||||
"display_name": "PrettyGCode for Klipper",
|
"display_name": "PrettyGCode for Klipper",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"index": 4,
|
"index": 5,
|
||||||
"module": "moonraker_telegram_bot_extension",
|
"module": "moonraker_telegram_bot_extension",
|
||||||
"maintained_by": "nlef",
|
"maintained_by": "nlef",
|
||||||
"display_name": "Moonraker Telegram Bot",
|
"display_name": "Moonraker Telegram Bot",
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ class TelegramBotExtension(BaseExtension):
|
|||||||
options=[
|
options=[
|
||||||
("type", "git_repo"),
|
("type", "git_repo"),
|
||||||
("path", str(TG_BOT_DIR)),
|
("path", str(TG_BOT_DIR)),
|
||||||
("orgin", TG_BOT_REPO),
|
("origin", TG_BOT_REPO),
|
||||||
("env", env_py),
|
("env", env_py),
|
||||||
("requirements", "scripts/requirements.txt"),
|
("requirements", "scripts/requirements.txt"),
|
||||||
("install_script", "scripts/install.sh"),
|
("install_script", "scripts/install.sh"),
|
||||||
|
|||||||
154
kiauh/procedures/switch_repo.py
Normal file
154
kiauh/procedures/switch_repo.py
Normal file
@@ -0,0 +1,154 @@
|
|||||||
|
# ======================================================================= #
|
||||||
|
# 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 __future__ import annotations
|
||||||
|
|
||||||
|
import shutil
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import Literal
|
||||||
|
|
||||||
|
from components.klipper import (
|
||||||
|
KLIPPER_BACKUP_DIR,
|
||||||
|
KLIPPER_DIR,
|
||||||
|
KLIPPER_ENV_DIR,
|
||||||
|
KLIPPER_REQ_FILE,
|
||||||
|
)
|
||||||
|
from components.klipper.klipper import Klipper
|
||||||
|
from components.klipper.klipper_setup import install_klipper_packages
|
||||||
|
from components.moonraker import (
|
||||||
|
MOONRAKER_BACKUP_DIR,
|
||||||
|
MOONRAKER_DIR,
|
||||||
|
MOONRAKER_ENV_DIR,
|
||||||
|
MOONRAKER_REQ_FILE,
|
||||||
|
)
|
||||||
|
from components.moonraker.moonraker import Moonraker
|
||||||
|
from components.moonraker.moonraker_setup import install_moonraker_packages
|
||||||
|
from core.backup_manager.backup_manager import BackupManager, BackupManagerException
|
||||||
|
from core.instance_manager.instance_manager import InstanceManager
|
||||||
|
from core.logger import Logger
|
||||||
|
from core.settings.kiauh_settings import RepoSettings
|
||||||
|
from utils.git_utils import GitException, get_repo_name, git_clone_wrapper
|
||||||
|
from utils.instance_utils import get_instances
|
||||||
|
from utils.sys_utils import (
|
||||||
|
VenvCreationFailedException,
|
||||||
|
create_python_venv,
|
||||||
|
install_python_requirements,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class RepoSwitchFailedException(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def run_switch_repo_routine(
|
||||||
|
name: Literal["klipper", "moonraker"], repo_settings: RepoSettings
|
||||||
|
) -> None:
|
||||||
|
repo_dir: Path = KLIPPER_DIR if name == "klipper" else MOONRAKER_DIR
|
||||||
|
env_dir: Path = KLIPPER_ENV_DIR if name == "klipper" else MOONRAKER_ENV_DIR
|
||||||
|
req_file = KLIPPER_REQ_FILE if name == "klipper" else MOONRAKER_REQ_FILE
|
||||||
|
backup_dir: Path = KLIPPER_BACKUP_DIR if name == "klipper" else MOONRAKER_BACKUP_DIR
|
||||||
|
_type = Klipper if name == "klipper" else Moonraker
|
||||||
|
|
||||||
|
# step 1: stop all instances
|
||||||
|
Logger.print_status(f"Stopping all {_type.__name__} instances ...")
|
||||||
|
instances = get_instances(_type)
|
||||||
|
InstanceManager.stop_all(instances)
|
||||||
|
|
||||||
|
repo_dir_backup_path: Path | None = None
|
||||||
|
env_dir_backup_path: Path | None = None
|
||||||
|
|
||||||
|
try:
|
||||||
|
# step 2: backup old repo and env
|
||||||
|
org, repo = get_repo_name(repo_dir)
|
||||||
|
backup_dir = backup_dir.joinpath(org)
|
||||||
|
bm = BackupManager()
|
||||||
|
repo_dir_backup_path = bm.backup_directory(
|
||||||
|
repo_dir.name,
|
||||||
|
repo_dir,
|
||||||
|
backup_dir,
|
||||||
|
)
|
||||||
|
env_dir_backup_path = bm.backup_directory(
|
||||||
|
env_dir.name,
|
||||||
|
env_dir,
|
||||||
|
backup_dir,
|
||||||
|
)
|
||||||
|
|
||||||
|
# step 3: read repo url and branch from settings
|
||||||
|
repo_url = repo_settings.repo_url
|
||||||
|
branch = repo_settings.branch
|
||||||
|
|
||||||
|
if not (repo_url or branch):
|
||||||
|
error = f"Invalid repository URL ({repo_url}) or branch ({branch})!"
|
||||||
|
raise ValueError(error)
|
||||||
|
|
||||||
|
# step 4: clone new repo
|
||||||
|
git_clone_wrapper(repo_url, repo_dir, branch, force=True)
|
||||||
|
|
||||||
|
# step 5: install os dependencies
|
||||||
|
if name == "klipper":
|
||||||
|
install_klipper_packages()
|
||||||
|
elif name == "moonraker":
|
||||||
|
install_moonraker_packages()
|
||||||
|
|
||||||
|
# step 6: recreate python virtualenv
|
||||||
|
Logger.print_status(f"Recreating {_type.__name__} virtualenv ...")
|
||||||
|
if not create_python_venv(env_dir, force=True):
|
||||||
|
raise GitException(f"Failed to recreate virtualenv for {_type.__name__}")
|
||||||
|
else:
|
||||||
|
install_python_requirements(env_dir, req_file)
|
||||||
|
|
||||||
|
Logger.print_ok(f"Switched to {repo_url} at branch {branch}!")
|
||||||
|
|
||||||
|
except BackupManagerException as e:
|
||||||
|
Logger.print_error(f"Error during backup of repository: {e}")
|
||||||
|
raise RepoSwitchFailedException(e)
|
||||||
|
|
||||||
|
except (GitException, VenvCreationFailedException) as e:
|
||||||
|
# if something goes wrong during cloning or recreating the virtualenv,
|
||||||
|
# we restore the backup of the repo and env
|
||||||
|
Logger.print_error(f"Error during repository switch: {e}", start="\n")
|
||||||
|
Logger.print_status(f"Restoring last backup of {_type.__name__} ...")
|
||||||
|
_restore_repo_backup(
|
||||||
|
_type.__name__,
|
||||||
|
env_dir,
|
||||||
|
env_dir_backup_path,
|
||||||
|
repo_dir,
|
||||||
|
repo_dir_backup_path,
|
||||||
|
)
|
||||||
|
|
||||||
|
except RepoSwitchFailedException as e:
|
||||||
|
Logger.print_error(f"Something went wrong: {e}")
|
||||||
|
return
|
||||||
|
|
||||||
|
Logger.print_status(f"Restarting all {_type.__name__} instances ...")
|
||||||
|
InstanceManager.start_all(instances)
|
||||||
|
|
||||||
|
|
||||||
|
def _restore_repo_backup(
|
||||||
|
name: str,
|
||||||
|
env_dir: Path,
|
||||||
|
env_dir_backup_path: Path | None,
|
||||||
|
repo_dir: Path,
|
||||||
|
repo_dir_backup_path: Path | None,
|
||||||
|
) -> None:
|
||||||
|
# if repo_dir_backup_path is not None and env_dir_backup_path is not None:
|
||||||
|
if not repo_dir_backup_path or not env_dir_backup_path:
|
||||||
|
raise RepoSwitchFailedException(
|
||||||
|
f"Unable to restore backup of {name}! Path of backups directory is None!"
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
if repo_dir.exists():
|
||||||
|
shutil.rmtree(repo_dir)
|
||||||
|
shutil.copytree(repo_dir_backup_path, repo_dir)
|
||||||
|
if env_dir.exists():
|
||||||
|
shutil.rmtree(env_dir)
|
||||||
|
shutil.copytree(env_dir_backup_path, env_dir)
|
||||||
|
Logger.print_warn(f"Restored backup of {name} successfully!")
|
||||||
|
except Exception as e:
|
||||||
|
raise RepoSwitchFailedException(f"Error restoring backup: {e}")
|
||||||
@@ -124,10 +124,12 @@ def get_install_status(
|
|||||||
else:
|
else:
|
||||||
status = 1 # incomplete
|
status = 1 # incomplete
|
||||||
|
|
||||||
|
org, repo = get_repo_name(repo_dir)
|
||||||
return ComponentStatus(
|
return ComponentStatus(
|
||||||
status=status,
|
status=status,
|
||||||
instances=instances,
|
instances=instances,
|
||||||
repo=get_repo_name(repo_dir),
|
owner=org,
|
||||||
|
repo=repo,
|
||||||
local=get_local_commit(repo_dir),
|
local=get_local_commit(repo_dir),
|
||||||
remote=get_remote_commit(repo_dir),
|
remote=get_remote_commit(repo_dir),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -12,11 +12,11 @@ import tempfile
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List, Tuple
|
from typing import List, Tuple
|
||||||
|
|
||||||
from core.instance_type import InstanceType
|
|
||||||
from core.logger import Logger
|
from core.logger import Logger
|
||||||
from core.submodules.simple_config_parser.src.simple_config_parser.simple_config_parser import (
|
from core.submodules.simple_config_parser.src.simple_config_parser.simple_config_parser import (
|
||||||
SimpleConfigParser,
|
SimpleConfigParser,
|
||||||
)
|
)
|
||||||
|
from utils.instance_type import InstanceType
|
||||||
|
|
||||||
ConfigOption = Tuple[str, str]
|
ConfigOption = Tuple[str, str]
|
||||||
|
|
||||||
|
|||||||
@@ -10,12 +10,16 @@ from subprocess import DEVNULL, PIPE, CalledProcessError, check_output, run
|
|||||||
from typing import List, Type
|
from typing import List, Type
|
||||||
|
|
||||||
from core.instance_manager.instance_manager import InstanceManager
|
from core.instance_manager.instance_manager import InstanceManager
|
||||||
from core.instance_type import InstanceType
|
|
||||||
from core.logger import Logger
|
from core.logger import Logger
|
||||||
from utils.input_utils import get_confirm, get_number_input
|
from utils.input_utils import get_confirm, get_number_input
|
||||||
|
from utils.instance_type import InstanceType
|
||||||
from utils.instance_utils import get_instances
|
from utils.instance_utils import get_instances
|
||||||
|
|
||||||
|
|
||||||
|
class GitException(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def git_clone_wrapper(
|
def git_clone_wrapper(
|
||||||
repo: str, target_dir: Path, branch: str | None = None, force: bool = False
|
repo: str, target_dir: Path, branch: str | None = None, force: bool = False
|
||||||
) -> None:
|
) -> None:
|
||||||
@@ -43,10 +47,10 @@ def git_clone_wrapper(
|
|||||||
except CalledProcessError:
|
except CalledProcessError:
|
||||||
log = "An unexpected error occured during cloning of the repository."
|
log = "An unexpected error occured during cloning of the repository."
|
||||||
Logger.print_error(log)
|
Logger.print_error(log)
|
||||||
return
|
raise GitException(log)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
Logger.print_error(f"Error removing existing repository: {e.strerror}")
|
Logger.print_error(f"Error removing existing repository: {e.strerror}")
|
||||||
return
|
raise GitException(f"Error removing existing repository: {e.strerror}")
|
||||||
|
|
||||||
|
|
||||||
def git_pull_wrapper(repo: str, target_dir: Path) -> None:
|
def git_pull_wrapper(repo: str, target_dir: Path) -> None:
|
||||||
@@ -66,20 +70,22 @@ def git_pull_wrapper(repo: str, target_dir: Path) -> None:
|
|||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def get_repo_name(repo: Path) -> str | None:
|
def get_repo_name(repo: Path) -> tuple[str, str] | None:
|
||||||
"""
|
"""
|
||||||
Helper method to extract the organisation and name of a repository |
|
Helper method to extract the organisation and name of a repository |
|
||||||
:param repo: repository to extract the values from
|
:param repo: repository to extract the values from
|
||||||
:return: String in form of "<orga>/<name>" or None
|
:return: String in form of "<orga>/<name>" or None
|
||||||
"""
|
"""
|
||||||
if not repo.exists() or not repo.joinpath(".git").exists():
|
if not repo.exists() or not repo.joinpath(".git").exists():
|
||||||
return "-"
|
return "-", "-"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
cmd = ["git", "-C", repo.as_posix(), "config", "--get", "remote.origin.url"]
|
cmd = ["git", "-C", repo.as_posix(), "config", "--get", "remote.origin.url"]
|
||||||
result: str = check_output(cmd, stderr=DEVNULL).decode(encoding="utf-8")
|
result: str = check_output(cmd, stderr=DEVNULL).decode(encoding="utf-8")
|
||||||
substrings: List[str] = result.strip().split("/")[-2:]
|
substrings: List[str] = result.strip().split("/")[-2:]
|
||||||
return "/".join(substrings).replace(".git", "")
|
return substrings[0], substrings[1]
|
||||||
|
|
||||||
|
# return "/".join(substrings).replace(".git", "")
|
||||||
except CalledProcessError:
|
except CalledProcessError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ from typing import TypeVar
|
|||||||
|
|
||||||
from components.klipper.klipper import Klipper
|
from components.klipper.klipper import Klipper
|
||||||
from components.moonraker.moonraker import Moonraker
|
from components.moonraker.moonraker import Moonraker
|
||||||
from components.octoeverywhere.octoeverywhere import Octoeverywhere
|
|
||||||
from extensions.obico.moonraker_obico import MoonrakerObico
|
from extensions.obico.moonraker_obico import MoonrakerObico
|
||||||
|
from extensions.octoeverywhere.octoeverywhere import Octoeverywhere
|
||||||
from extensions.telegram_bot.moonraker_telegram_bot import MoonrakerTelegramBot
|
from extensions.telegram_bot.moonraker_telegram_bot import MoonrakerTelegramBot
|
||||||
|
|
||||||
InstanceType = TypeVar(
|
InstanceType = TypeVar(
|
||||||
@@ -14,7 +14,7 @@ from typing import List
|
|||||||
|
|
||||||
from core.constants import SYSTEMD
|
from core.constants import SYSTEMD
|
||||||
from core.instance_manager.base_instance import SUFFIX_BLACKLIST
|
from core.instance_manager.base_instance import SUFFIX_BLACKLIST
|
||||||
from core.instance_type import InstanceType
|
from utils.instance_type import InstanceType
|
||||||
|
|
||||||
|
|
||||||
def get_instances(instance_type: type) -> List[InstanceType]:
|
def get_instances(instance_type: type) -> List[InstanceType]:
|
||||||
|
|||||||
@@ -39,6 +39,10 @@ SysCtlServiceAction = Literal[
|
|||||||
SysCtlManageAction = Literal["daemon-reload", "reset-failed"]
|
SysCtlManageAction = Literal["daemon-reload", "reset-failed"]
|
||||||
|
|
||||||
|
|
||||||
|
class VenvCreationFailedException(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def kill(opt_err_msg: str = "") -> None:
|
def kill(opt_err_msg: str = "") -> None:
|
||||||
"""
|
"""
|
||||||
Kills the application |
|
Kills the application |
|
||||||
@@ -87,11 +91,12 @@ def parse_packages_from_file(source_file: Path) -> List[str]:
|
|||||||
return packages
|
return packages
|
||||||
|
|
||||||
|
|
||||||
def create_python_venv(target: Path) -> bool:
|
def create_python_venv(target: Path, force: bool = False) -> bool:
|
||||||
"""
|
"""
|
||||||
Create a python 3 virtualenv at the provided target destination.
|
Create a python 3 virtualenv at the provided target destination.
|
||||||
Returns True if the virtualenv was created successfully.
|
Returns True if the virtualenv was created successfully.
|
||||||
Returns False if the virtualenv already exists, recreation was declined or creation failed.
|
Returns False if the virtualenv already exists, recreation was declined or creation failed.
|
||||||
|
:param force: Force recreation of the virtualenv
|
||||||
:param target: Path where to create the virtualenv at
|
:param target: Path where to create the virtualenv at
|
||||||
:return: bool
|
:return: bool
|
||||||
"""
|
"""
|
||||||
@@ -106,7 +111,7 @@ def create_python_venv(target: Path) -> bool:
|
|||||||
Logger.print_error(f"Error setting up virtualenv:\n{e}")
|
Logger.print_error(f"Error setting up virtualenv:\n{e}")
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
if not get_confirm(
|
if not force and not get_confirm(
|
||||||
"Virtualenv already exists. Re-create?", default_choice=False
|
"Virtualenv already exists. Re-create?", default_choice=False
|
||||||
):
|
):
|
||||||
Logger.print_info("Skipping re-creation of virtualenv ...")
|
Logger.print_info("Skipping re-creation of virtualenv ...")
|
||||||
@@ -174,14 +179,14 @@ def install_python_requirements(target: Path, requirements: Path) -> None:
|
|||||||
|
|
||||||
if result.returncode != 0 or result.stderr:
|
if result.returncode != 0 or result.stderr:
|
||||||
Logger.print_error(f"{result.stderr}", False)
|
Logger.print_error(f"{result.stderr}", False)
|
||||||
Logger.print_error("Installing Python requirements failed!")
|
raise VenvCreationFailedException("Installing Python requirements failed!")
|
||||||
return
|
|
||||||
|
|
||||||
Logger.print_ok("Installing Python requirements successful!")
|
Logger.print_ok("Installing Python requirements successful!")
|
||||||
except CalledProcessError as e:
|
|
||||||
log = f"Error installing Python requirements:\n{e.output.decode()}"
|
except Exception as e:
|
||||||
|
log = f"Error installing Python requirements: {e}"
|
||||||
Logger.print_error(log)
|
Logger.print_error(log)
|
||||||
raise
|
raise VenvCreationFailedException(log)
|
||||||
|
|
||||||
|
|
||||||
def update_system_package_lists(silent: bool, rls_info_change=False) -> None:
|
def update_system_package_lists(silent: bool, rls_info_change=False) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user