Skip to content

Commit

Permalink
Release v6.0.0-alpha.8
Browse files Browse the repository at this point in the history
Merge develop into master (Release v6.0.0-alpha.8)
  • Loading branch information
dw-0 authored Oct 21, 2024
2 parents 1b5691f + ff6162d commit 425d86a
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 46 deletions.
2 changes: 1 addition & 1 deletion default.kiauh.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ port: 80
unstable_releases: False

[fluidd]
port: 81
port: 80
unstable_releases: False
15 changes: 15 additions & 0 deletions kiauh/components/klipper_firmware/firmware_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,21 @@ def find_usb_dfu_device() -> List[str]:
return []


def find_usb_rp2_boot_device() -> List[str]:
try:
output = check_output("lsusb", shell=True, text=True, stderr=DEVNULL)
device_list = []
if output:
devices = output.splitlines()
device_list = [d.split(" ")[5] for d in devices if "RP2 Boot" in d]
return device_list

except CalledProcessError as e:
Logger.print_error("Unable to find a USB RP2 Boot device!")
Logger.print_error(e, prefix=False)
return []


def get_sd_flash_board_list() -> List[str]:
if not KLIPPER_DIR.exists() or not SD_FLASH_SCRIPT.exists():
return []
Expand Down
1 change: 1 addition & 0 deletions kiauh/components/klipper_firmware/flash_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class FlashCommand(Enum):
class ConnectionType(Enum):
USB = "USB"
USB_DFU = "USB (DFU)"
USB_RP2040 = "USB (RP2040)"
UART = "UART"


Expand Down
15 changes: 15 additions & 0 deletions kiauh/components/klipper_firmware/menus/klipper_flash_help_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ def print_menu(self) -> None:
count = 62 - len(color) - len(RESET_FORMAT)
subheader1 = f"{COLOR_CYAN}USB:{RESET_FORMAT}"
subheader2 = f"{COLOR_CYAN}UART:{RESET_FORMAT}"
subheader3 = f"{COLOR_CYAN}USB DFU:{RESET_FORMAT}"
subheader4 = f"{COLOR_CYAN}USB RP2040 Boot:{RESET_FORMAT}"
menu = textwrap.dedent(
f"""
╔═══════════════════════════════════════════════════════╗
Expand All @@ -164,6 +166,19 @@ def print_menu(self) -> None:
║ port your controller board is connected to when using ║
║ this connection method. ║
║ ║
{subheader3:<62}
║ Selecting USB DFU as the connection method will scan ║
║ the USB ports for connected controller boards in ║
║ STM32 DFU mode, which is usually done by holding down ║
║ the BOOT button or setting a special jumper on the ║
║ board before powering up. ║
║ ║
{subheader4:<62}
║ Selecting USB RP2 Boot as the connection method will ║
║ scan the USB ports for connected RP2040 controller ║
║ boards in Boot mode, which is usually done by holding ║
║ down the BOOT button before powering up. ║
║ ║
╟───────────────────────────────────────────────────────╢
"""
)[1:]
Expand Down
10 changes: 10 additions & 0 deletions kiauh/components/klipper_firmware/menus/klipper_flash_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
find_uart_device,
find_usb_device_by_id,
find_usb_dfu_device,
find_usb_rp2_boot_device,
get_sd_flash_board_list,
start_flash_process,
)
Expand Down Expand Up @@ -177,6 +178,7 @@ def set_options(self) -> None:
"1": Option(method=self.select_usb),
"2": Option(method=self.select_dfu),
"3": Option(method=self.select_usb_dfu),
"4": Option(method=self.select_usb_rp2040),
}

