mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-23 07:43:36 +05:00
feat(KIAUH): show Mainsail install status
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
@@ -20,9 +20,13 @@ from kiauh.core.menus.settings_menu import SettingsMenu
|
||||
from kiauh.core.menus.update_menu import UpdateMenu
|
||||
from kiauh.modules.klipper import KLIPPER_DIR, KLIPPER_ENV_DIR
|
||||
from kiauh.modules.klipper.klipper import Klipper
|
||||
from kiauh.modules.mainsail.mainsail_utils import get_mainsail_status
|
||||
from kiauh.modules.moonraker import MOONRAKER_DIR, MOONRAKER_ENV_DIR
|
||||
from kiauh.modules.moonraker.moonraker import Moonraker
|
||||
from kiauh.utils.common import get_repo_name, get_install_status_common
|
||||
from kiauh.utils.common import (
|
||||
get_repo_name,
|
||||
get_install_status_common,
|
||||
)
|
||||
from kiauh.utils.constants import COLOR_MAGENTA, COLOR_CYAN, RESET_FORMAT, COLOR_RED
|
||||
|
||||
|
||||
@@ -71,6 +75,8 @@ class MainMenu(BaseMenu):
|
||||
Moonraker, MOONRAKER_DIR, MOONRAKER_ENV_DIR
|
||||
)
|
||||
self.mr_repo = get_repo_name(MOONRAKER_DIR)
|
||||
# mainsail
|
||||
self.ms_status = get_mainsail_status()
|
||||
|
||||
def print_menu(self):
|
||||
self.fetch_status()
|
||||
|
||||
@@ -17,10 +17,21 @@ from typing import List
|
||||
|
||||
from kiauh.core.backup_manager.backup_manager import BackupManager
|
||||
from kiauh.modules.klipper.klipper import Klipper
|
||||
from kiauh.modules.mainsail import MAINSAIL_CONFIG_JSON
|
||||
from kiauh.modules.mainsail import MAINSAIL_CONFIG_JSON, MAINSAIL_DIR
|
||||
from kiauh.utils import NGINX_SITES_AVAILABLE, NGINX_CONFD
|
||||
from kiauh.utils.common import get_install_status_webui
|
||||
from kiauh.utils.logger import Logger
|
||||
|
||||
|
||||
def get_mainsail_status() -> str:
|
||||
return get_install_status_webui(
|
||||
MAINSAIL_DIR,
|
||||
Path(NGINX_SITES_AVAILABLE, "mainsail"),
|
||||
Path(NGINX_CONFD, "upstreams.conf"),
|
||||
Path(NGINX_CONFD, "common_vars.conf"),
|
||||
)
|
||||
|
||||
|
||||
def backup_config_json(is_temp=False) -> None:
|
||||
Logger.print_status(f"Backup '{MAINSAIL_CONFIG_JSON}' ...")
|
||||
bm = BackupManager()
|
||||
|
||||
@@ -23,6 +23,7 @@ from kiauh.utils.constants import (
|
||||
COLOR_GREEN,
|
||||
COLOR_RED,
|
||||
)
|
||||
from kiauh.utils.filesystem_utils import check_file_exist
|
||||
from kiauh.utils.logger import Logger
|
||||
from kiauh.utils.system_utils import check_package_install, install_system_packages
|
||||
|
||||
@@ -94,3 +95,28 @@ def get_install_status_common(
|
||||
return f"{COLOR_RED}Not installed!{RESET_FORMAT}"
|
||||
else:
|
||||
return f"{COLOR_YELLOW}Incomplete!{RESET_FORMAT}"
|
||||
|
||||
|
||||
def get_install_status_webui(
|
||||
install_dir: Path, nginx_cfg: Path, upstreams_cfg: Path, common_cfg: Path
|
||||
) -> str:
|
||||
"""
|
||||
Helper method to get the installation status of webuis
|
||||
like Mainsail or Fluidd |
|
||||
:param install_dir: folder of the static webui files
|
||||
:param nginx_cfg: the webuis NGINX config
|
||||
:param upstreams_cfg: the required upstreams.conf
|
||||
:param common_cfg: the required common_vars.conf
|
||||
:return: formatted string, containing the status
|
||||
"""
|
||||
dir_exist = Path(install_dir).exists()
|
||||
nginx_cfg_exist = check_file_exist(nginx_cfg)
|
||||
upstreams_cfg_exist = check_file_exist(upstreams_cfg)
|
||||
common_cfg_exist = check_file_exist(common_cfg)
|
||||
status = [dir_exist, nginx_cfg_exist, upstreams_cfg_exist, common_cfg_exist]
|
||||
if all(status):
|
||||
return f"{COLOR_GREEN}Installed!{RESET_FORMAT}"
|
||||
elif not any(status):
|
||||
return f"{COLOR_RED}Not installed!{RESET_FORMAT}"
|
||||
else:
|
||||
return f"{COLOR_YELLOW}Incomplete!{RESET_FORMAT}"
|
||||
|
||||
Reference in New Issue
Block a user