Compare commits

..

1 Commits

Author SHA1 Message Date
dw-0
8346ff04ed Merge d420daca26 into f2691f33d3 2024-04-28 12:59:46 +02:00
8 changed files with 53 additions and 49 deletions

View File

@@ -59,7 +59,12 @@ class BaseWebClient(ABC):
@property @property
@abstractmethod @abstractmethod
def download_url(self) -> str: def stable_url(self) -> str:
raise NotImplementedError
@property
@abstractmethod
def unstable_url(self) -> str:
raise NotImplementedError raise NotImplementedError
@property @property

View File

@@ -55,7 +55,7 @@ def print_client_already_installed_dialog(name: str):
print_back_footer() print_back_footer()
def print_client_port_select_dialog(name: str, port: int, ports_in_use: List[int]): def print_client_port_select_dialog(name: str, port: str, ports_in_use: List[str]):
port = f"{COLOR_CYAN}{port}{RESET_FORMAT}" port = f"{COLOR_CYAN}{port}{RESET_FORMAT}"
line1 = f"Please select the port, {name} should be served on." line1 = f"Please select the port, {name} should be served on."
line2 = f"In case you need {name} to be served on a specific" line2 = f"In case you need {name} to be served on a specific"

View File

@@ -104,18 +104,20 @@ def install_client(client: BaseWebClient) -> None:
install_client_cfg = get_confirm(question, allow_go_back=False) install_client_cfg = get_confirm(question, allow_go_back=False)
settings = KiauhSettings() settings = KiauhSettings()
port: int = settings.get(client.name, "port") port = settings.get(client.name, "port")
ports_in_use: List[int] = read_ports_from_nginx_configs() ports_in_use = read_ports_from_nginx_configs()
# check if configured port is a valid number and not in use already # check if configured port is a valid number and not in use already
valid_port = is_valid_port(port, ports_in_use) valid_port = is_valid_port(port, ports_in_use)
while not valid_port: while not valid_port:
next_port = get_next_free_port(ports_in_use) next_port = get_next_free_port(ports_in_use)
print_client_port_select_dialog(client.display_name, next_port, ports_in_use) print_client_port_select_dialog(client.display_name, next_port, ports_in_use)
port = get_number_input( port = str(
f"Configure {client.display_name} for port", get_number_input(
min_count=int(next_port), f"Configure {client.display_name} for port",
default=next_port, min_count=int(next_port),
default=next_port,
)
) )
valid_port = is_valid_port(port, ports_in_use) valid_port = is_valid_port(port, ports_in_use)
@@ -160,10 +162,8 @@ def download_client(client: BaseWebClient) -> None:
zipfile = f"{client.name.lower()}.zip" zipfile = f"{client.name.lower()}.zip"
target = Path().home().joinpath(zipfile) target = Path().home().joinpath(zipfile)
try: try:
Logger.print_status( Logger.print_status(f"Downloading {zipfile} ...")
f"Downloading {client.display_name} from {client.download_url} ..." download_file(client.stable_url, target, True)
)
download_file(client.download_url, target, True)
Logger.print_ok("Download complete!") Logger.print_ok("Download complete!")
Logger.print_status(f"Extracting {zipfile} ...") Logger.print_status(f"Extracting {zipfile} ...")
@@ -172,7 +172,7 @@ def download_client(client: BaseWebClient) -> None:
Logger.print_ok("OK!") Logger.print_ok("OK!")
except Exception: except Exception:
Logger.print_error(f"Downloading {client.display_name} failed!") Logger.print_error(f"Downloading {zipfile} failed!")
raise raise

View File

