mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-27 01:33:36 +05:00
Compare commits
3 Commits
v6.0.0-alp
...
5b5baf9810
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5b5baf9810 | ||
|
|
0c6c8bdabf | ||
|
|
f225ed028d |
@@ -27,6 +27,7 @@ from components.crowsnest import (
|
||||
)
|
||||
from components.klipper.klipper import Klipper
|
||||
from core.backup_manager.backup_manager import BackupManager
|
||||
from core.constants import CURRENT_USER
|
||||
from core.logger import DialogType, Logger
|
||||
from core.settings.kiauh_settings import KiauhSettings
|
||||
from core.types.component_status import ComponentStatus
|
||||
@@ -72,7 +73,7 @@ def install_crowsnest() -> None:
|
||||
Logger.print_info("Installer will prompt you for sudo password!")
|
||||
try:
|
||||
run(
|
||||
f"sudo make install",
|
||||
f"sudo make install BASE_USER={CURRENT_USER}",
|
||||
cwd=CROWSNEST_DIR,
|
||||
shell=True,
|
||||
check=True,
|
||||
|
||||
@@ -25,7 +25,6 @@ KLIPPER_SERVICE_NAME = "klipper.service"
|
||||
|
||||
# directories
|
||||
KLIPPER_DIR = Path.home().joinpath("klipper")
|
||||
KLIPPER_KCONFIGS_DIR = Path.home().joinpath("klipper-kconfigs")
|
||||
KLIPPER_ENV_DIR = Path.home().joinpath("klippy-env")
|
||||
KLIPPER_BACKUP_DIR = BACKUP_ROOT_DIR.joinpath("klipper-backups")
|
||||
|
||||
|
||||
@@ -46,11 +46,14 @@ def run_klipper_removal(
|
||||
Logger.print_info("No Klipper Services installed! Skipped ...")
|
||||
|
||||
if (remove_dir or remove_env) and unit_file_exists("klipper", suffix="service"):
|
||||
completion_msg.text = [
|
||||
"Some Klipper services are still installed:",
|
||||
f"● '{KLIPPER_DIR}' was not removed, even though selected for removal.",
|
||||
f"● '{KLIPPER_ENV_DIR}' was not removed, even though selected for removal.",
|
||||
]
|
||||
completion_msg.text.extend(
|
||||
[
|
||||
"\n\n",
|
||||
"Some Klipper services are still installed:",
|
||||
f"● '{KLIPPER_DIR}' was not removed.",
|
||||
f"● '{KLIPPER_ENV_DIR}' was not removed.",
|
||||
]
|
||||
)
|
||||
else:
|
||||
if remove_dir:
|
||||
Logger.print_status("Removing Klipper local repository ...")
|
||||
|
||||
@@ -36,7 +36,9 @@ from components.webui_client.client_utils import (
|
||||
)
|
||||
from core.instance_manager.instance_manager import InstanceManager
|
||||
from core.logger import DialogType, Logger
|
||||
from core.services.message_service import Message
|
||||
from core.settings.kiauh_settings import KiauhSettings
|
||||
from core.types.color import Color
|
||||
from utils.common import check_install_dependencies
|
||||
from utils.git_utils import git_clone_wrapper, git_pull_wrapper
|
||||
from utils.input_utils import get_confirm
|
||||
@@ -50,9 +52,15 @@ from utils.sys_utils import (
|
||||
)
|
||||
|
||||
|
||||
def install_klipper() -> None:
|
||||
def install_klipper() -> Message:
|
||||
Logger.print_status("Installing Klipper ...")
|
||||
|
||||
completion_msg = Message(
|
||||
title="Klipper Installation Process completed",
|
||||
text=["Klipper installation canceled by the user!"],
|
||||
color=Color.YELLOW,
|
||||
)
|
||||
|
||||
klipper_list: List[Klipper] = get_instances(Klipper)
|
||||
moonraker_list: List[Moonraker] = get_instances(Moonraker)
|
||||
match_moonraker: bool = False
|
||||
@@ -60,28 +68,21 @@ def install_klipper() -> None:
|
||||
# if there are more moonraker instances than klipper instances, ask the user to
|
||||
# match the klipper instance count to the count of moonraker instances with the same suffix
|
||||
if len(moonraker_list) > len(klipper_list):
|
||||
is_confirmed = display_moonraker_info(moonraker_list)
|
||||
if not is_confirmed:
|
||||
Logger.print_status(EXIT_KLIPPER_SETUP)
|
||||
return
|
||||
if not match_moonraker_instances(moonraker_list):
|
||||
return completion_msg
|
||||
match_moonraker = True
|
||||
|
||||
install_count, name_dict = get_install_count_and_name_dict(
|
||||
klipper_list, moonraker_list
|
||||
)
|
||||
|
||||
if install_count == 0:
|
||||
Logger.print_status(EXIT_KLIPPER_SETUP)
|
||||
return
|
||||
|
||||
is_multi_install = install_count > 1 or (len(name_dict) >= 1 and install_count >= 1)
|
||||
if not name_dict and install_count == 1:
|
||||
name_dict = {0: ""}
|
||||
elif is_multi_install and not match_moonraker:
|
||||
custom_names = use_custom_names_or_go_back()
|
||||
if custom_names is None:
|
||||
Logger.print_status(EXIT_KLIPPER_SETUP)
|
||||
return
|
||||
return completion_msg
|
||||
|
||||
handle_instance_names(install_count, name_dict, custom_names)
|
||||
|
||||
@@ -91,8 +92,10 @@ def install_klipper() -> None:
|
||||
run_klipper_setup(klipper_list, name_dict, create_example_cfg)
|
||||
except Exception as e:
|
||||
Logger.print_error(e)
|
||||
Logger.print_error("Klipper installation failed!")
|
||||
return
|
||||
completion_msg.color = Color.RED
|
||||
completion_msg.text = ["Klipper installation failed!"]
|
||||
|
||||
return completion_msg
|
||||
|
||||
|
||||
def run_klipper_setup(
|
||||
@@ -155,7 +158,7 @@ def get_install_count_and_name_dict(
|
||||
return install_count, name_dict
|
||||
|
||||
|
||||
def setup_klipper_prerequesites() -> None:
|
||||
def setup_klipper_prerequesites() -> bool:
|
||||
settings = KiauhSettings()
|
||||
repo = settings.klipper.repo_url
|
||||
branch = settings.klipper.branch
|
||||
@@ -171,6 +174,8 @@ def setup_klipper_prerequesites() -> None:
|
||||
Logger.print_error("Error during installation of Klipper requirements!")
|
||||
raise
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def install_klipper_packages() -> None:
|
||||
script = KLIPPER_INSTALL_SCRIPT
|
||||
@@ -223,7 +228,7 @@ def use_custom_names_or_go_back() -> bool | None:
|
||||
return _input
|
||||
|
||||
|
||||
def display_moonraker_info(moonraker_list: List[Moonraker]) -> bool:
|
||||
def match_moonraker_instances(moonraker_list: List[Moonraker]) -> bool:
|
||||
# todo: only show the klipper instances that are not already installed
|
||||
Logger.print_dialog(
|
||||
DialogType.INFO,
|
||||
|
||||
@@ -14,6 +14,7 @@ from typing import Type
|
||||
from components.klipper import klipper_remove
|
||||
from core.menus import FooterType, Option
|
||||
from core.menus.base_menu import BaseMenu
|
||||
from core.menus.utils.menu_utils import get_checkbox_state
|
||||
from core.types.color import Color
|
||||
|
||||
|
||||
@@ -47,11 +48,9 @@ class KlipperRemoveMenu(BaseMenu):
|
||||
}
|
||||
|
||||
def print_menu(self) -> None:
|
||||
checked = f"[{Color.apply('x', Color.CYAN)}]"
|
||||
unchecked = "[ ]"
|
||||
o1 = checked if self.remove_klipper_service else unchecked
|
||||
o2 = checked if self.remove_klipper_dir else unchecked
|
||||
o3 = checked if self.remove_klipper_env else unchecked
|
||||
o1 = get_checkbox_state(self.remove_klipper_service)
|
||||
o2 = get_checkbox_state(self.remove_klipper_dir)
|
||||
o3 = get_checkbox_state(self.remove_klipper_env)
|
||||
sel_state = f"{'Select'if not self.select_state else 'Deselect'} everything"
|
||||
menu = textwrap.dedent(
|
||||
f"""
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
# ======================================================================= #
|
||||
import re
|
||||
from pathlib import Path
|
||||
from subprocess import (
|
||||
DEVNULL,
|
||||
PIPE,
|
||||
@@ -139,7 +138,6 @@ def start_flash_process(flash_options: FlashOptions) -> None:
|
||||
if flash_options.flash_method is FlashMethod.REGULAR:
|
||||
cmd = [
|
||||
"make",
|
||||
f"KCONFIG_CONFIG={flash_options.selected_kconfig}",
|
||||
flash_options.flash_command.value,
|
||||
f"FLASH_DEVICE={flash_options.selected_mcu}",
|
||||
]
|
||||
@@ -167,17 +165,17 @@ def start_flash_process(flash_options: FlashOptions) -> None:
|
||||
if rc != 0:
|
||||
raise Exception(f"Flashing failed with returncode: {rc}")
|
||||
else:
|
||||
Logger.print_ok("Flashing successful!", start="\n", end="\n\n")
|
||||
Logger.print_ok("Flashing successfull!", start="\n", end="\n\n")
|
||||
|
||||
except (Exception, CalledProcessError):
|
||||
Logger.print_error("Flashing failed!", start="\n")
|
||||
Logger.print_error("See the console output above!", end="\n\n")
|
||||
|
||||
|
||||
def run_make_clean(kconfig=Path(KLIPPER_DIR.joinpath(".config"))) -> None:
|
||||
def run_make_clean() -> None:
|
||||
try:
|
||||
run(
|
||||
f"make KCONFIG_CONFIG={kconfig} clean",
|
||||
"make clean",
|
||||
cwd=KLIPPER_DIR,
|
||||
shell=True,
|
||||
check=True,
|
||||
@@ -187,10 +185,10 @@ def run_make_clean(kconfig=Path(KLIPPER_DIR.joinpath(".config"))) -> None:
|
||||
raise
|
||||
|
||||
|
||||
def run_make_menuconfig(kconfig=Path(KLIPPER_DIR.joinpath(".config"))) -> None:
|
||||
def run_make_menuconfig() -> None:
|
||||
try:
|
||||
run(
|
||||
f"make PYTHON=python3 KCONFIG_CONFIG={kconfig} menuconfig",
|
||||
"make PYTHON=python3 menuconfig",
|
||||
cwd=KLIPPER_DIR,
|
||||
shell=True,
|
||||
check=True,
|
||||
@@ -200,10 +198,10 @@ def run_make_menuconfig(kconfig=Path(KLIPPER_DIR.joinpath(".config"))) -> None:
|
||||
raise
|
||||
|
||||
|
||||
def run_make(kconfig=Path(KLIPPER_DIR.joinpath(".config"))) -> None:
|
||||
def run_make() -> None:
|
||||
try:
|
||||
run(
|
||||
f"make PYTHON=python3 KCONFIG_CONFIG={kconfig}",
|
||||
"make PYTHON=python3",
|
||||
cwd=KLIPPER_DIR,
|
||||
shell=True,
|
||||
check=True,
|
||||
|
||||
@@ -39,7 +39,6 @@ class FlashOptions:
|
||||
_selected_mcu: str = ""
|
||||
_selected_board: str = ""
|
||||
_selected_baudrate: int = 250000
|
||||
_selected_kconfig: str = ".config"
|
||||
|
||||
def __new__(cls, *args, **kwargs):
|
||||
if not cls._instance:
|
||||
@@ -105,11 +104,3 @@ class FlashOptions:
|
||||
@selected_baudrate.setter
|
||||
def selected_baudrate(self, value: int) -> None:
|
||||
self._selected_baudrate = value
|
||||
|
||||
@property
|
||||
def selected_kconfig(self) -> str:
|
||||
return self._selected_kconfig
|
||||
|
||||
@selected_kconfig.setter
|
||||
def selected_kconfig(self, value: str) -> None:
|
||||
self._selected_kconfig = value
|
||||
|
||||
@@ -9,22 +9,18 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import textwrap
|
||||
from pathlib import Path
|
||||
from shutil import copyfile
|
||||
from typing import List, Set, Type
|
||||
|
||||
from components.klipper import KLIPPER_DIR, KLIPPER_KCONFIGS_DIR
|
||||
from components.klipper import KLIPPER_DIR
|
||||
from components.klipper_firmware.firmware_utils import (
|
||||
run_make,
|
||||
run_make_clean,
|
||||
run_make_menuconfig,
|
||||
)
|
||||
from components.klipper_firmware.flash_options import FlashOptions
|
||||
from core.logger import DialogType, Logger
|
||||
from core.logger import Logger
|
||||
from core.menus import Option
|
||||
from core.menus.base_menu import BaseMenu
|
||||
from core.types.color import Color
|
||||
from utils.input_utils import get_confirm, get_string_input
|
||||
from utils.sys_utils import (
|
||||
check_package_install,
|
||||
install_system_packages,
|
||||
@@ -32,112 +28,16 @@ from utils.sys_utils import (
|
||||
)
|
||||
|
||||
|
||||
# noinspection PyUnusedLocal
|
||||
# noinspection PyMethodMayBeStatic
|
||||
class KlipperKConfigMenu(BaseMenu):
|
||||
def __init__(self, previous_menu: Type[BaseMenu] | None = None):
|
||||
super().__init__()
|
||||
self.title = "Firmware Config Menu"
|
||||
self.title_color = Color.CYAN
|
||||
self.previous_menu: Type[BaseMenu] | None = previous_menu
|
||||
self.flash_options = FlashOptions()
|
||||
self.kconfigs_dirname = KLIPPER_KCONFIGS_DIR
|
||||
self.kconfig_default = KLIPPER_DIR.joinpath(".config")
|
||||
self.configs: List[Path] = []
|
||||
self.kconfig = (
|
||||
self.kconfig_default if not Path(self.kconfigs_dirname).is_dir() else None
|
||||
)
|
||||
|
||||
def run(self) -> None:
|
||||
if not self.kconfig:
|
||||
super().run()
|
||||
else:
|
||||
self.flash_options.selected_kconfig = self.kconfig
|
||||
|
||||
def set_previous_menu(self, previous_menu: Type[BaseMenu] | None) -> None:
|
||||
from core.menus.advanced_menu import AdvancedMenu
|
||||
|
||||
self.previous_menu = (
|
||||
previous_menu if previous_menu is not None else AdvancedMenu
|
||||
)
|
||||
|
||||
def set_options(self) -> None:
|
||||
if not Path(self.kconfigs_dirname).is_dir():
|
||||
return
|
||||
|
||||
self.input_label_txt = "Select config or action to continue (default=N)"
|
||||
self.default_option = Option(
|
||||
method=self.select_config, opt_data=self.kconfig_default
|
||||
)
|
||||
|
||||
option_index = 1
|
||||
for kconfig in Path(self.kconfigs_dirname).iterdir():
|
||||
if not kconfig.name.endswith(".config"):
|
||||
continue
|
||||
kconfig_path = self.kconfigs_dirname.joinpath(kconfig)
|
||||
if Path(kconfig_path).is_file():
|
||||
self.configs += [kconfig]
|
||||
self.options[str(option_index)] = Option(
|
||||
method=self.select_config, opt_data=kconfig_path
|
||||
)
|
||||
option_index += 1
|
||||
self.options["n"] = Option(
|
||||
method=self.select_config, opt_data=self.kconfig_default
|
||||
)
|
||||
|
||||
def print_menu(self) -> None:
|
||||
cfg_found_str = Color.apply(
|
||||
"Previously saved firmware configs found!", Color.GREEN
|
||||
)
|
||||
menu = textwrap.dedent(
|
||||
f"""
|
||||
╟───────────────────────────────────────────────────────╢
|
||||
║ {cfg_found_str:^62} ║
|
||||
║ ║
|
||||
║ Select an existing config or create a new one. ║
|
||||
╟───────────────────────────────────────────────────────╢
|
||||
║ Available firmware configs: ║
|
||||
"""
|
||||
)[1:]
|
||||
|
||||
start_index = 1
|
||||
for i, s in enumerate(self.configs):
|
||||
line = f"{start_index + i}) {s.name}"
|
||||
menu += f"║ {line:<54}║\n"
|
||||
|
||||
new_config = Color.apply("N) Create new firmware config", Color.GREEN)
|
||||
menu += "║ ║\n"
|
||||
menu += f"║ {new_config:<62} ║\n"
|
||||
|
||||
menu += "╟───────────────────────────────────────────────────────╢\n"
|
||||
|
||||
print(menu, end="")
|
||||
|
||||
def select_config(self, **kwargs) -> None:
|
||||
selection: str | None = kwargs.get("opt_data", None)
|
||||
if selection is None:
|
||||
raise Exception("opt_data is None")
|
||||
if not Path(selection).is_file() and selection != self.kconfig_default:
|
||||
raise Exception("opt_data does not exists")
|
||||
self.kconfig = selection
|
||||
|
||||
|
||||
# noinspection PyUnusedLocal
|
||||
# noinspection PyMethodMayBeStatic
|
||||
class KlipperBuildFirmwareMenu(BaseMenu):
|
||||
def __init__(
|
||||
self, kconfig: str | None = None, previous_menu: Type[BaseMenu] | None = None
|
||||
):
|
||||
def __init__(self, previous_menu: Type[BaseMenu] | None = None):
|
||||
super().__init__()
|
||||
self.title = "Build Firmware Menu"
|
||||
self.title_color = Color.CYAN
|
||||
self.previous_menu: Type[BaseMenu] | None = previous_menu
|
||||
self.deps: Set[str] = {"build-essential", "dpkg-dev", "make"}
|
||||
self.missing_deps: List[str] = check_package_install(self.deps)
|
||||
self.flash_options = FlashOptions()
|
||||
self.kconfigs_dirname = KLIPPER_KCONFIGS_DIR
|
||||
self.kconfig_default = KLIPPER_DIR.joinpath(".config")
|
||||
self.kconfig = self.flash_options.selected_kconfig
|
||||
|
||||
def set_previous_menu(self, previous_menu: Type[BaseMenu] | None) -> None:
|
||||
from core.menus.advanced_menu import AdvancedMenu
|
||||
@@ -147,22 +47,16 @@ class KlipperBuildFirmwareMenu(BaseMenu):
|
||||
)
|
||||
|
||||
def set_options(self) -> None:
|
||||
self.input_label_txt = "Press ENTER to install dependencies"
|
||||
self.default_option = Option(method=self.install_missing_deps)
|
||||
|
||||
def run(self):
|
||||
# immediately start the build process if all dependencies are met
|
||||
if len(self.missing_deps) == 0:
|
||||
self.start_build_process()
|
||||
self.input_label_txt = "Press ENTER to continue"
|
||||
self.default_option = Option(method=self.start_build_process)
|
||||
else:
|
||||
super().run()
|
||||
self.input_label_txt = "Press ENTER to install dependencies"
|
||||
self.default_option = Option(method=self.install_missing_deps)
|
||||
|
||||
def print_menu(self) -> None:
|
||||
txt = Color.apply("Dependencies are missing!", Color.RED)
|
||||
menu = textwrap.dedent(
|
||||
f"""
|
||||
╟───────────────────────────────────────────────────────╢
|
||||
║ {txt:^62} ║
|
||||
"""
|
||||
╟───────────────────────────────────────────────────────╢
|
||||
║ The following dependencies are required: ║
|
||||
║ ║
|
||||
@@ -173,11 +67,19 @@ class KlipperBuildFirmwareMenu(BaseMenu):
|
||||
status_ok = Color.apply("*INSTALLED*", Color.GREEN)
|
||||
status_missing = Color.apply("*MISSING*", Color.RED)
|
||||
status = status_missing if d in self.missing_deps else status_ok
|
||||
padding = 40 - len(d) + len(status) + (len(status_ok) - len(status))
|
||||
padding = 39 - len(d) + len(status) + (len(status_ok) - len(status))
|
||||
d = Color.apply(f"● {d}", Color.CYAN)
|
||||
menu += f"║ {d}{status:>{padding}} ║\n"
|
||||
|
||||
menu += "║ ║\n"
|
||||
|
||||
color = Color.GREEN if len(self.missing_deps) == 0 else Color.RED
|
||||
txt = (
|
||||
"All dependencies are met!"
|
||||
if len(self.missing_deps) == 0
|
||||
else "Dependencies are missing!"
|
||||
)
|
||||
|
||||
menu += f"║ {Color.apply(txt, color):<62} ║\n"
|
||||
menu += "╟───────────────────────────────────────────────────────╢\n"
|
||||
|
||||
print(menu, end="")
|
||||
@@ -196,16 +98,13 @@ class KlipperBuildFirmwareMenu(BaseMenu):
|
||||
|
||||
def start_build_process(self, **kwargs) -> None:
|
||||
try:
|
||||
run_make_clean(self.kconfig)
|
||||
run_make_menuconfig(self.kconfig)
|
||||
run_make(self.kconfig)
|
||||
run_make_clean()
|
||||
run_make_menuconfig()
|
||||
run_make()
|
||||
|
||||
Logger.print_ok("Firmware successfully built!")
|
||||
Logger.print_ok(f"Firmware file located in '{KLIPPER_DIR}/out'!")
|
||||
|
||||
if self.kconfig == self.kconfig_default:
|
||||
self.save_firmware_config()
|
||||
|
||||
except Exception as e:
|
||||
Logger.print_error(e)
|
||||
Logger.print_error("Building Klipper Firmware failed!")
|
||||
@@ -213,62 +112,3 @@ class KlipperBuildFirmwareMenu(BaseMenu):
|
||||
finally:
|
||||
if self.previous_menu is not None:
|
||||
self.previous_menu().run()
|
||||
|
||||
def save_firmware_config(self) -> None:
|
||||
Logger.print_dialog(
|
||||
DialogType.CUSTOM,
|
||||
[
|
||||
"You can save the firmware build configs for multiple MCUs,"
|
||||
" and use them to update the firmware after a Klipper version upgrade"
|
||||
],
|
||||
custom_title="Save firmware config",
|
||||
)
|
||||
if not get_confirm(
|
||||
"Do you want to save firmware config?", default_choice=False
|
||||
):
|
||||
return
|
||||
|
||||
filename = self.kconfig_default
|
||||
while True:
|
||||
Logger.print_dialog(
|
||||
DialogType.CUSTOM,
|
||||
[
|
||||
"Allowed characters: a-z, 0-9 and '-'",
|
||||
"The name must not contain the following:",
|
||||
"\n\n",
|
||||
"● Any special characters",
|
||||
"● No leading or trailing '-'",
|
||||
],
|
||||
)
|
||||
input_name = get_string_input(
|
||||
"Enter the new firmware config name",
|
||||
regex=r"^[a-z0-9]+([a-z0-9-]*[a-z0-9])?$",
|
||||
)
|
||||
filename = self.kconfigs_dirname.joinpath(f"{input_name}.config")
|
||||
|
||||
if Path(filename).is_file():
|
||||
if get_confirm(
|
||||
f"Firmware config {input_name} already exists, overwrite?",
|
||||
default_choice=False,
|
||||
):
|
||||
break
|
||||
|
||||
if Path(filename).is_dir():
|
||||
Logger.print_error(f"Path {filename} exists and it's a directory")
|
||||
|
||||
if not Path(filename).exists():
|
||||
break
|
||||
|
||||
if not get_confirm(
|
||||
f"Save firmware config to '{filename}'?", default_choice=True
|
||||
):
|
||||
Logger.print_info("Aborted saving firmware config ...")
|
||||
return
|
||||
|
||||
if not Path(self.kconfigs_dirname).exists():
|
||||
Path(self.kconfigs_dirname).mkdir()
|
||||
|
||||
copyfile(self.kconfig_default, filename)
|
||||
|
||||
Logger.print_ok()
|
||||
Logger.print_ok(f"Firmware config successfully saved to {filename}")
|
||||
|
||||
@@ -10,7 +10,6 @@ from __future__ import annotations
|
||||
|
||||
import textwrap
|
||||
import time
|
||||
from pathlib import Path
|
||||
from typing import Type
|
||||
|
||||
from components.klipper_firmware.firmware_utils import (
|
||||
@@ -421,7 +420,6 @@ class KlipperFlashOverviewMenu(BaseMenu):
|
||||
mcu = self.flash_options.selected_mcu.split("/")[-1]
|
||||
board = self.flash_options.selected_board
|
||||
baudrate = self.flash_options.selected_baudrate
|
||||
kconfig = Path(self.flash_options.selected_kconfig).name
|
||||
color = Color.CYAN
|
||||
subheader = f"[{Color.apply('Overview', color)}]"
|
||||
menu = textwrap.dedent(
|
||||
@@ -454,13 +452,6 @@ class KlipperFlashOverviewMenu(BaseMenu):
|
||||
"""
|
||||
)[1:]
|
||||
|
||||
if self.flash_options.flash_method is FlashMethod.REGULAR:
|
||||
menu += textwrap.dedent(
|
||||
f"""
|
||||
║ Firmware config: {Color.apply(f"{kconfig:<36}", color)} ║
|
||||
"""
|
||||
)[1:]
|
||||
|
||||
menu += textwrap.dedent(
|
||||
"""
|
||||
║ ║
|
||||
|
||||
@@ -12,8 +12,9 @@ import textwrap
|
||||
from typing import Type
|
||||
|
||||
from components.moonraker import moonraker_remove
|
||||
from core.menus import Option
|
||||
from core.menus import FooterType, Option
|
||||
from core.menus.base_menu import BaseMenu
|
||||
from core.menus.utils.menu_utils import get_checkbox_state
|
||||
from core.types.color import Color
|
||||
|
||||
|
||||
@@ -21,14 +22,17 @@ from core.types.color import Color
|
||||
class MoonrakerRemoveMenu(BaseMenu):
|
||||
def __init__(self, previous_menu: Type[BaseMenu] | None = None):
|
||||
super().__init__()
|
||||
|
||||
self.title = "Remove Moonraker"
|
||||
self.title_color = Color.RED
|
||||
self.previous_menu: Type[BaseMenu] | None = previous_menu
|
||||
self.footer_type = FooterType.BACK
|
||||
|
||||
self.remove_moonraker_service = False
|
||||
self.remove_moonraker_dir = False
|
||||
self.remove_moonraker_env = False
|
||||
self.remove_moonraker_polkit = False
|
||||
self.selection_state = False
|
||||
self.select_state = False
|
||||
|
||||
def set_previous_menu(self, previous_menu: Type[BaseMenu] | None) -> None:
|
||||
from core.menus.remove_menu import RemoveMenu
|
||||
@@ -46,19 +50,18 @@ class MoonrakerRemoveMenu(BaseMenu):
|
||||
}
|
||||
|
||||
def print_menu(self) -> None:
|
||||
checked = f"[{Color.apply('x', Color.CYAN)}]"
|
||||
unchecked = "[ ]"
|
||||
o1 = checked if self.remove_moonraker_service else unchecked
|
||||
o2 = checked if self.remove_moonraker_dir else unchecked
|
||||
o3 = checked if self.remove_moonraker_env else unchecked
|
||||
o4 = checked if self.remove_moonraker_polkit else unchecked
|
||||
o1 = get_checkbox_state(self.remove_moonraker_service)
|
||||
o2 = get_checkbox_state(self.remove_moonraker_dir)
|
||||
o3 = get_checkbox_state(self.remove_moonraker_env)
|
||||
o4 = get_checkbox_state(self.remove_moonraker_polkit)
|
||||
sel_state = f"{'Select'if not self.select_state else 'Deselect'} everything"
|
||||
menu = textwrap.dedent(
|
||||
f"""
|
||||
╟───────────────────────────────────────────────────────╢
|
||||
║ Enter a number and hit enter to select / deselect ║
|
||||
║ the specific option for removal. ║
|
||||
╟───────────────────────────────────────────────────────╢
|
||||
║ a) {self._get_selection_state_str():37} ║
|
||||
║ a) {sel_state:49} ║
|
||||
╟───────────────────────────────────────────────────────╢
|
||||
║ 1) {o1} Remove Service ║
|
||||
║ 2) {o2} Remove Local Repository ║
|
||||
@@ -72,11 +75,11 @@ class MoonrakerRemoveMenu(BaseMenu):
|
||||
print(menu, end="")
|
||||
|
||||
def toggle_all(self, **kwargs) -> None:
|
||||
self.selection_state = not self.selection_state
|
||||
self.remove_moonraker_service = self.selection_state
|
||||
self.remove_moonraker_dir = self.selection_state
|
||||
self.remove_moonraker_env = self.selection_state
|
||||
self.remove_moonraker_polkit = self.selection_state
|
||||
self.select_state = not self.select_state
|
||||
self.remove_moonraker_service = self.select_state
|
||||
self.remove_moonraker_dir = self.select_state
|
||||
self.remove_moonraker_env = self.select_state
|
||||
self.remove_moonraker_polkit = self.select_state
|
||||
|
||||
def toggle_remove_moonraker_service(self, **kwargs) -> None:
|
||||
self.remove_moonraker_service = not self.remove_moonraker_service
|
||||
@@ -97,32 +100,20 @@ class MoonrakerRemoveMenu(BaseMenu):
|
||||
and not self.remove_moonraker_env
|
||||
and not self.remove_moonraker_polkit
|
||||
):
|
||||
print(
|
||||
Color.apply(
|
||||
"Nothing selected! Select options to remove first.", Color.RED
|
||||
)
|
||||
)
|
||||
msg = "Nothing selected! Select options to remove first."
|
||||
print(Color.apply(msg, Color.RED))
|
||||
return
|
||||
|
||||
moonraker_remove.run_moonraker_removal(
|
||||
completion_msg = moonraker_remove.run_moonraker_removal(
|
||||
self.remove_moonraker_service,
|
||||
self.remove_moonraker_dir,
|
||||
self.remove_moonraker_env,
|
||||
self.remove_moonraker_polkit,
|
||||
)
|
||||
self.message_service.set_message(completion_msg)
|
||||
|
||||
self.remove_moonraker_service = False
|
||||
self.remove_moonraker_dir = False
|
||||
self.remove_moonraker_env = False
|
||||
self.remove_moonraker_polkit = False
|
||||
|
||||
self._go_back()
|
||||
|
||||
def _get_selection_state_str(self) -> str:
|
||||
return (
|
||||
"Select everything" if not self.selection_state else "Deselect everything"
|
||||
)
|
||||
|
||||
def _go_back(self, **kwargs) -> None:
|
||||
if self.previous_menu is not None:
|
||||
self.previous_menu().run()
|
||||
self.select_state = False
|
||||
|
||||
@@ -16,6 +16,8 @@ from components.moonraker import MOONRAKER_DIR, MOONRAKER_ENV_DIR
|
||||
from components.moonraker.moonraker import Moonraker
|
||||
from core.instance_manager.instance_manager import InstanceManager
|
||||
from core.logger import Logger
|
||||
from core.services.message_service import Message
|
||||
from core.types.color import Color
|
||||
from utils.fs_utils import run_remove_routines
|
||||
from utils.input_utils import get_selection_input
|
||||
from utils.instance_utils import get_instances
|
||||
@@ -27,7 +29,12 @@ def run_moonraker_removal(
|
||||
remove_dir: bool,
|
||||
remove_env: bool,
|
||||
remove_polkit: bool,
|
||||
) -> None:
|
||||
) -> Message:
|
||||
completion_msg = Message(
|
||||
title="Moonraker Removal Process completed",
|
||||
color=Color.GREEN,
|
||||
)
|
||||
|
||||
instances = get_instances(Moonraker)
|
||||
|
||||
if remove_service:
|
||||
@@ -35,27 +42,45 @@ def run_moonraker_removal(
|
||||
if instances:
|
||||
instances_to_remove = select_instances_to_remove(instances)
|
||||
remove_instances(instances_to_remove)
|
||||
instance_names = [i.service_file_path.stem for i in instances_to_remove]
|
||||
txt = f"● Moonraker instances removed: {', '.join(instance_names)}"
|
||||
completion_msg.text.append(txt)
|
||||
else:
|
||||
Logger.print_info("No Moonraker Services installed! Skipped ...")
|
||||
|
||||
delete_remaining: bool = remove_polkit or remove_dir or remove_env
|
||||
if delete_remaining and unit_file_exists("moonraker", suffix="service"):
|
||||
Logger.print_info("There are still other Moonraker services installed")
|
||||
Logger.print_info(
|
||||
"● Moonraker PolicyKit rules were not removed.", prefix=False
|
||||
completion_msg.text.extend(
|
||||
[
|
||||
"\n\n",
|
||||
"Some Moonraker services are still installed:",
|
||||
"● Moonraker PolicyKit rules were not removed.",
|
||||
f"● '{MOONRAKER_DIR}' was not removed.",
|
||||
f"● '{MOONRAKER_ENV_DIR}' was not removed.",
|
||||
]
|
||||
)
|
||||
Logger.print_info(f"● '{MOONRAKER_DIR}' was not removed.", prefix=False)
|
||||
Logger.print_info(f"● '{MOONRAKER_ENV_DIR}' was not removed.", prefix=False)
|
||||
else:
|
||||
if remove_polkit:
|
||||
Logger.print_status("Removing all Moonraker policykit rules ...")
|
||||
remove_polkit_rules()
|
||||
if remove_polkit_rules():
|
||||
completion_msg.text.append("● Moonraker PolicyKit rules removed")
|
||||
if remove_dir:
|
||||
Logger.print_status("Removing Moonraker local repository ...")
|
||||
run_remove_routines(MOONRAKER_DIR)
|
||||
if run_remove_routines(MOONRAKER_DIR):
|
||||
completion_msg.text.append("● Moonraker local repository removed")
|
||||
if remove_env:
|
||||
Logger.print_status("Removing Moonraker Python environment ...")
|
||||
run_remove_routines(MOONRAKER_ENV_DIR)
|
||||
if run_remove_routines(MOONRAKER_ENV_DIR):
|
||||
completion_msg.text.append("● Moonraker Python environment removed")
|
||||
|
||||
if completion_msg.text:
|
||||
completion_msg.text.insert(0, "The following actions were performed:")
|
||||
else:
|
||||
completion_msg.color = Color.YELLOW
|
||||
completion_msg.centered = True
|
||||
completion_msg.text = ["Nothing to remove."]
|
||||
|
||||
return completion_msg
|
||||
|
||||
|
||||
def select_instances_to_remove(
|
||||
@@ -97,19 +122,23 @@ def remove_instances(
|
||||
delete_moonraker_env_file(instance)
|
||||
|
||||
|
||||
def remove_polkit_rules() -> None:
|
||||
def remove_polkit_rules() -> bool:
|
||||
if not MOONRAKER_DIR.exists():
|
||||
log = "Cannot remove policykit rules. Moonraker directory not found."
|
||||
Logger.print_warn(log)
|
||||
return
|
||||
return False
|
||||
|
||||
try:
|
||||
cmd = [f"{MOONRAKER_DIR}/scripts/set-policykit-rules.sh", "--clear"]
|
||||
run(cmd, stderr=PIPE, stdout=DEVNULL, check=True)
|
||||
result = run(cmd, stderr=PIPE, stdout=DEVNULL, check=True)
|
||||
if result.returncode != 0:
|
||||
raise CalledProcessError(result.returncode, cmd)
|
||||
except CalledProcessError as e:
|
||||
Logger.print_error(f"Error while removing policykit rules: {e}")
|
||||
return False
|
||||
|
||||
Logger.print_ok("Policykit rules successfully removed!")
|
||||
return True
|
||||
|
||||
|
||||
def delete_moonraker_env_file(instance: Moonraker):
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
# ======================================================================= #
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import subprocess
|
||||
from typing import List
|
||||
|
||||
@@ -30,7 +31,6 @@ from components.moonraker.moonraker_dialogs import print_moonraker_overview
|
||||
from components.moonraker.moonraker_utils import (
|
||||
backup_moonraker_dir,
|
||||
create_example_moonraker_conf,
|
||||
parse_sysdeps_file,
|
||||
)
|
||||
from components.webui_client.client_utils import (
|
||||
enable_mainsail_remotemode,
|
||||
@@ -53,7 +53,6 @@ from utils.sys_utils import (
|
||||
cmd_sysctl_manage,
|
||||
cmd_sysctl_service,
|
||||
create_python_venv,
|
||||
get_distro_info,
|
||||
install_python_requirements,
|
||||
parse_packages_from_file,
|
||||
)
|
||||
@@ -158,37 +157,9 @@ def install_moonraker_packages() -> None:
|
||||
moonraker_deps = []
|
||||
|
||||
if MOONRAKER_DEPS_JSON_FILE.exists():
|
||||
Logger.print_status(
|
||||
f"Parsing system dependencies from {MOONRAKER_DEPS_JSON_FILE.name} ..."
|
||||
)
|
||||
parsed_sysdeps = parse_sysdeps_file(MOONRAKER_DEPS_JSON_FILE)
|
||||
distro_name, distro_version = get_distro_info()
|
||||
|
||||
Logger.print_info(f"Distro name: {distro_name}")
|
||||
Logger.print_info(f"Distro version: {distro_version}")
|
||||
|
||||
for dep in parsed_sysdeps.get(distro_name, []):
|
||||
pkg = dep[0].strip()
|
||||
comparator = dep[1].strip()
|
||||
req_version = dep[2].strip()
|
||||
|
||||
comparisons = {
|
||||
"": lambda x, y: True,
|
||||
"<": lambda x, y: x < y,
|
||||
">": lambda x, y: x > y,
|
||||
"<=": lambda x, y: x <= y,
|
||||
">=": lambda x, y: x >= y,
|
||||
"==": lambda x, y: x == y,
|
||||
"!=": lambda x, y: x != y,
|
||||
}
|
||||
|
||||
if comparisons[comparator](float(distro_version), float(req_version or 0)):
|
||||
moonraker_deps.append(pkg)
|
||||
|
||||
with open(MOONRAKER_DEPS_JSON_FILE, "r") as deps:
|
||||
moonraker_deps = json.load(deps).get("debian", [])
|
||||
elif MOONRAKER_INSTALL_SCRIPT.exists():
|
||||
Logger.print_status(
|
||||
f"Parsing system dependencies from {MOONRAKER_INSTALL_SCRIPT.name} ..."
|
||||
)
|
||||
moonraker_deps = parse_packages_from_file(MOONRAKER_INSTALL_SCRIPT)
|
||||
|
||||
if not moonraker_deps:
|
||||
|
||||
@@ -6,11 +6,9 @@
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
# ======================================================================= #
|
||||
import json
|
||||
import re
|
||||
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
from typing import Dict, List, Optional, Tuple
|
||||
from typing import Dict, List, Optional
|
||||
|
||||
from components.moonraker import (
|
||||
MODULE_PATH,
|
||||
@@ -140,34 +138,3 @@ def backup_moonraker_db_dir() -> None:
|
||||
bm.backup_directory(
|
||||
name, source=instance.db_dir, target=MOONRAKER_DB_BACKUP_DIR
|
||||
)
|
||||
|
||||
|
||||
# This function is from sync_dependencies.py script from the Moonraker project on GitHub:
|
||||
# https://github.com/Arksine/moonraker/blob/master/scripts/sync_dependencies.py
|
||||
# Thanks to Arksine for his work on this project!
|
||||
def parse_sysdeps_file(sysdeps_file: Path) -> Dict[str, List[Tuple[str, str, str]]]:
|
||||
"""
|
||||
Parses the system dependencies file and returns a dictionary with the parsed dependencies.
|
||||
:param sysdeps_file: The path to the system dependencies file.
|
||||
:return: A dictionary with the parsed dependencies in the format {distro: [(package, comparator, version)]}.
|
||||
"""
|
||||
base_deps: Dict[str, List[str]] = json.loads(sysdeps_file.read_bytes())
|
||||
parsed_deps: Dict[str, List[Tuple[str, str, str]]] = {}
|
||||
|
||||
for distro, pkgs in base_deps.items():
|
||||
parsed_deps[distro] = []
|
||||
for dep in pkgs:
|
||||
parts = dep.split(";", maxsplit=1)
|
||||
if len(parts) == 1:
|
||||
parsed_deps[distro].append((dep.strip(), "", ""))
|
||||
else:
|
||||
pkg_name = parts[0].strip()
|
||||
dep_parts = re.split(r"(==|!=|<=|>=|<|>)", parts[1].strip())
|
||||
comp_var = dep_parts[0].strip().lower()
|
||||
if len(dep_parts) != 3 or comp_var != "distro_version":
|
||||
continue
|
||||
operator = dep_parts[1].strip()
|
||||
req_version = dep_parts[2].strip()
|
||||
parsed_deps[distro].append((pkg_name, operator, req_version))
|
||||
|
||||
return parsed_deps
|
||||
|
||||
@@ -37,6 +37,7 @@ from components.webui_client.client_utils import (
|
||||
)
|
||||
from core.instance_manager.instance_manager import InstanceManager
|
||||
from core.logger import DialogType, Logger
|
||||
from core.services.message_service import Message
|
||||
from core.settings.kiauh_settings import KiauhSettings
|
||||
from core.types.color import Color
|
||||
from utils.common import backup_printer_config_dir, check_install_dependencies
|
||||
@@ -55,14 +56,21 @@ def install_client(
|
||||
client: BaseWebClient,
|
||||
settings: KiauhSettings,
|
||||
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)
|
||||
|
||||
enable_remotemode = False
|
||||
if not mr_instances:
|
||||
print_moonraker_not_found_dialog(client.display_name)
|
||||
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
|
||||
# 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)
|
||||
)
|
||||
|
||||
check_install_dependencies({"nginx"})
|
||||
|
||||
try:
|
||||
check_install_dependencies({"nginx"})
|
||||
|
||||
download_client(client)
|
||||
if enable_remotemode and client.client == WebClientType.MAINSAIL:
|
||||
enable_mainsail_remotemode()
|
||||
@@ -130,23 +138,17 @@ def install_client(
|
||||
|
||||
except Exception as e:
|
||||
Logger.print_error(e)
|
||||
Logger.print_dialog(
|
||||
DialogType.ERROR,
|
||||
center_content=True,
|
||||
content=[f"{client.display_name} installation failed!"],
|
||||
)
|
||||
return
|
||||
completion_msg.color = Color.RED
|
||||
completion_msg.title = f"{client.display_name} Installation Process failed!"
|
||||
completion_msg.text.append(
|
||||
f"An unexpected error occured. Please see the output above. {client.display_name} installation failed!")
|
||||
return completion_msg
|
||||
|
||||
# noinspection HttpUrlsUsage
|
||||
Logger.print_dialog(
|
||||
DialogType.CUSTOM,
|
||||
custom_title=f"{client.display_name} installation complete!",
|
||||
custom_color=Color.GREEN,
|
||||
center_content=True,
|
||||
content=[
|
||||
f"Open {client.display_name} now on: http://{get_ipv4_addr()}{'' if port == 80 else f':{port}'}",
|
||||
],
|
||||
)
|
||||
completion_msg.text.append(
|
||||
f"Open {client.display_name} now on: http://{get_ipv4_addr()}:{port}")
|
||||
|
||||
return completion_msg
|
||||
|
||||
|
||||
def download_client(client: BaseWebClient) -> None:
|
||||
|
||||
@@ -65,7 +65,8 @@ class ClientInstallMenu(BaseMenu):
|
||||
print(menu, end="")
|
||||
|
||||
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:
|
||||
curr_port = self._get_current_port()
|
||||
|
||||
@@ -15,7 +15,6 @@ from components.klipper import KLIPPER_DIR
|
||||
from components.klipper.klipper import Klipper
|
||||
from components.klipper_firmware.menus.klipper_build_menu import (
|
||||
KlipperBuildFirmwareMenu,
|
||||
KlipperKConfigMenu,
|
||||
)
|
||||
from components.klipper_firmware.menus.klipper_flash_menu import (
|
||||
KlipperFlashMethodMenu,
|
||||
@@ -77,15 +76,12 @@ class AdvancedMenu(BaseMenu):
|
||||
rollback_repository(MOONRAKER_DIR, Moonraker)
|
||||
|
||||
def build(self, **kwargs) -> None:
|
||||
KlipperKConfigMenu().run()
|
||||
KlipperBuildFirmwareMenu(previous_menu=self.__class__).run()
|
||||
|
||||
def flash(self, **kwargs) -> None:
|
||||
KlipperKConfigMenu().run()
|
||||
KlipperFlashMethodMenu(previous_menu=self.__class__).run()
|
||||
|
||||
def build_flash(self, **kwargs) -> None:
|
||||
KlipperKConfigMenu().run()
|
||||
KlipperBuildFirmwareMenu(previous_menu=KlipperFlashMethodMenu).run()
|
||||
KlipperFlashMethodMenu(previous_menu=self.__class__).run()
|
||||
|
||||
|
||||
@@ -75,27 +75,20 @@ class InstallMenu(BaseMenu):
|
||||
print(menu, end="")
|
||||
|
||||
def install_klipper(self, **kwargs) -> None:
|
||||
klipper_setup.install_klipper()
|
||||
completion_msg = klipper_setup.install_klipper()
|
||||
self.message_service.set_message(completion_msg)
|
||||
|
||||
def install_moonraker(self, **kwargs) -> None:
|
||||
moonraker_setup.install_moonraker()
|
||||
|
||||
def install_mainsail(self, **kwargs) -> None:
|
||||
client: MainsailData = MainsailData()
|
||||
if client.client_dir.exists():
|
||||
ClientInstallMenu(client, self.__class__).run()
|
||||
else:
|
||||
install_client(client, settings=KiauhSettings())
|
||||
self._install_client(MainsailData())
|
||||
|
||||
def install_mainsail_config(self, **kwargs) -> None:
|
||||
install_client_config(MainsailData())
|
||||
|
||||
def install_fluidd(self, **kwargs) -> None:
|
||||
client: FluiddData = FluiddData()
|
||||
if client.client_dir.exists():
|
||||
ClientInstallMenu(client, self.__class__).run()
|
||||
else:
|
||||
install_client(client, settings=KiauhSettings())
|
||||
self._install_client(FluiddData())
|
||||
|
||||
def install_fluidd_config(self, **kwargs) -> None:
|
||||
install_client_config(FluiddData())
|
||||
@@ -105,3 +98,10 @@ class InstallMenu(BaseMenu):
|
||||
|
||||
def install_crowsnest(self, **kwargs) -> None:
|
||||
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)
|
||||
|
||||
@@ -21,7 +21,9 @@ from core.menus import Option
|
||||
from core.menus.base_menu import BaseMenu
|
||||
from core.settings.kiauh_settings import KiauhSettings, RepoSettings
|
||||
from core.types.color import Color
|
||||
from core.types.component_status import ComponentStatus
|
||||
from procedures.switch_repo import run_switch_repo_routine
|
||||
from utils.git_utils import get_repo_name
|
||||
from utils.input_utils import get_confirm, get_string_input
|
||||
|
||||
|
||||
@@ -139,12 +141,12 @@ class SettingsMenu(BaseMenu):
|
||||
|
||||
repo = get_string_input(
|
||||
"Enter new repository URL",
|
||||
regex=r"^[\w/.:-]+$",
|
||||
regex="^[\w/.:-]+$",
|
||||
default=KLIPPER_REPO_URL if repo_name == "klipper" else MOONRAKER_REPO_URL,
|
||||
)
|
||||
branch = get_string_input(
|
||||
"Enter new branch name",
|
||||
regex=r"^.+$",
|
||||
regex="^.+$",
|
||||
default="master"
|
||||
)
|
||||
|
||||
|
||||
0
kiauh/core/menus/utils/__init__.py
Normal file
0
kiauh/core/menus/utils/__init__.py
Normal file
13
kiauh/core/menus/utils/menu_utils.py
Normal file
13
kiauh/core/menus/utils/menu_utils.py
Normal file
@@ -0,0 +1,13 @@
|
||||
# ======================================================================= #
|
||||
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/dw-0/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
# ======================================================================= #
|
||||
from core.types.color import Color
|
||||
|
||||
|
||||
def get_checkbox_state(checked: bool) -> str:
|
||||
return f"[{Color.apply('x', Color.CYAN)}]" if checked else "[ ]"
|
||||
@@ -31,7 +31,7 @@ def change_system_hostname() -> None:
|
||||
"http://<hostname>.local",
|
||||
"\n\n",
|
||||
"Example: If you set your hostname to 'my-printer', you can access an "
|
||||
"installed webinterface by typing 'http://my-printer.local' in the "
|
||||
"installed webinterface by tyoing 'http://my-printer.local' in the "
|
||||
"browser.",
|
||||
],
|
||||
custom_title="CHANGE SYSTEM HOSTNAME",
|
||||
@@ -51,7 +51,7 @@ def change_system_hostname() -> None:
|
||||
)
|
||||
hostname = get_string_input(
|
||||
"Enter the new hostname",
|
||||
regex=r"^[a-z0-9]+([a-z0-9-]*[a-z0-9])?$",
|
||||
regex="^[a-z0-9]+([a-z0-9-]*[a-z0-9])?$",
|
||||
)
|
||||
if not get_confirm(f"Change the hostname to '{hostname}'?", default_choice=False):
|
||||
Logger.print_info("Aborting hostname change ...")
|
||||
|
||||
@@ -19,7 +19,7 @@ import urllib.error
|
||||
import urllib.request
|
||||
from pathlib import Path
|
||||
from subprocess import DEVNULL, PIPE, CalledProcessError, Popen, check_output, run
|
||||
from typing import List, Literal, Set, Tuple
|
||||
from typing import List, Literal, Set
|
||||
|
||||
from core.constants import SYSTEMD
|
||||
from core.logger import Logger
|
||||
@@ -539,32 +539,3 @@ def get_service_file_path(instance_type: type, suffix: str) -> Path:
|
||||
file_path: Path = SYSTEMD.joinpath(f"{name}.service")
|
||||
|
||||
return file_path
|
||||
|
||||
|
||||
def get_distro_info() -> Tuple[str, str]:
|
||||
distro_info: str = check_output(["cat", "/etc/os-release"]).decode().strip()
|
||||
|
||||
if not distro_info:
|
||||
raise ValueError("Error reading distro info!")
|
||||
|
||||
distro_id: str = ""
|
||||
distro_id_like: str = ""
|
||||
distro_version: str = ""
|
||||
|
||||
for line in distro_info.split("\n"):
|
||||
if line.startswith("ID="):
|
||||
distro_id = line.split("=")[1].strip('"').strip()
|
||||
if line.startswith("ID_LIKE="):
|
||||
distro_id_like = line.split("=")[1].strip('"').strip()
|
||||
if line.startswith("VERSION_ID="):
|
||||
distro_version = line.split("=")[1].strip('"').strip()
|
||||
|
||||
if distro_id == "raspbian":
|
||||
distro_id = distro_id_like
|
||||
|
||||
if not distro_id:
|
||||
raise ValueError("Error reading distro id!")
|
||||
if not distro_version:
|
||||
raise ValueError("Error reading distro version!")
|
||||
|
||||
return distro_id.lower(), distro_version
|
||||
|
||||
@@ -16,7 +16,6 @@ trusted_clients:
|
||||
cors_domains:
|
||||
*.lan
|
||||
*.local
|
||||
*.internal
|
||||
*://localhost
|
||||
*://localhost:*
|
||||
*://my.mainsail.xyz
|
||||
|
||||
@@ -105,7 +105,7 @@ function install_crowsnest(){
|
||||
pushd "${HOME}/crowsnest" &> /dev/null || exit 1
|
||||
title_msg "Installer will prompt you for sudo password!"
|
||||
status_msg "Launching crowsnest installer ..."
|
||||
if ! sudo make install; then
|
||||
if ! sudo make install BASE_USER=$USER; then
|
||||
error_msg "Something went wrong! Please try again..."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user