From 70ad635e3d17dc0cbb5c25069c55143cd62da011 Mon Sep 17 00:00:00 2001 From: dw-0 Date: Sat, 25 May 2024 21:31:26 +0200 Subject: [PATCH] feat: add util function to check if moonraker is installed Signed-off-by: Dominik Willner --- kiauh/utils/common.py | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/kiauh/utils/common.py b/kiauh/utils/common.py index 8ca8051..28b0a6f 100644 --- a/kiauh/utils/common.py +++ b/kiauh/utils/common.py @@ -20,7 +20,7 @@ from utils.constants import ( RESET_FORMAT, ) from utils.git_utils import get_local_commit, get_remote_commit, get_repo_name -from utils.logger import Logger +from utils.logger import DialogType, Logger from utils.sys_utils import ( check_package_install, install_system_packages, @@ -124,3 +124,33 @@ def backup_printer_config_dir(): source=instance.cfg_dir, target=PRINTER_CFG_BACKUP_DIR, ) + + +def moonraker_exists(name: str = "") -> bool: + """ + Helper method to check if a Moonraker instance exists + :param name: Optional name of an installer where the check is performed + :return: True if at least one Moonraker instance exists, False otherwise + """ + from components.moonraker.moonraker import Moonraker + + mr_im = InstanceManager(Moonraker) + mr_instances: List[Moonraker] = mr_im.instances + + info = ( + f"{name} requires Moonraker to be installed" + if name + else "A Moonraker installation is required" + ) + + if not mr_instances: + Logger.print_dialog( + DialogType.WARNING, + [ + "No Moonraker instances found!", + f"{info}. Please install Moonraker first!", + ], + end="", + ) + return False + return True