mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-23 15:53:36 +05:00
Compare commits
9 Commits
9864dd0c7f
...
bf0385e3c9
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bf0385e3c9 | ||
|
|
750bf1caaf | ||
|
|
27455dfc64 | ||
|
|
940f7cfbf1 | ||
|
|
e5d0e97b82 | ||
|
|
799892500a | ||
|
|
5f1e42b88b | ||
|
|
09dc961646 | ||
|
|
40e382c9a1 |
@@ -30,7 +30,7 @@ from utils.input_utils import get_confirm
|
||||
from utils.logger import Logger
|
||||
from utils.sys_utils import (
|
||||
parse_packages_from_file,
|
||||
control_systemd_service,
|
||||
cmd_sysctl_service,
|
||||
)
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ def install_crowsnest() -> None:
|
||||
|
||||
def update_crowsnest() -> None:
|
||||
try:
|
||||
control_systemd_service("crowsnest", "stop")
|
||||
cmd_sysctl_service("crowsnest", "stop")
|
||||
|
||||
if not CROWSNEST_DIR.exists():
|
||||
git_clone_wrapper(CROWSNEST_REPO, CROWSNEST_DIR, "master")
|
||||
@@ -111,7 +111,7 @@ def update_crowsnest() -> None:
|
||||
deps = parse_packages_from_file(script)
|
||||
check_install_dependencies(deps)
|
||||
|
||||
control_systemd_service("crowsnest", "restart")
|
||||
cmd_sysctl_service("crowsnest", "restart")
|
||||
|
||||
Logger.print_ok("Crowsnest updated successfully.", end="\n\n")
|
||||
except CalledProcessError as e:
|
||||
|
||||
@@ -45,7 +45,7 @@ from utils.constants import CURRENT_USER
|
||||
from utils.git_utils import get_repo_name, get_remote_commit, get_local_commit
|
||||
from utils.input_utils import get_confirm, get_string_input, get_number_input
|
||||
from utils.logger import Logger
|
||||
from utils.sys_utils import control_systemd_service
|
||||
from utils.sys_utils import cmd_sysctl_service
|
||||
|
||||
|
||||
def get_klipper_status() -> (
|
||||
@@ -258,7 +258,7 @@ def handle_disruptive_system_packages() -> None:
|
||||
|
||||
for service in services if services else []:
|
||||
try:
|
||||
control_systemd_service(service, "mask")
|
||||
cmd_sysctl_service(service, "mask")
|
||||
except subprocess.CalledProcessError:
|
||||
warn_msg = textwrap.dedent(
|
||||
f"""
|
||||
|
||||
@@ -34,11 +34,12 @@ from utils.git_utils import (
|
||||
get_remote_commit,
|
||||
)
|
||||
from utils.input_utils import get_confirm
|
||||
from utils.logger import Logger
|
||||
from utils.logger import Logger, DialogType
|
||||
from utils.sys_utils import (
|
||||
check_python_version,
|
||||
control_systemd_service,
|
||||
cmd_sysctl_service,
|
||||
install_python_requirements,
|
||||
cmd_sysctl_manage,
|
||||
)
|
||||
|
||||
|
||||
@@ -51,10 +52,16 @@ def install_klipperscreen() -> None:
|
||||
mr_im = InstanceManager(Moonraker)
|
||||
mr_instances = mr_im.instances
|
||||
if not mr_instances:
|
||||
# TODO: add moonraker not found dialog
|
||||
print("Moonraker not found!")
|
||||
warn_msg = [
|
||||
"Moonraker not found! KlipperScreen will not properly work "
|
||||
"without a working Moonraker installation.",
|
||||
"KlipperScreens update manager configuration for Moonraker "
|
||||
"will not be added to any moonraker.conf.",
|
||||
]
|
||||
Logger.print_dialog(DialogType.WARNING, warn_msg)
|
||||
if not get_confirm(
|
||||
"Continue KlipperScreen installation?",
|
||||
default_choice=False,
|
||||
allow_go_back=True,
|
||||
):
|
||||
return
|
||||
@@ -98,7 +105,7 @@ def patch_klipperscreen_update_manager(instances: List[Moonraker]) -> None:
|
||||
|
||||
def update_klipperscreen() -> None:
|
||||
try:
|
||||
control_systemd_service("KlipperScreen", "stop")
|
||||
cmd_sysctl_service("KlipperScreen", "stop")
|
||||
|
||||
if not KLIPPERSCREEN_DIR.exists():
|
||||
Logger.print_info(
|
||||
@@ -108,7 +115,7 @@ def update_klipperscreen() -> None:
|
||||
|
||||
Logger.print_status("Updating KlipperScreen ...")
|
||||
|
||||
control_systemd_service("KlipperScreen", "stop")
|
||||
cmd_sysctl_service("KlipperScreen", "stop")
|
||||
|
||||
settings = KiauhSettings()
|
||||
if settings.get("kiauh", "backup_before_update"):
|
||||
@@ -121,11 +128,11 @@ def update_klipperscreen() -> None:
|
||||
)
|
||||
install_python_requirements(KLIPPERSCREEN_ENV, requirements)
|
||||
|
||||
control_systemd_service("KlipperScreen", "start")
|
||||
cmd_sysctl_service("KlipperScreen", "start")
|
||||
|
||||
Logger.print_ok("KlipperScreen updated successfully.", end="\n\n")
|
||||
except CalledProcessError as e:
|
||||
Logger.print_error(f"Something went wrong! Please try again...\n{e}")
|
||||
Logger.print_error(f"Error updating KlipperScreen:\n{e}")
|
||||
return
|
||||
|
||||
|
||||
@@ -170,9 +177,11 @@ def remove_klipperscreen() -> None:
|
||||
service = SYSTEMD.joinpath("KlipperScreen.service")
|
||||
if service.exists():
|
||||
Logger.print_status("Removing KlipperScreen service ...")
|
||||
control_systemd_service(service, "stop")
|
||||
control_systemd_service(service, "disable")
|
||||
cmd_sysctl_service(service, "stop")
|
||||
cmd_sysctl_service(service, "disable")
|
||||
remove_with_sudo(service)
|
||||
cmd_sysctl_manage("deamon-reload")
|
||||
cmd_sysctl_manage("reset-failed")
|
||||
Logger.print_ok("KlipperScreen service successfully removed!")
|
||||
|
||||
logfile = Path("/tmp/KlipperScreen.log")
|
||||
@@ -206,8 +215,12 @@ def remove_klipperscreen() -> None:
|
||||
def backup_klipperscreen_dir() -> None:
|
||||
bm = BackupManager()
|
||||
bm.backup_directory(
|
||||
"KlipperScreen", source=KLIPPERSCREEN_DIR, target=KLIPPERSCREEN_BACKUP_DIR
|
||||
"KlipperScreen",
|
||||
source=KLIPPERSCREEN_DIR,
|
||||
target=KLIPPERSCREEN_BACKUP_DIR,
|
||||
)
|
||||
bm.backup_directory(
|
||||
"KlipperScreen-env", source=KLIPPERSCREEN_ENV, target=KLIPPERSCREEN_BACKUP_DIR
|
||||
"KlipperScreen-env",
|
||||
source=KLIPPERSCREEN_ENV,
|
||||
target=KLIPPERSCREEN_BACKUP_DIR,
|
||||
)
|
||||
|
||||
16
kiauh/components/mobileraker/__init__.py
Normal file
16
kiauh/components/mobileraker/__init__.py
Normal file
@@ -0,0 +1,16 @@
|
||||
# ======================================================================= #
|
||||
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/dw-0/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
# ======================================================================= #
|
||||
from pathlib import Path
|
||||
|
||||
from core.backup_manager import BACKUP_ROOT_DIR
|
||||
|
||||
MOBILERAKER_REPO = "https://github.com/Clon1998/mobileraker_companion.git"
|
||||
MOBILERAKER_DIR = Path.home().joinpath("mobileraker_companion")
|
||||
MOBILERAKER_ENV = Path.home().joinpath("mobileraker-env")
|
||||
MOBILERAKER_BACKUP_DIR = BACKUP_ROOT_DIR.joinpath("mobileraker-backups")
|
||||
224
kiauh/components/mobileraker/mobileraker.py
Normal file
224
kiauh/components/mobileraker/mobileraker.py
Normal file
@@ -0,0 +1,224 @@
|
||||
# ======================================================================= #
|
||||
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/dw-0/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
# ======================================================================= #
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
from subprocess import run, CalledProcessError
|
||||
from typing import List, Dict, Literal, Union
|
||||
|
||||
from components.klipper.klipper import Klipper
|
||||
from components.mobileraker import (
|
||||
MOBILERAKER_REPO,
|
||||
MOBILERAKER_DIR,
|
||||
MOBILERAKER_ENV,
|
||||
MOBILERAKER_BACKUP_DIR,
|
||||
)
|
||||
from components.moonraker.moonraker import Moonraker
|
||||
from core.backup_manager.backup_manager import BackupManager
|
||||
from core.instance_manager.instance_manager import InstanceManager
|
||||
from core.settings.kiauh_settings import KiauhSettings
|
||||
from utils.common import get_install_status, check_install_dependencies
|
||||
from utils.config_utils import add_config_section, remove_config_section
|
||||
from utils.constants import SYSTEMD
|
||||
from utils.fs_utils import remove_with_sudo
|
||||
from utils.git_utils import (
|
||||
git_clone_wrapper,
|
||||
git_pull_wrapper,
|
||||
get_repo_name,
|
||||
get_local_commit,
|
||||
get_remote_commit,
|
||||
)
|
||||
from utils.input_utils import get_confirm
|
||||
from utils.logger import Logger, DialogType
|
||||
from utils.sys_utils import (
|
||||
check_python_version,
|
||||
cmd_sysctl_service,
|
||||
install_python_requirements,
|
||||
cmd_sysctl_manage,
|
||||
)
|
||||
|
||||
|
||||
def install_mobileraker() -> None:
|
||||
Logger.print_status("Installing Mobileraker's companion ...")
|
||||
|
||||
if not check_python_version(3, 7):
|
||||
return
|
||||
|
||||
mr_im = InstanceManager(Moonraker)
|
||||
mr_instances = mr_im.instances
|
||||
if not mr_instances:
|
||||
warn_msg = [
|
||||
"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.",
|
||||
]
|
||||
Logger.print_dialog(DialogType.WARNING, warn_msg)
|
||||
if not get_confirm(
|
||||
"Continue Mobileraker's companion installation?",
|
||||
default_choice=False,
|
||||
allow_go_back=True,
|
||||
):
|
||||
return
|
||||
|
||||
package_list = ["wget", "curl", "unzip", "dfu-util"]
|
||||
check_install_dependencies(package_list)
|
||||
|
||||
git_clone_wrapper(MOBILERAKER_REPO, MOBILERAKER_DIR)
|
||||
|
||||
try:
|
||||
script = f"{MOBILERAKER_DIR}/scripts/install.sh"
|
||||
run(script, shell=True, check=True)
|
||||
if mr_instances:
|
||||
patch_mobileraker_update_manager(mr_instances)
|
||||
mr_im.restart_all_instance()
|
||||
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:
|
||||
env_py = f"{MOBILERAKER_ENV}/bin/python"
|
||||
add_config_section(
|
||||
section="update_manager mobileraker",
|
||||
instances=instances,
|
||||
options=[
|
||||
("type", "git_repo"),
|
||||
("path", "mobileraker_companion"),
|
||||
("orgin", MOBILERAKER_REPO),
|
||||
("primary_branch", "main"),
|
||||
("managed_services", "mobileraker"),
|
||||
("env", env_py),
|
||||
("requirements", "scripts/mobileraker-requirements.txt"),
|
||||
("install_script", "scripts/install.sh"),
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
def update_mobileraker() -> None:
|
||||
try:
|
||||
cmd_sysctl_service("KlipperScreen", "stop")
|
||||
|
||||
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", "stop")
|
||||
|
||||
settings = KiauhSettings()
|
||||
if settings.get("kiauh", "backup_before_update"):
|
||||
backup_mobileraker_dir()
|
||||
|
||||
git_pull_wrapper(MOBILERAKER_REPO, MOBILERAKER_DIR)
|
||||
|
||||
requirements = MOBILERAKER_DIR.joinpath("/scripts/mobileraker-requirements.txt")
|
||||
install_python_requirements(MOBILERAKER_ENV, requirements)
|
||||
|
||||
cmd_sysctl_service("mobileraker", "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() -> (
|
||||
Dict[
|
||||
Literal["status", "status_code", "repo", "local", "remote"],
|
||||
Union[str, int],
|
||||
]
|
||||
):
|
||||
files = [
|
||||
MOBILERAKER_DIR,
|
||||
MOBILERAKER_ENV,
|
||||
SYSTEMD.joinpath("mobileraker.service"),
|
||||
]
|
||||
status = get_install_status(MOBILERAKER_DIR, files)
|
||||
return {
|
||||
"status": status.get("status"),
|
||||
"status_code": status.get("status_code"),
|
||||
"repo": get_repo_name(MOBILERAKER_DIR),
|
||||
"local": get_local_commit(MOBILERAKER_DIR),
|
||||
"remote": get_remote_commit(MOBILERAKER_DIR),
|
||||
}
|
||||
|
||||
|
||||
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.exists():
|
||||
Logger.print_status("Removing Mobileraker's companion environment ...")
|
||||
shutil.rmtree(MOBILERAKER_ENV)
|
||||
Logger.print_ok("Mobileraker's companion environment successfully removed!")
|
||||
else:
|
||||
Logger.print_warn("Mobileraker's companion environment not found!")
|
||||
|
||||
service = SYSTEMD.joinpath("mobileraker.service")
|
||||
if service.exists():
|
||||
Logger.print_status("Removing mobileraker service ...")
|
||||
cmd_sysctl_service(service, "stop")
|
||||
cmd_sysctl_service(service, "disable")
|
||||
remove_with_sudo(service)
|
||||
cmd_sysctl_manage("deamon-reload")
|
||||
cmd_sysctl_manage("reset-failed")
|
||||
Logger.print_ok("Mobileraker's companion service successfully removed!")
|
||||
|
||||
kl_im = InstanceManager(Klipper)
|
||||
kl_instances: List[Klipper] = kl_im.instances
|
||||
for instance in kl_instances:
|
||||
logfile = instance.log_dir.joinpath("mobileraker.log")
|
||||
if logfile.exists():
|
||||
Logger.print_status(f"Removing {logfile} ...")
|
||||
Path(logfile).unlink()
|
||||
Logger.print_ok(f"{logfile} successfully removed!")
|
||||
|
||||
mr_im = InstanceManager(Moonraker)
|
||||
mr_instances: List[Moonraker] = mr_im.instances
|
||||
if mr_instances:
|
||||
Logger.print_status(
|
||||
"Removing Mobileraker's companion from update manager ..."
|
||||
)
|
||||
remove_config_section("update_manager mobileraker", 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_companion",
|
||||
source=MOBILERAKER_DIR,
|
||||
target=MOBILERAKER_BACKUP_DIR,
|
||||
)
|
||||
bm.backup_directory(
|
||||
"mobileraker-env",
|
||||
source=MOBILERAKER_ENV,
|
||||
target=MOBILERAKER_BACKUP_DIR,
|
||||
)
|
||||
@@ -55,7 +55,7 @@ from utils.sys_utils import (
|
||||
download_file,
|
||||
set_nginx_permissions,
|
||||
get_ipv4_addr,
|
||||
control_systemd_service,
|
||||
cmd_sysctl_service,
|
||||
)
|
||||
|
||||
|
||||
@@ -145,7 +145,7 @@ def install_client(client: BaseWebClient) -> None:
|
||||
create_client_nginx_cfg(client, port)
|
||||
if kl_instances:
|
||||
symlink_webui_nginx_log(kl_instances)
|
||||
control_systemd_service("nginx", "restart")
|
||||
cmd_sysctl_service("nginx", "restart")
|
||||
|
||||
except Exception as e:
|
||||
Logger.print_error(f"{client.display_name} installation failed!\n{e}")
|
||||
|
||||
@@ -35,13 +35,18 @@ from utils.git_utils import (
|
||||
from utils.logger import Logger
|
||||
|
||||
|
||||
def get_client_status(client: BaseWebClient) -> str:
|
||||
return get_install_status_webui(
|
||||
def get_client_status(
|
||||
client: BaseWebClient, fetch_remote: bool = False
|
||||
) -> Dict[Literal["status", "local", "remote"], str]:
|
||||
status = get_install_status_webui(
|
||||
client.client_dir,
|
||||
NGINX_SITES_AVAILABLE.joinpath(client.name),
|
||||
NGINX_CONFD.joinpath("upstreams.conf"),
|
||||
NGINX_CONFD.joinpath("common_vars.conf"),
|
||||
)
|
||||
local = get_local_client_version(client)
|
||||
remote = get_remote_client_version(client) if fetch_remote else None
|
||||
return {"status": status, "local": local, "remote": remote}
|
||||
|
||||
|
||||
def get_client_config_status(
|
||||
|
||||
@@ -15,7 +15,7 @@ from typing import List, Optional, Union, TypeVar
|
||||
from core.instance_manager.base_instance import BaseInstance
|
||||
from utils.constants import SYSTEMD
|
||||
from utils.logger import Logger
|
||||
from utils.sys_utils import control_systemd_service
|
||||
from utils.sys_utils import cmd_sysctl_service
|
||||
|
||||
T = TypeVar(name="T", bound=BaseInstance, covariant=True)
|
||||
|
||||
@@ -109,7 +109,7 @@ class InstanceManager:
|
||||
def enable_instance(self) -> None:
|
||||
Logger.print_status(f"Enabling {self.instance_service_full} ...")
|
||||
try:
|
||||
control_systemd_service(self.instance_service_full, "enable")
|
||||
cmd_sysctl_service(self.instance_service_full, "enable")
|
||||
except subprocess.CalledProcessError as e:
|
||||
Logger.print_error(f"Error enabling service {self.instance_service_full}:")
|
||||
Logger.print_error(f"{e}")
|
||||
@@ -117,7 +117,7 @@ class InstanceManager:
|
||||
def disable_instance(self) -> None:
|
||||
Logger.print_status(f"Disabling {self.instance_service_full} ...")
|
||||
try:
|
||||
control_systemd_service(self.instance_service_full, "disable")
|
||||
cmd_sysctl_service(self.instance_service_full, "disable")
|
||||
except subprocess.CalledProcessError as e:
|
||||
Logger.print_error(f"Error disabling {self.instance_service_full}:")
|
||||
Logger.print_error(f"{e}")
|
||||
@@ -125,7 +125,7 @@ class InstanceManager:
|
||||
def start_instance(self) -> None:
|
||||
Logger.print_status(f"Starting {self.instance_service_full} ...")
|
||||
try:
|
||||
control_systemd_service(self.instance_service_full, "start")
|
||||
cmd_sysctl_service(self.instance_service_full, "start")
|
||||
except subprocess.CalledProcessError as e:
|
||||
Logger.print_error(f"Error starting {self.instance_service_full}:")
|
||||
Logger.print_error(f"{e}")
|
||||
@@ -133,7 +133,7 @@ class InstanceManager:
|
||||
def restart_instance(self) -> None:
|
||||
Logger.print_status(f"Restarting {self.instance_service_full} ...")
|
||||
try:
|
||||
control_systemd_service(self.instance_service_full, "restart")
|
||||
cmd_sysctl_service(self.instance_service_full, "restart")
|
||||
except subprocess.CalledProcessError as e:
|
||||
Logger.print_error(f"Error restarting {self.instance_service_full}:")
|
||||
Logger.print_error(f"{e}")
|
||||
@@ -151,7 +151,7 @@ class InstanceManager:
|
||||
def stop_instance(self) -> None:
|
||||
Logger.print_status(f"Stopping {self.instance_service_full} ...")
|
||||
try:
|
||||
control_systemd_service(self.instance_service_full, "stop")
|
||||
cmd_sysctl_service(self.instance_service_full, "stop")
|
||||
except subprocess.CalledProcessError as e:
|
||||
Logger.print_error(f"Error stopping {self.instance_service_full}:")
|
||||
Logger.print_error(f"{e}")
|
||||
|
||||
@@ -13,6 +13,7 @@ from typing import Type, Optional
|
||||
from components.crowsnest.crowsnest import install_crowsnest
|
||||
from components.klipper import klipper_setup
|
||||
from components.klipperscreen.klipperscreen import install_klipperscreen
|
||||
from components.mobileraker.mobileraker import install_mobileraker
|
||||
from components.moonraker import moonraker_setup
|
||||
from components.webui_client import client_setup
|
||||
from components.webui_client.client_config import client_config_setup
|
||||
@@ -47,6 +48,7 @@ class InstallMenu(BaseMenu):
|
||||
"5": Option(method=self.install_mainsail_config, menu=False),
|
||||
"6": Option(method=self.install_fluidd_config, menu=False),
|
||||
"7": Option(method=self.install_klipperscreen, menu=False),
|
||||
"8": Option(method=self.install_mobileraker, menu=False),
|
||||
"9": Option(method=self.install_crowsnest, menu=False),
|
||||
}
|
||||
|
||||
@@ -96,5 +98,8 @@ class InstallMenu(BaseMenu):
|
||||
def install_klipperscreen(self, **kwargs):
|
||||
install_klipperscreen()
|
||||
|
||||
def install_mobileraker(self, **kwargs):
|
||||
install_mobileraker()
|
||||
|
||||
def install_crowsnest(self, **kwargs):
|
||||
install_crowsnest()
|
||||
|
||||
@@ -14,6 +14,7 @@ from components.crowsnest.crowsnest import get_crowsnest_status
|
||||
from components.klipper.klipper_utils import get_klipper_status
|
||||
from components.klipperscreen.klipperscreen import get_klipperscreen_status
|
||||
from components.log_uploads.menus.log_upload_menu import LogUploadMenu
|
||||
from components.mobileraker.mobileraker import get_mobileraker_status
|
||||
from components.moonraker.moonraker_utils import get_moonraker_status
|
||||
from components.webui_client.client_utils import (
|
||||
get_client_status,
|
||||
@@ -49,16 +50,9 @@ class MainMenu(BaseMenu):
|
||||
self.header = True
|
||||
self.footer_type = FooterType.QUIT
|
||||
|
||||
self.kl_status = ""
|
||||
self.kl_repo = ""
|
||||
self.mr_status = ""
|
||||
self.mr_repo = ""
|
||||
self.ms_status = ""
|
||||
self.fl_status = ""
|
||||
self.ks_status = ""
|
||||
self.mb_status = ""
|
||||
self.cn_status = ""
|
||||
self.cc_status = ""
|
||||
self.kl_status = self.kl_repo = self.mr_status = self.mr_repo = ""
|
||||
self.ms_status = self.fl_status = self.ks_status = self.mb_status = ""
|
||||
self.cn_status = self.cc_status = ""
|
||||
self.init_status()
|
||||
|
||||
def set_previous_menu(self, previous_menu: Optional[Type[BaseMenu]]) -> None:
|
||||
@@ -87,18 +81,20 @@ class MainMenu(BaseMenu):
|
||||
)
|
||||
|
||||
def fetch_status(self) -> None:
|
||||
self._update_status("kl", get_klipper_status)
|
||||
self._update_status("mr", get_moonraker_status)
|
||||
self.ms_status = get_client_status(MainsailData())
|
||||
self.fl_status = get_client_status(FluiddData())
|
||||
self._get_component_status("kl", get_klipper_status)
|
||||
self._get_component_status("mr", get_moonraker_status)
|
||||
self._get_component_status("ms", get_client_status, MainsailData())
|
||||
self._get_component_status("fl", get_client_status, FluiddData())
|
||||
self.cc_status = get_current_client_config([MainsailData(), FluiddData()])
|
||||
self._update_status("ks", get_klipperscreen_status)
|
||||
self._update_status("cn", get_crowsnest_status)
|
||||
self._get_component_status("ks", get_klipperscreen_status)
|
||||
self._get_component_status("mb", get_mobileraker_status)
|
||||
self._get_component_status("cn", get_crowsnest_status)
|
||||
|
||||
def _update_status(self, status_name: str, status_fn: callable) -> None:
|
||||
status_data = status_fn()
|
||||
def _get_component_status(self, name: str, status_fn: callable, *args) -> None:
|
||||
status_data = status_fn(*args)
|
||||
status = status_data.get("status")
|
||||
code = status_data.get("status_code")
|
||||
repo = status_data.get("repo")
|
||||
|
||||
instance_count = status_data.get("instances")
|
||||
|
||||
@@ -106,18 +102,10 @@ class MainMenu(BaseMenu):
|
||||
if instance_count and code == 1:
|
||||
count = f" {instance_count}"
|
||||
|
||||
setattr(
|
||||
self,
|
||||
f"{status_name}_status",
|
||||
self._format_status_by_code(code, status, count),
|
||||
)
|
||||
setattr(
|
||||
self,
|
||||
f"{status_name}_repo",
|
||||
f"{COLOR_CYAN}{status_data.get('repo')}{RESET_FORMAT}",
|
||||
)
|
||||
setattr(self, f"{name}_status", self._format_by_code(code, status, count))
|
||||
setattr(self, f"{name}_repo", f"{COLOR_CYAN}{repo}{RESET_FORMAT}")
|
||||
|
||||
def _format_status_by_code(self, code: int, status: str, count: str) -> str:
|
||||
def _format_by_code(self, code: int, status: str, count: str) -> str:
|
||||
if code == 1:
|
||||
return f"{COLOR_GREEN}{status}{count}{RESET_FORMAT}"
|
||||
elif code == 2:
|
||||
@@ -144,8 +132,8 @@ class MainMenu(BaseMenu):
|
||||
| 2) [Update] | Moonraker: {self.mr_status:<32} |
|
||||
| 3) [Remove] | Repo: {self.mr_repo:<32} |
|
||||
| 4) [Advanced] |------------------------------------|
|
||||
| 5) [Backup] | Mainsail: {self.ms_status:<26} |
|
||||
| | Fluidd: {self.fl_status:<26} |
|
||||
| 5) [Backup] | Mainsail: {self.ms_status:<35} |
|
||||
| | Fluidd: {self.fl_status:<35} |
|
||||
| S) [Settings] | Client-Config: {self.cc_status:<26} |
|
||||
| | |
|
||||
| Community: | KlipperScreen: {self.ks_status:<26} |
|
||||
|
||||
@@ -13,6 +13,7 @@ from typing import Type, Optional
|
||||
from components.crowsnest.crowsnest import remove_crowsnest
|
||||
from components.klipper.menus.klipper_remove_menu import KlipperRemoveMenu
|
||||
from components.klipperscreen.klipperscreen import remove_klipperscreen
|
||||
from components.mobileraker.mobileraker import remove_mobileraker
|
||||
from components.moonraker.menus.moonraker_remove_menu import (
|
||||
MoonrakerRemoveMenu,
|
||||
)
|
||||
@@ -45,7 +46,8 @@ class RemoveMenu(BaseMenu):
|
||||
"3": Option(method=self.remove_mainsail, menu=True),
|
||||
"4": Option(method=self.remove_fluidd, menu=True),
|
||||
"5": Option(method=self.remove_klipperscreen, menu=True),
|
||||
"6": Option(method=self.remove_crowsnest, menu=True),
|
||||
"6": Option(method=self.remove_mobileraker, menu=True),
|
||||
"7": Option(method=self.remove_crowsnest, menu=True),
|
||||
}
|
||||
|
||||
def print_menu(self):
|
||||
@@ -62,11 +64,11 @@ class RemoveMenu(BaseMenu):
|
||||
| Firmware & API: | Touchscreen GUI: |
|
||||
| 1) [Klipper] | 5) [KlipperScreen] |
|
||||
| 2) [Moonraker] | |
|
||||
| | Webcam Streamer: |
|
||||
| Klipper Webinterface: | 6) [Crowsnest] |
|
||||
| | Android / iOS: |
|
||||
| Klipper Webinterface: | 6) [Mobileraker] |
|
||||
| 3) [Mainsail] | |
|
||||
| 4) [Fluidd] | |
|
||||
| | |
|
||||
| 4) [Fluidd] | Webcam Streamer: |
|
||||
| | 7) [Crowsnest] |
|
||||
"""
|
||||
)[1:]
|
||||
print(menu, end="")
|
||||
@@ -86,5 +88,8 @@ class RemoveMenu(BaseMenu):
|
||||
def remove_klipperscreen(self, **kwargs):
|
||||
remove_klipperscreen()
|
||||
|
||||
def remove_mobileraker(self, **kwargs):
|
||||
remove_mobileraker()
|
||||
|
||||
def remove_crowsnest(self, **kwargs):
|
||||
remove_crowsnest()
|
||||
|
||||
@@ -19,6 +19,10 @@ from components.klipperscreen.klipperscreen import (
|
||||
update_klipperscreen,
|
||||
get_klipperscreen_status,
|
||||
)
|
||||
from components.mobileraker.mobileraker import (
|
||||
update_mobileraker,
|
||||
get_mobileraker_status,
|
||||
)
|
||||
from components.moonraker.moonraker_setup import update_moonraker
|
||||
from components.moonraker.moonraker_utils import get_moonraker_status
|
||||
from components.webui_client.client_config.client_config_setup import (
|
||||
@@ -26,9 +30,8 @@ from components.webui_client.client_config.client_config_setup import (
|
||||
)
|
||||
from components.webui_client.client_setup import update_client
|
||||
from components.webui_client.client_utils import (
|
||||
get_local_client_version,
|
||||
get_remote_client_version,
|
||||
get_client_config_status,
|
||||
get_client_status,
|
||||
)
|
||||
from components.webui_client.fluidd_data import FluiddData
|
||||
from components.webui_client.mainsail_data import MainsailData
|
||||
@@ -38,7 +41,6 @@ from utils.constants import (
|
||||
COLOR_GREEN,
|
||||
RESET_FORMAT,
|
||||
COLOR_YELLOW,
|
||||
COLOR_WHITE,
|
||||
COLOR_RED,
|
||||
)
|
||||
|
||||
@@ -50,25 +52,15 @@ class UpdateMenu(BaseMenu):
|
||||
super().__init__()
|
||||
self.previous_menu = previous_menu
|
||||
|
||||
self.kl_local = f"{COLOR_WHITE}{RESET_FORMAT}"
|
||||
self.kl_remote = f"{COLOR_WHITE}{RESET_FORMAT}"
|
||||
self.mr_local = f"{COLOR_WHITE}{RESET_FORMAT}"
|
||||
self.mr_remote = f"{COLOR_WHITE}{RESET_FORMAT}"
|
||||
self.ms_local = f"{COLOR_WHITE}{RESET_FORMAT}"
|
||||
self.ms_remote = f"{COLOR_WHITE}{RESET_FORMAT}"
|
||||
self.fl_local = f"{COLOR_WHITE}{RESET_FORMAT}"
|
||||
self.fl_remote = f"{COLOR_WHITE}{RESET_FORMAT}"
|
||||
self.mc_local = f"{COLOR_WHITE}{RESET_FORMAT}"
|
||||
self.mc_remote = f"{COLOR_WHITE}{RESET_FORMAT}"
|
||||
self.fc_local = f"{COLOR_WHITE}{RESET_FORMAT}"
|
||||
self.fc_remote = f"{COLOR_WHITE}{RESET_FORMAT}"
|
||||
self.ks_local = f"{COLOR_WHITE}{RESET_FORMAT}"
|
||||
self.ks_remote = f"{COLOR_WHITE}{RESET_FORMAT}"
|
||||
self.cn_local = f"{COLOR_WHITE}{RESET_FORMAT}"
|
||||
self.cn_remote = f"{COLOR_WHITE}{RESET_FORMAT}"
|
||||
self.kl_local = self.kl_remote = self.mr_local = self.mr_remote = ""
|
||||
self.ms_local = self.ms_remote = self.fl_local = self.fl_remote = ""
|
||||
self.mc_local = self.mc_remote = self.fc_local = self.fc_remote = ""
|
||||
self.ks_local = self.ks_remote = self.mb_local = self.mb_remote = ""
|
||||
self.cn_local = self.cn_remote = ""
|
||||
|
||||
self.mainsail_client = MainsailData()
|
||||
self.fluidd_client = FluiddData()
|
||||
self.mainsail_data = MainsailData()
|
||||
self.fluidd_data = FluiddData()
|
||||
self._fetch_update_status()
|
||||
|
||||
def set_previous_menu(self, previous_menu: Optional[Type[BaseMenu]]) -> None:
|
||||
from core.menus.main_menu import MainMenu
|
||||
@@ -93,7 +85,7 @@ class UpdateMenu(BaseMenu):
|
||||
}
|
||||
|
||||
def print_menu(self):
|
||||
self.fetch_update_status()
|
||||
self._fetch_update_status()
|
||||
|
||||
header = " [ Update Menu ] "
|
||||
color = COLOR_GREEN
|
||||
@@ -119,7 +111,7 @@ class UpdateMenu(BaseMenu):
|
||||
| | | |
|
||||
| Other: |---------------|---------------|
|
||||
| 7) KlipperScreen | {self.ks_local:<22} | {self.ks_remote:<22} |
|
||||
| 8) Mobileraker | | |
|
||||
| 8) Mobileraker | {self.mb_local:<22} | {self.mb_remote:<22} |
|
||||
| 9) Crowsnest | {self.cn_local:<22} | {self.cn_remote:<22} |
|
||||
| |-------------------------------|
|
||||
| 10) System | |
|
||||
@@ -137,84 +129,57 @@ class UpdateMenu(BaseMenu):
|
||||
update_moonraker()
|
||||
|
||||
def update_mainsail(self, **kwargs):
|
||||
update_client(self.mainsail_client)
|
||||
update_client(self.mainsail_data)
|
||||
|
||||
def update_mainsail_config(self, **kwargs):
|
||||
update_client_config(self.mainsail_client)
|
||||
update_client_config(self.mainsail_data)
|
||||
|
||||
def update_fluidd(self, **kwargs):
|
||||
update_client(self.fluidd_client)
|
||||
update_client(self.fluidd_data)
|
||||
|
||||
def update_fluidd_config(self, **kwargs):
|
||||
update_client_config(self.fluidd_client)
|
||||
update_client_config(self.fluidd_data)
|
||||
|
||||
def update_klipperscreen(self, **kwargs):
|
||||
update_klipperscreen()
|
||||
|
||||
def update_mobileraker(self, **kwargs): ...
|
||||
def update_mobileraker(self, **kwargs):
|
||||
update_mobileraker()
|
||||
|
||||
def update_crowsnest(self, **kwargs):
|
||||
update_crowsnest()
|
||||
|
||||
def upgrade_system_packages(self, **kwargs): ...
|
||||
|
||||
def fetch_update_status(self):
|
||||
def _fetch_update_status(self):
|
||||
# klipper
|
||||
kl_status = get_klipper_status()
|
||||
self.kl_local = self.format_local_status(
|
||||
kl_status.get("local"), kl_status.get("remote")
|
||||
)
|
||||
self.kl_remote = kl_status.get("remote")
|
||||
self.kl_remote = f"{COLOR_GREEN}{kl_status.get('remote')}{RESET_FORMAT}"
|
||||
|
||||
self._get_update_status("kl", get_klipper_status)
|
||||
# moonraker
|
||||
mr_status = get_moonraker_status()
|
||||
self.mr_local = self.format_local_status(
|
||||
mr_status.get("local"), mr_status.get("remote")
|
||||
)
|
||||
self.mr_remote = f"{COLOR_GREEN}{mr_status.get('remote')}{RESET_FORMAT}"
|
||||
|
||||
self._get_update_status("mr", get_moonraker_status)
|
||||
# mainsail
|
||||
ms_local_ver = get_local_client_version(self.mainsail_client)
|
||||
ms_remote_ver = get_remote_client_version(self.mainsail_client)
|
||||
self.ms_local = self.format_local_status(ms_local_ver, ms_remote_ver)
|
||||
self.ms_remote = f"{COLOR_GREEN if ms_remote_ver != 'ERROR' else COLOR_RED}{ms_remote_ver}{RESET_FORMAT}"
|
||||
|
||||
# fluidd
|
||||
fl_local_ver = get_local_client_version(self.fluidd_client)
|
||||
fl_remote_ver = get_remote_client_version(self.fluidd_client)
|
||||
self.fl_local = self.format_local_status(fl_local_ver, fl_remote_ver)
|
||||
self.fl_remote = f"{COLOR_GREEN if fl_remote_ver != 'ERROR' else COLOR_RED}{fl_remote_ver}{RESET_FORMAT}"
|
||||
|
||||
self._get_update_status("ms", get_client_status, self.mainsail_data, True)
|
||||
# mainsail-config
|
||||
mc_status = get_client_config_status(self.mainsail_client)
|
||||
self.mc_local = self.format_local_status(
|
||||
mc_status.get("local"), mc_status.get("remote")
|
||||
)
|
||||
self.mc_remote = f"{COLOR_GREEN}{mc_status.get('remote')}{RESET_FORMAT}"
|
||||
|
||||
self._get_update_status("mc", get_client_config_status, self.mainsail_data)
|
||||
# fluidd
|
||||
self._get_update_status("fl", get_client_status, self.fluidd_data, True)
|
||||
# fluidd-config
|
||||
fc_status = get_client_config_status(self.fluidd_client)
|
||||
self.fc_local = self.format_local_status(
|
||||
fc_status.get("local"), fc_status.get("remote")
|
||||
)
|
||||
self.fc_remote = f"{COLOR_GREEN}{fc_status.get('remote')}{RESET_FORMAT}"
|
||||
|
||||
self._get_update_status("fc", get_client_config_status, self.fluidd_data)
|
||||
# klipperscreen
|
||||
ks_status = get_klipperscreen_status()
|
||||
self.ks_local = self.format_local_status(
|
||||
ks_status.get("local"), ks_status.get("remote")
|
||||
)
|
||||
self.ks_remote = f"{COLOR_GREEN}{ks_status.get('remote')}{RESET_FORMAT}"
|
||||
|
||||
self._get_update_status("ks", get_klipperscreen_status)
|
||||
# mobileraker
|
||||
self._get_update_status("mb", get_mobileraker_status)
|
||||
# crowsnest
|
||||
cn_status = get_crowsnest_status()
|
||||
self.cn_local = self.format_local_status(
|
||||
cn_status.get("local"), cn_status.get("remote")
|
||||
)
|
||||
self.cn_remote = f"{COLOR_GREEN}{cn_status.get('remote')}{RESET_FORMAT}"
|
||||
self._get_update_status("cn", get_crowsnest_status)
|
||||
|
||||
def format_local_status(self, local_version, remote_version) -> str:
|
||||
def _format_local_status(self, local_version, remote_version) -> str:
|
||||
if local_version == remote_version:
|
||||
return f"{COLOR_GREEN}{local_version}{RESET_FORMAT}"
|
||||
return f"{COLOR_YELLOW}{local_version}{RESET_FORMAT}"
|
||||
|
||||
def _get_update_status(self, name: str, status_fn: callable, *args) -> None:
|
||||
status_data = status_fn(*args)
|
||||
local_ver = status_data.get("local")
|
||||
remote_ver = status_data.get("remote")
|
||||
color = COLOR_GREEN if remote_ver != "ERROR" else COLOR_RED
|
||||
setattr(self, f"{name}_local", self._format_local_status(local_ver, remote_ver))
|
||||
setattr(self, f"{name}_remote", f"{color}{remote_ver}{RESET_FORMAT}")
|
||||
|
||||
@@ -6,6 +6,9 @@
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
# ======================================================================= #
|
||||
import textwrap
|
||||
from enum import Enum
|
||||
from typing import List
|
||||
|
||||
from utils.constants import (
|
||||
COLOR_WHITE,
|
||||
@@ -14,9 +17,31 @@ from utils.constants import (
|
||||
COLOR_RED,
|
||||
COLOR_MAGENTA,
|
||||
RESET_FORMAT,
|
||||
COLOR_CYAN,
|
||||
)
|
||||
|
||||
|
||||
class DialogType(Enum):
|
||||
INFO = ("INFO", COLOR_WHITE)
|
||||
SUCCESS = ("SUCCESS", COLOR_GREEN)
|
||||
ATTENTION = ("ATTENTION", COLOR_YELLOW)
|
||||
WARNING = ("WARNING", COLOR_YELLOW)
|
||||
ERROR = ("ERROR", COLOR_RED)
|
||||
CUSTOM = (None, None)
|
||||
|
||||
|
||||
class DialogCustomColor(Enum):
|
||||
WHITE = COLOR_WHITE
|
||||
GREEN = COLOR_GREEN
|
||||
YELLOW = COLOR_YELLOW
|
||||
RED = COLOR_RED
|
||||
CYAN = COLOR_CYAN
|
||||
MAGENTA = COLOR_MAGENTA
|
||||
|
||||
|
||||
LINE_WIDTH = 53
|
||||
|
||||
|
||||
class Logger:
|
||||
@staticmethod
|
||||
def info(msg):
|
||||
@@ -57,3 +82,76 @@ class Logger:
|
||||
def print_status(msg, prefix=True, start="", end="\n") -> None:
|
||||
message = f"\n###### {msg}" if prefix else msg
|
||||
print(f"{COLOR_MAGENTA}{start}{message}{RESET_FORMAT}", end=end)
|
||||
|
||||
@staticmethod
|
||||
def print_dialog(
|
||||
title: DialogType,
|
||||
content: List[str],
|
||||
custom_title: str = None,
|
||||
custom_color: DialogCustomColor = None,
|
||||
) -> None:
|
||||
dialog_color = Logger._get_dialog_color(title, custom_color)
|
||||
dialog_title = Logger._get_dialog_title(title, custom_title)
|
||||
dialog_title_formatted = Logger._format_dialog_title(dialog_title)
|
||||
dialog_content = Logger._format_dialog_content(content, LINE_WIDTH)
|
||||
top = Logger._format_top_border(dialog_color)
|
||||
bottom = Logger._format_bottom_border()
|
||||
|
||||
print(
|
||||
f"{top}{dialog_title_formatted}{dialog_content}{bottom}",
|
||||
end="",
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def _get_dialog_title(title: DialogType, custom_title: str = None) -> str:
|
||||
if title == DialogType.CUSTOM and custom_title:
|
||||
return f"[ {custom_title} ]"
|
||||
return f"[ {title.value[0]} ]" if title.value[0] else None
|
||||
|
||||
@staticmethod
|
||||
def _get_dialog_color(
|
||||
title: DialogType, custom_color: DialogCustomColor = None
|
||||
) -> str:
|
||||
if title == DialogType.CUSTOM and custom_color:
|
||||
return str(custom_color.value)
|
||||
return title.value[1] if title.value[1] else DialogCustomColor.WHITE.value
|
||||
|
||||
@staticmethod
|
||||
def _format_top_border(color: str) -> str:
|
||||
return textwrap.dedent(f"""
|
||||
{color}┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
|
||||
""")[:-1]
|
||||
|
||||
@staticmethod
|
||||
def _format_bottom_border() -> str:
|
||||
return textwrap.dedent(f"""
|
||||
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
|
||||
{RESET_FORMAT}""")
|
||||
|
||||
@staticmethod
|
||||
def _format_dialog_title(title: str) -> str:
|
||||
if title is not None:
|
||||
return textwrap.dedent(f"""
|
||||
┃ {title:^{LINE_WIDTH}} ┃
|
||||
┠───────────────────────────────────────────────────────┨
|
||||
""")
|
||||
else:
|
||||
return "\n"
|
||||
|
||||
@staticmethod
|
||||
def _format_dialog_content(content: List[str], line_width: int) -> str:
|
||||
border_left = "┃"
|
||||
border_right = "┃"
|
||||
wrapper = textwrap.TextWrapper(line_width)
|
||||
|
||||
lines = []
|
||||
for i, c in enumerate(content):
|
||||
paragraph = wrapper.wrap(c)
|
||||
lines.extend(paragraph)
|
||||
if i < len(content) - 1:
|
||||
lines.append(" " * line_width)
|
||||
|
||||
formatted_lines = [
|
||||
f"{border_left} {line:<{line_width}} {border_right}" for line in lines
|
||||
]
|
||||
return "\n".join(formatted_lines)
|
||||
|
||||
@@ -26,6 +26,19 @@ from utils.input_utils import get_confirm
|
||||
from utils.logger import Logger
|
||||
|
||||
|
||||
SysCtlServiceAction = Literal[
|
||||
"start",
|
||||
"stop",
|
||||
"restart",
|
||||
"reload",
|
||||
"enable",
|
||||
"disable",
|
||||
"mask",
|
||||
"unmask",
|
||||
]
|
||||
SysCtlManageAction = Literal["deamon-reload", "reset-failed"]
|
||||
|
||||
|
||||
def kill(opt_err_msg: str = "") -> None:
|
||||
"""
|
||||
Kills the application |
|
||||
@@ -328,9 +341,7 @@ def set_nginx_permissions() -> None:
|
||||
Logger.print_ok("Permissions granted.")
|
||||
|
||||
|
||||
def control_systemd_service(
|
||||
name: str, action: Literal["start", "stop", "restart", "enable", "disable", "mask"]
|
||||
) -> None:
|
||||
def cmd_sysctl_service(name: str, action: SysCtlServiceAction) -> None:
|
||||
"""
|
||||
Helper method to execute several actions for a specific systemd service. |
|
||||
:param name: the service name
|
||||
@@ -339,8 +350,7 @@ def control_systemd_service(
|
||||
"""
|
||||
try:
|
||||
Logger.print_status(f"{action.capitalize()} {name} ...")
|
||||
command = ["sudo", "systemctl", action, name]
|
||||
run(command, stderr=PIPE, check=True)
|
||||
run(["sudo", "systemctl", action, name], stderr=PIPE, check=True)
|
||||
Logger.print_ok("OK!")
|
||||
except CalledProcessError as e:
|
||||
log = f"Failed to {action} {name}: {e.stderr.decode()}"
|
||||
@@ -348,6 +358,15 @@ def control_systemd_service(
|
||||
raise
|
||||
|
||||
|
||||
def cmd_sysctl_manage(action: SysCtlManageAction) -> None:
|
||||
try:
|
||||
run(["sudo", "systemctl", action], stderr=PIPE, check=True)
|
||||
except CalledProcessError as e:
|
||||
log = f"Failed to run {action}: {e.stderr.decode()}"
|
||||
Logger.print_error(log)
|
||||
raise
|
||||
|
||||
|
||||
def log_process(process: Popen) -> None:
|
||||
"""
|
||||
Helper method to print stdout of a process in near realtime to the console.
|
||||
|
||||
Reference in New Issue
Block a user