mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-25 00:33:37 +05:00
fix(mobileraker): fix typo and add more constants
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
@@ -9,8 +9,19 @@
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from core.backup_manager import BACKUP_ROOT_DIR
|
from core.backup_manager import BACKUP_ROOT_DIR
|
||||||
|
from utils.constants import SYSTEMD
|
||||||
|
|
||||||
|
# names
|
||||||
MOBILERAKER_REPO = "https://github.com/Clon1998/mobileraker_companion.git"
|
MOBILERAKER_REPO = "https://github.com/Clon1998/mobileraker_companion.git"
|
||||||
|
MOBILERAKER_UPDATER_SECTION_NAME = "update_manager mobileraker"
|
||||||
|
MOBILERAKER_LOG_NAME = "mobileraker.log"
|
||||||
|
|
||||||
|
# directories
|
||||||
MOBILERAKER_DIR = Path.home().joinpath("mobileraker_companion")
|
MOBILERAKER_DIR = Path.home().joinpath("mobileraker_companion")
|
||||||
MOBILERAKER_ENV = Path.home().joinpath("mobileraker-env")
|
|
||||||
MOBILERAKER_BACKUP_DIR = BACKUP_ROOT_DIR.joinpath("mobileraker-backups")
|
MOBILERAKER_BACKUP_DIR = BACKUP_ROOT_DIR.joinpath("mobileraker-backups")
|
||||||
|
|
||||||
|
# files
|
||||||
|
MOBILERAKER_ENV = Path.home().joinpath("mobileraker-env")
|
||||||
|
MOBILERAKER_INSTALL_SCRIPT = MOBILERAKER_DIR.joinpath("scripts/install.sh")
|
||||||
|
MOBILERAKER_REQ_FILE = MOBILERAKER_DIR.joinpath("scripts/mobileraker-requirements.txt")
|
||||||
|
MOBILERAKER_SERVICE_FILE = SYSTEMD.joinpath("mobileraker.service")
|
||||||
|
|||||||
@@ -16,7 +16,12 @@ from components.mobileraker import (
|
|||||||
MOBILERAKER_BACKUP_DIR,
|
MOBILERAKER_BACKUP_DIR,
|
||||||
MOBILERAKER_DIR,
|
MOBILERAKER_DIR,
|
||||||
MOBILERAKER_ENV,
|
MOBILERAKER_ENV,
|
||||||
|
MOBILERAKER_INSTALL_SCRIPT,
|
||||||
|
MOBILERAKER_LOG_NAME,
|
||||||
MOBILERAKER_REPO,
|
MOBILERAKER_REPO,
|
||||||
|
MOBILERAKER_REQ_FILE,
|
||||||
|
MOBILERAKER_SERVICE_FILE,
|
||||||
|
MOBILERAKER_UPDATER_SECTION_NAME,
|
||||||
)
|
)
|
||||||
from components.moonraker.moonraker import Moonraker
|
from components.moonraker.moonraker import Moonraker
|
||||||
from core.backup_manager.backup_manager import BackupManager
|
from core.backup_manager.backup_manager import BackupManager
|
||||||
@@ -24,7 +29,6 @@ from core.instance_manager.instance_manager import InstanceManager
|
|||||||
from core.settings.kiauh_settings import KiauhSettings
|
from core.settings.kiauh_settings import KiauhSettings
|
||||||
from utils.common import check_install_dependencies, get_install_status
|
from utils.common import check_install_dependencies, get_install_status
|
||||||
from utils.config_utils import add_config_section, remove_config_section
|
from utils.config_utils import add_config_section, remove_config_section
|
||||||
from utils.constants import SYSTEMD
|
|
||||||
from utils.fs_utils import remove_with_sudo
|
from utils.fs_utils import remove_with_sudo
|
||||||
from utils.git_utils import (
|
from utils.git_utils import (
|
||||||
git_clone_wrapper,
|
git_clone_wrapper,
|
||||||
@@ -72,8 +76,7 @@ def install_mobileraker() -> None:
|
|||||||
git_clone_wrapper(MOBILERAKER_REPO, MOBILERAKER_DIR)
|
git_clone_wrapper(MOBILERAKER_REPO, MOBILERAKER_DIR)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
script = f"{MOBILERAKER_DIR}/scripts/install.sh"
|
run(MOBILERAKER_INSTALL_SCRIPT.as_posix(), shell=True, check=True)
|
||||||
run(script, shell=True, check=True)
|
|
||||||
if mr_instances:
|
if mr_instances:
|
||||||
patch_mobileraker_update_manager(mr_instances)
|
patch_mobileraker_update_manager(mr_instances)
|
||||||
mr_im.restart_all_instance()
|
mr_im.restart_all_instance()
|
||||||
@@ -89,19 +92,18 @@ def install_mobileraker() -> None:
|
|||||||
|
|
||||||
|
|
||||||
def patch_mobileraker_update_manager(instances: List[Moonraker]) -> None:
|
def patch_mobileraker_update_manager(instances: List[Moonraker]) -> None:
|
||||||
env_py = f"{MOBILERAKER_ENV}/bin/python"
|
|
||||||
add_config_section(
|
add_config_section(
|
||||||
section="update_manager mobileraker",
|
section=MOBILERAKER_UPDATER_SECTION_NAME,
|
||||||
instances=instances,
|
instances=instances,
|
||||||
options=[
|
options=[
|
||||||
("type", "git_repo"),
|
("type", "git_repo"),
|
||||||
("path", "mobileraker_companion"),
|
("path", MOBILERAKER_DIR.as_posix()),
|
||||||
("orgin", MOBILERAKER_REPO),
|
("origin", MOBILERAKER_REPO),
|
||||||
("primary_branch", "main"),
|
("primary_branch", "main"),
|
||||||
("managed_services", "mobileraker"),
|
("managed_services", "mobileraker"),
|
||||||
("env", env_py),
|
("env", f"{MOBILERAKER_ENV}/bin/python"),
|
||||||
("requirements", "scripts/mobileraker-requirements.txt"),
|
("requirements", MOBILERAKER_REQ_FILE.as_posix()),
|
||||||
("install_script", "scripts/install.sh"),
|
("install_script", MOBILERAKER_INSTALL_SCRIPT.as_posix()),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -124,8 +126,7 @@ def update_mobileraker() -> None:
|
|||||||
|
|
||||||
git_pull_wrapper(MOBILERAKER_REPO, MOBILERAKER_DIR)
|
git_pull_wrapper(MOBILERAKER_REPO, MOBILERAKER_DIR)
|
||||||
|
|
||||||
requirements = MOBILERAKER_DIR.joinpath("/scripts/mobileraker-requirements.txt")
|
install_python_requirements(MOBILERAKER_ENV, MOBILERAKER_REQ_FILE)
|
||||||
install_python_requirements(MOBILERAKER_ENV, requirements)
|
|
||||||
|
|
||||||
cmd_sysctl_service("mobileraker", "start")
|
cmd_sysctl_service("mobileraker", "start")
|
||||||
|
|
||||||
@@ -139,7 +140,7 @@ def get_mobileraker_status() -> ComponentStatus:
|
|||||||
return get_install_status(
|
return get_install_status(
|
||||||
MOBILERAKER_DIR,
|
MOBILERAKER_DIR,
|
||||||
MOBILERAKER_ENV,
|
MOBILERAKER_ENV,
|
||||||
files=[SYSTEMD.joinpath("mobileraker.service")],
|
files=[MOBILERAKER_SERVICE_FILE],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -160,12 +161,11 @@ def remove_mobileraker() -> None:
|
|||||||
else:
|
else:
|
||||||
Logger.print_warn("Mobileraker's companion environment not found!")
|
Logger.print_warn("Mobileraker's companion environment not found!")
|
||||||
|
|
||||||
service = SYSTEMD.joinpath("mobileraker.service")
|
if MOBILERAKER_SERVICE_FILE.exists():
|
||||||
if service.exists():
|
|
||||||
Logger.print_status("Removing mobileraker service ...")
|
Logger.print_status("Removing mobileraker service ...")
|
||||||
cmd_sysctl_service(service, "stop")
|
cmd_sysctl_service(MOBILERAKER_SERVICE_FILE, "stop")
|
||||||
cmd_sysctl_service(service, "disable")
|
cmd_sysctl_service(MOBILERAKER_SERVICE_FILE, "disable")
|
||||||
remove_with_sudo(service)
|
remove_with_sudo(MOBILERAKER_SERVICE_FILE)
|
||||||
cmd_sysctl_manage("daemon-reload")
|
cmd_sysctl_manage("daemon-reload")
|
||||||
cmd_sysctl_manage("reset-failed")
|
cmd_sysctl_manage("reset-failed")
|
||||||
Logger.print_ok("Mobileraker's companion service successfully removed!")
|
Logger.print_ok("Mobileraker's companion service successfully removed!")
|
||||||
@@ -173,7 +173,7 @@ def remove_mobileraker() -> None:
|
|||||||
kl_im = InstanceManager(Klipper)
|
kl_im = InstanceManager(Klipper)
|
||||||
kl_instances: List[Klipper] = kl_im.instances
|
kl_instances: List[Klipper] = kl_im.instances
|
||||||
for instance in kl_instances:
|
for instance in kl_instances:
|
||||||
logfile = instance.log_dir.joinpath("mobileraker.log")
|
logfile = instance.log_dir.joinpath(MOBILERAKER_LOG_NAME)
|
||||||
if logfile.exists():
|
if logfile.exists():
|
||||||
Logger.print_status(f"Removing {logfile} ...")
|
Logger.print_status(f"Removing {logfile} ...")
|
||||||
Path(logfile).unlink()
|
Path(logfile).unlink()
|
||||||
@@ -185,7 +185,7 @@ def remove_mobileraker() -> None:
|
|||||||
Logger.print_status(
|
Logger.print_status(
|
||||||
"Removing Mobileraker's companion from update manager ..."
|
"Removing Mobileraker's companion from update manager ..."
|
||||||
)
|
)
|
||||||
remove_config_section("update_manager mobileraker", mr_instances)
|
remove_config_section(MOBILERAKER_UPDATER_SECTION_NAME, mr_instances)
|
||||||
Logger.print_ok(
|
Logger.print_ok(
|
||||||
"Mobileraker's companion successfully removed from update manager!"
|
"Mobileraker's companion successfully removed from update manager!"
|
||||||
)
|
)
|
||||||
@@ -199,12 +199,12 @@ def remove_mobileraker() -> None:
|
|||||||
def backup_mobileraker_dir() -> None:
|
def backup_mobileraker_dir() -> None:
|
||||||
bm = BackupManager()
|
bm = BackupManager()
|
||||||
bm.backup_directory(
|
bm.backup_directory(
|
||||||
"mobileraker_companion",
|
MOBILERAKER_DIR.name,
|
||||||
source=MOBILERAKER_DIR,
|
source=MOBILERAKER_DIR,
|
||||||
target=MOBILERAKER_BACKUP_DIR,
|
target=MOBILERAKER_BACKUP_DIR,
|
||||||
)
|
)
|
||||||
bm.backup_directory(
|
bm.backup_directory(
|
||||||
"mobileraker-env",
|
MOBILERAKER_ENV.name,
|
||||||
source=MOBILERAKER_ENV,
|
source=MOBILERAKER_ENV,
|
||||||
target=MOBILERAKER_BACKUP_DIR,
|
target=MOBILERAKER_BACKUP_DIR,
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user