@@ -22,11 +22,10 @@ from components.webui_client.base_data import (
from components.webui_client.mainsail_data import MainsailData from components.webui_client.mainsail_data import MainsailData
from core.backup_manager.backup_manager import BackupManager from core.backup_manager.backup_manager import BackupManager
from core.repo_manager.repo_manager import RepoManager from core.repo_manager.repo_manager import RepoManager
from core.settings.kiauh_settings import KiauhSettings
from utils import NGINX_SITES_AVAILABLE, NGINX_CONFD from utils import NGINX_SITES_AVAILABLE, NGINX_CONFD
from utils.common import get_install_status_webui from utils.common import get_install_status_webui
from utils.constants import COLOR_CYAN, RESET_FORMAT, COLOR_YELLOW from utils.constants import COLOR_CYAN, RESET_FORMAT, COLOR_YELLOW
from utils.git_utils import get_latest_tag, get_latest_unstable_tag from utils.git_utils import get_latest_tag
from utils.logger import Logger from utils.logger import Logger
@@ -202,20 +201,3 @@ def config_for_other_client_exist(client_to_ignore: WebClientType) -> bool:
clients = clients - {client_to_ignore.value} clients = clients - {client_to_ignore.value}
return True if len(clients) > 0 else False return True if len(clients) > 0 else False
def get_download_url(base_url: str, client: BaseWebClient) -> str:
settings = KiauhSettings()
use_unstable = settings.get(client.name, "unstable_releases")
stable_url = f"{base_url}/latest/download/{client.name}.zip"
if not use_unstable:
return stable_url
try:
unstable_tag = get_latest_unstable_tag(client.repo_path)
if unstable_tag == "":
raise Exception
return f"{base_url}/download/{unstable_tag}/{client.name}.zip"
except Exception:
return stable_url

View File

@@ -18,8 +18,8 @@ from components.webui_client.base_data import (
WebClientType, WebClientType,
BaseWebClient, BaseWebClient,
) )
from components.webui_client.client_utils import get_download_url
from core.backup_manager import BACKUP_ROOT_DIR from core.backup_manager import BACKUP_ROOT_DIR
from utils.git_utils import get_latest_unstable_tag
@dataclass(frozen=True) @dataclass(frozen=True)
@@ -46,8 +46,19 @@ class FluiddData(BaseWebClient):
repo_path: str = "fluidd-core/fluidd" repo_path: str = "fluidd-core/fluidd"
@property @property
def download_url(self) -> str: def stable_url(self) -> str:
return get_download_url(self.BASE_DL_URL, self) return f"{self.BASE_DL_URL}/latest/download/fluidd.zip"
@property
def unstable_url(self) -> str:
try:
unstable_tag = get_latest_unstable_tag(self.repo_path)
if unstable_tag != "":
return f"{self.BASE_DL_URL}/download/{unstable_tag}/fluidd.zip"
else:
raise Exception
except Exception:
return self.stable_url
@property @property
def client_config(self) -> BaseWebClientConfig: def client_config(self) -> BaseWebClientConfig:

View File

@@ -19,6 +19,7 @@ from components.webui_client.base_data import (
BaseWebClient, BaseWebClient,
) )
from core.backup_manager import BACKUP_ROOT_DIR from core.backup_manager import BACKUP_ROOT_DIR
from utils.git_utils import get_latest_unstable_tag
@dataclass(frozen=True) @dataclass(frozen=True)
@@ -45,10 +46,19 @@ class MainsailData(BaseWebClient):
repo_path: str = "mainsail-crew/mainsail" repo_path: str = "mainsail-crew/mainsail"
@property @property
def download_url(self) -> str: def stable_url(self) -> str:
from components.webui_client.client_utils import get_download_url return f"{self.BASE_DL_URL}/latest/download/mainsail.zip"
return get_download_url(self.BASE_DL_URL, self) @property
def unstable_url(self) -> str:
try:
unstable_tag = get_latest_unstable_tag(self.repo_path)
if unstable_tag != "":
return f"{self.BASE_DL_URL}/download/{unstable_tag}/mainsail.zip"
else:
raise Exception
except Exception:
return self.stable_url
@property @property
def client_config(self) -> BaseWebClientConfig: def client_config(self) -> BaseWebClientConfig:

View File

@@ -12,7 +12,6 @@ from __future__ import annotations
import subprocess import subprocess
import sys import sys
import textwrap import textwrap
import traceback
from abc import abstractmethod from abc import abstractmethod
from typing import Type, Dict, Optional from typing import Type, Dict, Optional
@@ -214,6 +213,4 @@ class BaseMenu(metaclass=PostInitCaller):
option.method(opt_index=option.opt_index, opt_data=option.opt_data) option.method(opt_index=option.opt_index, opt_data=option.opt_data)
self.run() self.run()
except Exception as e: except Exception as e:
Logger.print_error( Logger.print_error(f"An unexpected error occured:\n{e}")
f"An unexpected error occured:\n{e}\n{traceback.format_exc()}"
)

View File

@@ -149,7 +149,7 @@ def create_nginx_cfg(name: str, port: int, root_dir: Path) -> None:
raise raise
def read_ports_from_nginx_configs() -> List[int]: def read_ports_from_nginx_configs() -> List[str]:
""" """
Helper function to iterate over all NGINX configs and read all ports defined for listen Helper function to iterate over all NGINX configs and read all ports defined for listen
:return: A sorted list of listen ports :return: A sorted list of listen ports
@@ -168,19 +168,18 @@ def read_ports_from_nginx_configs() -> List[int]:
if line.startswith("listen") and line.split()[-1] not in port_list: if line.startswith("listen") and line.split()[-1] not in port_list:
port_list.append(line.split()[-1]) port_list.append(line.split()[-1])
ports_to_ints_list = [int(port) for port in port_list] return sorted(port_list, key=lambda x: int(x))
return sorted(ports_to_ints_list, key=lambda x: int(x))
def is_valid_port(port: int, ports_in_use: List[int]) -> bool: def is_valid_port(port: str, ports_in_use: List[str]) -> bool:
return port not in ports_in_use return port.isdigit() and port not in ports_in_use
def get_next_free_port(ports_in_use: List[int]) -> int: def get_next_free_port(ports_in_use: List[str]) -> str:
valid_ports = set(range(80, 7125)) valid_ports = set(range(80, 7125))
used_ports = set(map(int, ports_in_use)) used_ports = set(map(int, ports_in_use))
return min(valid_ports - used_ports) return str(min(valid_ports - used_ports))
def add_config_section( def add_config_section(