Compare commits

..

3 Commits

Author SHA1 Message Date
dw-0
1660ca4c7c Merge d6317ad439 into a374ac8fac 2024-05-19 16:05:56 +02:00
dw-0
d6317ad439 chore: cleanup moonraker telegram bot
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-05-19 16:05:31 +02:00
dw-0
e28869be1a fix(mobileraker): remove copy paste error
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-05-18 22:39:17 +02:00
3 changed files with 23 additions and 25 deletions

View File

@@ -8,38 +8,38 @@
# ======================================================================= # # ======================================================================= #
import shutil import shutil
from pathlib import Path from pathlib import Path
from subprocess import run, CalledProcessError from subprocess import CalledProcessError, run
from typing import List, Dict, Literal, Union from typing import Dict, List, Literal, Union
from components.klipper.klipper import Klipper from components.klipper.klipper import Klipper
from components.mobileraker import ( from components.mobileraker import (
MOBILERAKER_REPO, MOBILERAKER_BACKUP_DIR,
MOBILERAKER_DIR, MOBILERAKER_DIR,
MOBILERAKER_ENV, MOBILERAKER_ENV,
MOBILERAKER_BACKUP_DIR, MOBILERAKER_REPO,
) )
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
from core.instance_manager.instance_manager import InstanceManager 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 get_install_status, check_install_dependencies 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.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_pull_wrapper,
get_repo_name,
get_local_commit, get_local_commit,
get_remote_commit, get_remote_commit,
get_repo_name,
git_clone_wrapper,
git_pull_wrapper,
) )
from utils.input_utils import get_confirm from utils.input_utils import get_confirm
from utils.logger import Logger, DialogType from utils.logger import DialogType, Logger
from utils.sys_utils import ( from utils.sys_utils import (
check_python_version, check_python_version,
cmd_sysctl_manage,
cmd_sysctl_service, cmd_sysctl_service,
install_python_requirements, install_python_requirements,
cmd_sysctl_manage,
) )
@@ -111,8 +111,6 @@ def patch_mobileraker_update_manager(instances: List[Moonraker]) -> None:
def update_mobileraker() -> None: def update_mobileraker() -> None:
try: try:
cmd_sysctl_service("KlipperScreen", "stop")
if not MOBILERAKER_DIR.exists(): if not MOBILERAKER_DIR.exists():
Logger.print_info( Logger.print_info(
"Mobileraker's companion does not seem to be installed! Skipping ..." "Mobileraker's companion does not seem to be installed! Skipping ..."

View File

@@ -7,15 +7,14 @@
# This file may be distributed under the terms of the GNU GPLv3 license # # This file may be distributed under the terms of the GNU GPLv3 license #
# ======================================================================= # # ======================================================================= #
import subprocess
from pathlib import Path from pathlib import Path
from subprocess import DEVNULL, CalledProcessError, run
from typing import List from typing import List
from core.instance_manager.base_instance import BaseInstance from core.instance_manager.base_instance import BaseInstance
from utils.constants import SYSTEMD from utils.constants import SYSTEMD
from utils.logger import Logger from utils.logger import Logger
MODULE_PATH = Path(__file__).resolve().parent MODULE_PATH = Path(__file__).resolve().parent
TELEGRAM_BOT_DIR = Path.home().joinpath("moonraker-telegram-bot") TELEGRAM_BOT_DIR = Path.home().joinpath("moonraker-telegram-bot")
@@ -64,7 +63,7 @@ class MoonrakerTelegramBot(BaseInstance):
) )
self.write_env_file(env_template_file_path, env_file_target) self.write_env_file(env_template_file_path, env_file_target)
except subprocess.CalledProcessError as e: except CalledProcessError as e:
Logger.print_error( Logger.print_error(
f"Error creating service file {service_file_target}: {e}" f"Error creating service file {service_file_target}: {e}"
) )
@@ -81,9 +80,9 @@ class MoonrakerTelegramBot(BaseInstance):
try: try:
command = ["sudo", "rm", "-f", service_file_path] command = ["sudo", "rm", "-f", service_file_path]
subprocess.run(command, check=True) run(command, check=True)
Logger.print_ok(f"Service file deleted: {service_file_path}") Logger.print_ok(f"Service file deleted: {service_file_path}")
except subprocess.CalledProcessError as e: except CalledProcessError as e:
Logger.print_error(f"Error deleting service file: {e}") Logger.print_error(f"Error deleting service file: {e}")
raise raise
@@ -97,10 +96,10 @@ class MoonrakerTelegramBot(BaseInstance):
service_template_path, env_file_target service_template_path, env_file_target
) )
command = ["sudo", "tee", service_file_target] command = ["sudo", "tee", service_file_target]
subprocess.run( run(
command, command,
input=service_content.encode(), input=service_content.encode(),
stdout=subprocess.DEVNULL, stdout=DEVNULL,
check=True, check=True,
) )
Logger.print_ok(f"Service file created: {service_file_target}") Logger.print_ok(f"Service file created: {service_file_target}")

View File

@@ -14,22 +14,22 @@ from components.moonraker.moonraker import Moonraker
from core.instance_manager.instance_manager import InstanceManager from core.instance_manager.instance_manager import InstanceManager
from extensions.base_extension import BaseExtension from extensions.base_extension import BaseExtension
from extensions.telegram_bot.moonraker_telegram_bot import ( from extensions.telegram_bot.moonraker_telegram_bot import (
MoonrakerTelegramBot,
TELEGRAM_BOT_REPO,
TELEGRAM_BOT_DIR, TELEGRAM_BOT_DIR,
TELEGRAM_BOT_ENV, TELEGRAM_BOT_ENV,
TELEGRAM_BOT_REPO,
MoonrakerTelegramBot,
) )
from utils.common import check_install_dependencies from utils.common import check_install_dependencies
from utils.config_utils import add_config_section, remove_config_section from utils.config_utils import add_config_section, remove_config_section
from utils.fs_utils import remove_file from utils.fs_utils import remove_file
from utils.git_utils import git_clone_wrapper, git_pull_wrapper from utils.git_utils import git_clone_wrapper, git_pull_wrapper
from utils.input_utils import get_confirm from utils.input_utils import get_confirm
from utils.logger import Logger, DialogType from utils.logger import DialogType, Logger
from utils.sys_utils import ( from utils.sys_utils import (
parse_packages_from_file, cmd_sysctl_manage,
create_python_venv, create_python_venv,
install_python_requirements, install_python_requirements,
cmd_sysctl_manage, parse_packages_from_file,
) )
@@ -44,7 +44,8 @@ class TelegramBotExtension(BaseExtension):
DialogType.WARNING, DialogType.WARNING,
[ [
"No Moonraker instances found!", "No Moonraker instances found!",
"Moonraker Telegram Bot requires Moonraker to be installed. Please install Moonraker first!", "Moonraker Telegram Bot requires Moonraker to be installed. "
"Please install Moonraker first!",
], ],
) )
return return