diff --git a/kiauh/extensions/telegram_bot/moonraker_telegram_bot.py b/kiauh/extensions/telegram_bot/moonraker_telegram_bot.py index 316b01c..9e5c3fe 100644 --- a/kiauh/extensions/telegram_bot/moonraker_telegram_bot.py +++ b/kiauh/extensions/telegram_bot/moonraker_telegram_bot.py @@ -7,15 +7,14 @@ # This file may be distributed under the terms of the GNU GPLv3 license # # ======================================================================= # -import subprocess from pathlib import Path +from subprocess import DEVNULL, CalledProcessError, run from typing import List from core.instance_manager.base_instance import BaseInstance from utils.constants import SYSTEMD from utils.logger import Logger - MODULE_PATH = Path(__file__).resolve().parent 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) - except subprocess.CalledProcessError as e: + except CalledProcessError as e: Logger.print_error( f"Error creating service file {service_file_target}: {e}" ) @@ -81,9 +80,9 @@ class MoonrakerTelegramBot(BaseInstance): try: 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}") - except subprocess.CalledProcessError as e: + except CalledProcessError as e: Logger.print_error(f"Error deleting service file: {e}") raise @@ -97,10 +96,10 @@ class MoonrakerTelegramBot(BaseInstance): service_template_path, env_file_target ) command = ["sudo", "tee", service_file_target] - subprocess.run( + run( command, input=service_content.encode(), - stdout=subprocess.DEVNULL, + stdout=DEVNULL, check=True, ) Logger.print_ok(f"Service file created: {service_file_target}") diff --git a/kiauh/extensions/telegram_bot/moonraker_telegram_bot_extension.py b/kiauh/extensions/telegram_bot/moonraker_telegram_bot_extension.py index 90143c2..e6c5e74 100644 --- a/kiauh/extensions/telegram_bot/moonraker_telegram_bot_extension.py +++ b/kiauh/extensions/telegram_bot/moonraker_telegram_bot_extension.py @@ -14,22 +14,22 @@ from components.moonraker.moonraker import Moonraker from core.instance_manager.instance_manager import InstanceManager from extensions.base_extension import BaseExtension from extensions.telegram_bot.moonraker_telegram_bot import ( - MoonrakerTelegramBot, - TELEGRAM_BOT_REPO, TELEGRAM_BOT_DIR, TELEGRAM_BOT_ENV, + TELEGRAM_BOT_REPO, + MoonrakerTelegramBot, ) from utils.common import check_install_dependencies from utils.config_utils import add_config_section, remove_config_section from utils.fs_utils import remove_file from utils.git_utils import git_clone_wrapper, git_pull_wrapper from utils.input_utils import get_confirm -from utils.logger import Logger, DialogType +from utils.logger import DialogType, Logger from utils.sys_utils import ( - parse_packages_from_file, + cmd_sysctl_manage, create_python_venv, install_python_requirements, - cmd_sysctl_manage, + parse_packages_from_file, ) @@ -44,7 +44,8 @@ class TelegramBotExtension(BaseExtension): DialogType.WARNING, [ "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