Compare commits

...

4 Commits

Author SHA1 Message Date
dw-0
f225ed028d refactor: add completion-message to webclient installer
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-12-20 20:45:14 +01:00
dw-0
4ae5a37ec6 fix: most recent tag not shown correctly in main menu
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-11-24 21:43:10 +01:00
dw-0
935f81aab6 fix: backup fails in case of dangling symlink
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-11-24 21:26:12 +01:00
nlef
dbbc87f18e fix: use correct telegram bot config path (#600)
* fix telegram bot config path

* use _post)init_value

---------

Co-authored-by: dw-0 <th33xitus@gmail.com>
Co-authored-by: dw-0 <domwil1091+github@gmail.com>
2024-11-24 15:53:49 +01:00
7 changed files with 43 additions and 37 deletions

View File

@@ -37,6 +37,7 @@ from components.webui_client.client_utils import (
) )
from core.instance_manager.instance_manager import InstanceManager from core.instance_manager.instance_manager import InstanceManager
from core.logger import DialogType, Logger from core.logger import DialogType, Logger
from core.services.message_service import Message
from core.settings.kiauh_settings import KiauhSettings from core.settings.kiauh_settings import KiauhSettings
from core.types.color import Color from core.types.color import Color
from utils.common import backup_printer_config_dir, check_install_dependencies from utils.common import backup_printer_config_dir, check_install_dependencies
@@ -55,14 +56,21 @@ def install_client(
client: BaseWebClient, client: BaseWebClient,
settings: KiauhSettings, settings: KiauhSettings,
reinstall: bool = False, reinstall: bool = False,
) -> None: ) -> Message:
completion_msg = Message(
title=f"{client.display_name} Installation Process completed",
color=Color.GREEN,
)
mr_instances: List[Moonraker] = get_instances(Moonraker) mr_instances: List[Moonraker] = get_instances(Moonraker)
enable_remotemode = False enable_remotemode = False
if not mr_instances: if not mr_instances:
print_moonraker_not_found_dialog(client.display_name) print_moonraker_not_found_dialog(client.display_name)
if not get_confirm(f"Continue {client.display_name} installation?"): if not get_confirm(f"Continue {client.display_name} installation?"):
return completion_msg.color = Color.YELLOW
completion_msg.title = f"{client.display_name} Installation Process aborted"
completion_msg.text.append("Installation was aborted by the user!")
return completion_msg
# if moonraker is not installed or multiple instances # if moonraker is not installed or multiple instances
# are installed we enable mainsails remote mode # are installed we enable mainsails remote mode
@@ -90,9 +98,9 @@ def install_client(
default_port if reinstall else get_client_port_selection(client, settings) default_port if reinstall else get_client_port_selection(client, settings)
) )
check_install_dependencies({"nginx"})
try: try:
check_install_dependencies({"nginx"})
download_client(client) download_client(client)
if enable_remotemode and client.client == WebClientType.MAINSAIL: if enable_remotemode and client.client == WebClientType.MAINSAIL:
enable_mainsail_remotemode() enable_mainsail_remotemode()
@@ -130,23 +138,17 @@ def install_client(
except Exception as e: except Exception as e:
Logger.print_error(e) Logger.print_error(e)
Logger.print_dialog( completion_msg.color = Color.RED
DialogType.ERROR, completion_msg.title = f"{client.display_name} Installation Process failed!"
center_content=True, completion_msg.text.append(
content=[f"{client.display_name} installation failed!"], f"An unexpected error occured. Please see the output above. {client.display_name} installation failed!")
) return completion_msg
return
# noinspection HttpUrlsUsage # noinspection HttpUrlsUsage
Logger.print_dialog( completion_msg.text.append(
DialogType.CUSTOM, f"Open {client.display_name} now on: http://{get_ipv4_addr()}:{port}")
custom_title=f"{client.display_name} installation complete!",
custom_color=Color.GREEN, return completion_msg
center_content=True,
content=[
f"Open {client.display_name} now on: http://{get_ipv4_addr()}:{port}",
],
)
def download_client(client: BaseWebClient) -> None: def download_client(client: BaseWebClient) -> None:

View File

@@ -65,7 +65,8 @@ class ClientInstallMenu(BaseMenu):
print(menu, end="") print(menu, end="")
def reinstall_client(self, **kwargs) -> None: def reinstall_client(self, **kwargs) -> None:
install_client(self.client, settings=self.settings, reinstall=True) completion_msg = install_client(self.client, settings=self.settings, reinstall=True)
self.message_service.set_message(completion_msg)
def change_listen_port(self, **kwargs) -> None: def change_listen_port(self, **kwargs) -> None:
curr_port = self._get_current_port() curr_port = self._get_current_port()

View File

@@ -79,14 +79,14 @@ class BackupManager:
if source is None or not Path(source).exists(): if source is None or not Path(source).exists():
Logger.print_info("Source directory does not exist! Skipping ...") Logger.print_info("Source directory does not exist! Skipping ...")
return return None
target = self.backup_root_dir if target is None else target target = self.backup_root_dir if target is None else target
try: try:
date = get_current_date().get("date") date = get_current_date().get("date")
time = get_current_date().get("time") time = get_current_date().get("time")
backup_target = target.joinpath(f"{name.lower()}-{date}-{time}") backup_target = target.joinpath(f"{name.lower()}-{date}-{time}")
shutil.copytree(source, backup_target, ignore=self.ignore_folders_func) shutil.copytree(source, backup_target, ignore=self.ignore_folders_func, ignore_dangling_symlinks=True)
Logger.print_ok("Backup successful!") Logger.print_ok("Backup successful!")
return backup_target return backup_target

View File

@@ -81,21 +81,13 @@ class InstallMenu(BaseMenu):
moonraker_setup.install_moonraker() moonraker_setup.install_moonraker()
def install_mainsail(self, **kwargs) -> None: def install_mainsail(self, **kwargs) -> None:
client: MainsailData = MainsailData() self._install_client(MainsailData())
if client.client_dir.exists():
ClientInstallMenu(client, self.__class__).run()
else:
install_client(client, settings=KiauhSettings())
def install_mainsail_config(self, **kwargs) -> None: def install_mainsail_config(self, **kwargs) -> None:
install_client_config(MainsailData()) install_client_config(MainsailData())
def install_fluidd(self, **kwargs) -> None: def install_fluidd(self, **kwargs) -> None:
client: FluiddData = FluiddData() self._install_client(FluiddData())
if client.client_dir.exists():
ClientInstallMenu(client, self.__class__).run()
else:
install_client(client, settings=KiauhSettings())
def install_fluidd_config(self, **kwargs) -> None: def install_fluidd_config(self, **kwargs) -> None:
install_client_config(FluiddData()) install_client_config(FluiddData())
@@ -105,3 +97,10 @@ class InstallMenu(BaseMenu):
def install_crowsnest(self, **kwargs) -> None: def install_crowsnest(self, **kwargs) -> None:
install_crowsnest() install_crowsnest()
def _install_client(self, client: MainsailData | FluiddData) -> None:
if client.client_dir.exists():
ClientInstallMenu(client, self.__class__).run()
else:
completion_msg = install_client(client, settings=KiauhSettings())
self.message_service.set_message(completion_msg)

View File

@@ -118,7 +118,7 @@ class MoonrakerTelegramBot:
) )
env_file_content = env_file_content.replace( env_file_content = env_file_content.replace(
"%CFG%", "%CFG%",
f"{self.base.cfg_dir}/printer.cfg", self.cfg_file.as_posix()
) )
env_file_content = env_file_content.replace( env_file_content = env_file_content.replace(
"%LOG%", "%LOG%",

View File

@@ -43,7 +43,8 @@ def get_kiauh_version() -> str:
Helper method to get the current KIAUH version by reading the latest tag Helper method to get the current KIAUH version by reading the latest tag
:return: string of the latest tag :return: string of the latest tag
""" """
return get_local_tags(Path(__file__).parent.parent)[-1] lastest_tag: str = get_local_tags(Path(__file__).parent.parent)[-1]
return lastest_tag
def convert_camelcase_to_kebabcase(name: str) -> str: def convert_camelcase_to_kebabcase(name: str) -> str:

View File

@@ -1,6 +1,7 @@
from __future__ import annotations from __future__ import annotations
import json import json
import re
import shutil import shutil
import urllib.request import urllib.request
from http.client import HTTPResponse from http.client import HTTPResponse
@@ -118,7 +119,7 @@ def get_local_tags(repo_path: Path, _filter: str | None = None) -> List[str]:
:return: List of tags :return: List of tags
""" """
try: try:
cmd = ["git", "tag", "-l"] cmd: List[str] = ["git", "tag", "-l"]
if _filter is not None: if _filter is not None:
cmd.append(f"'${_filter}'") cmd.append(f"'${_filter}'")
@@ -129,8 +130,10 @@ def get_local_tags(repo_path: Path, _filter: str | None = None) -> List[str]:
cwd=repo_path.as_posix(), cwd=repo_path.as_posix(),
).decode(encoding="utf-8") ).decode(encoding="utf-8")
tags = result.split("\n") tags: List[str] = result.split("\n")[:-1]
return tags[:-1]
return sorted(tags, key=lambda x: [int(i) if i.isdigit() else i for i in
re.split(r'(\d+)', x)])
except CalledProcessError: except CalledProcessError:
return [] return []