def print_menu(self) -> None:
Expand All @@ -193,6 +195,7 @@ def print_menu(self) -> None:
║ 1) USB ║
║ 2) UART ║
║ 3) USB (DFU mode) ║
║ 4) USB (RP2040 mode) ║
╟───────────────────────────┬───────────────────────────╢
"""
)[1:]
Expand All @@ -210,6 +213,10 @@ def select_usb_dfu(self, **kwargs):
self.flash_options.connection_type = ConnectionType.USB_DFU
self.get_mcu_list()

def select_usb_rp2040(self, **kwargs):
self.flash_options.connection_type = ConnectionType.USB_RP2040
self.get_mcu_list()

def get_mcu_list(self, **kwargs):
conn_type = self.flash_options.connection_type

Expand All @@ -222,6 +229,9 @@ def get_mcu_list(self, **kwargs):
elif conn_type is ConnectionType.USB_DFU:
Logger.print_status("Identifying MCU connected via USB in DFU mode ...")
self.flash_options.mcu_list = find_usb_dfu_device()
elif conn_type is ConnectionType.USB_RP2040:
Logger.print_status("Identifying MCU connected via USB in RP2 Boot mode ...")
self.flash_options.mcu_list = find_usb_rp2_boot_device()

if len(self.flash_options.mcu_list) < 1:
Logger.print_warn("No MCUs found!")
Expand Down
39 changes: 22 additions & 17 deletions kiauh/components/webui_client/client_dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
from core.logger import DialogType, Logger


def print_moonraker_not_found_dialog() -> None:
def print_moonraker_not_found_dialog(name: str) -> None:
Logger.print_dialog(
DialogType.WARNING,
[
"No local Moonraker installation was found!",
"\n\n",
"It is possible to install Mainsail without a local Moonraker installation. "
f"It is possible to install {name} without a local Moonraker installation. "
"If you continue, you need to make sure, that Moonraker is installed on "
"another machine in your network. Otherwise Mainsail will NOT work "
f"another machine in your network. Otherwise {name} will NOT work "
"correctly.",
],
)
Expand All @@ -40,20 +40,25 @@ def print_client_already_installed_dialog(name: str) -> None:
def print_client_port_select_dialog(
name: str, port: int, ports_in_use: List[int]
) -> None:
Logger.print_dialog(
DialogType.CUSTOM,
[
f"Please select the port, {name} should be served on. If your are unsure "
f"what to select, hit Enter to apply the suggested value of: {port}",
"\n\n",
f"In case you need {name} to be served on a specific port, you can set it "
f"now. Make sure that the port is not already used by another application "
f"on your system!",
"\n\n",
"The following ports were found to be in use already:",
*[f"● {port}" for port in ports_in_use],
],
)
dialog_content: List[str] = [
f"Please select the port, {name} should be served on. If your are unsure "
f"what to select, hit Enter to apply the suggested value of: {port}",
"\n\n",
f"In case you need {name} to be served on a specific port, you can set it "
f"now. Make sure that the port is not already used by another application "
f"on your system!",
]

if ports_in_use:
dialog_content.extend(
[
"\n\n",
"The following ports were found to be in use already:",
*[f"● {port}" for port in ports_in_use],
]
)

Logger.print_dialog(DialogType.CUSTOM, dialog_content)


def print_install_client_config_dialog(client: BaseWebClient) -> None:
Expand Down
26 changes: 4 additions & 22 deletions kiauh/components/webui_client/client_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
install_client_config,
)
from components.webui_client.client_dialogs import (
print_client_port_select_dialog,
print_install_client_config_dialog,
print_moonraker_not_found_dialog,
)
Expand All @@ -33,18 +32,15 @@
create_nginx_cfg,
detect_client_cfg_conflict,
enable_mainsail_remotemode,
get_next_free_port,
is_valid_port,
read_ports_from_nginx_configs,
get_client_port_selection,
symlink_webui_nginx_log,
)
from core.instance_manager.instance_manager import InstanceManager
from core.logger import Logger
from core.settings.kiauh_settings import KiauhSettings
from utils.common import check_install_dependencies
from utils.config_utils import add_config_section
from utils.fs_utils import unzip
from utils.input_utils import get_confirm, get_number_input
from utils.input_utils import get_confirm
from utils.instance_utils import get_instances
from utils.sys_utils import (
cmd_sysctl_service,
Expand All @@ -67,7 +63,7 @@ def install_client(client: BaseWebClient) -> None:

enable_remotemode = False
if not mr_instances:
print_moonraker_not_found_dialog()
print_moonraker_not_found_dialog(client.display_name)
if not get_confirm(f"Continue {client.display_name} installation?"):
return

Expand All @@ -92,21 +88,7 @@ def install_client(client: BaseWebClient) -> None:
question = f"Download the recommended {client_config.display_name}?"
install_client_cfg = get_confirm(question, allow_go_back=False)

settings = KiauhSettings()
port: int = settings.get(client.name, "port")
ports_in_use: List[int] = read_ports_from_nginx_configs()

# check if configured port is a valid number and not in use already
valid_port = is_valid_port(port, ports_in_use)
while not valid_port:
next_port = get_next_free_port(ports_in_use)
print_client_port_select_dialog(client.display_name, next_port, ports_in_use)
port = get_number_input(
f"Configure {client.display_name} for port",
min_count=int(next_port),
default=next_port,
)
valid_port = is_valid_port(port, ports_in_use)
port: int = get_client_port_selection(client)

check_install_dependencies({"nginx"})

Expand Down
29 changes: 26 additions & 3 deletions kiauh/components/webui_client/client_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
BaseWebClient,
WebClientType,
)
from components.webui_client.client_dialogs import print_client_port_select_dialog
from components.webui_client.fluidd_data import FluiddData
from components.webui_client.mainsail_data import MainsailData
from core.backup_manager.backup_manager import BackupManager
Expand All @@ -33,7 +34,7 @@
RESET_FORMAT,
)
from core.logger import Logger
from core.settings.kiauh_settings import KiauhSettings
from core.settings.kiauh_settings import KiauhSettings, WebUiSettings
from core.submodules.simple_config_parser.src.simple_config_parser.simple_config_parser import (
SimpleConfigParser,
)
Expand All @@ -44,6 +45,7 @@
get_latest_remote_tag,
get_latest_unstable_tag,
)
from utils.input_utils import get_number_input
from utils.instance_utils import get_instances


Expand Down Expand Up @@ -368,8 +370,29 @@ def read_ports_from_nginx_configs() -> List[int]:
return sorted(ports_to_ints_list, key=lambda x: int(x))


def is_valid_port(port: int, ports_in_use: List[int]) -> bool:
return port not in ports_in_use
def get_client_port_selection(client: BaseWebClient) -> int:
settings = KiauhSettings()
default_port: int = int(settings.get(client.name, "port"))

ports_in_use: List[int] = read_ports_from_nginx_configs()
next_free_port: int = get_next_free_port(ports_in_use)

port: int = next_free_port if default_port in ports_in_use else default_port

print_client_port_select_dialog(client.display_name, port, ports_in_use)

while True:
question = f"Configure {client.display_name} for port"
port_input = get_number_input(question, min_count=80, default=port)

if port_input not in ports_in_use:
client_settings: WebUiSettings = settings[client.name]
client_settings.port = port_input
settings.save()

return port_input

Logger.print_error("This port is already in use. Please select another one.")


def get_next_free_port(ports_in_use: List[int]) -> int:
Expand Down
6 changes: 3 additions & 3 deletions scripts/spoolman.sh
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ managed_services: Spoolman
regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/moonraker\.asvc"
moonraker_asvc=$(find "${HOME}" -maxdepth 2 -type f -regextype posix-extended -regex "${regex}" | sort)

if [[ -n ${moonraker_asvc} ]]; then
if ! grep -q "^Spoolman$" "${moonraker_asvc}"; then
status_msg "Adding Spoolman service to moonraker.asvc..."
/bin/sh -c "echo 'Spoolman' >> ${moonraker_asvc}"
sed -i '$a''Spoolman' "${moonraker_asvc}"
fi
}

Expand Down Expand Up @@ -248,7 +248,7 @@ function get_spoolman_status() {

function get_local_spoolman_version() {
[[ ! -d "${SPOOLMAN_DIR}" ]] && return

local version
version=$(grep -o '"version":\s*"[^"]*' "${SPOOLMAN_DIR}"/release_info.json | cut -d'"' -f4)
echo "${version}"
Expand Down

0 comments on commit 425d86a

Please sign in to comment.