mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-27 01:33:36 +05:00
Compare commits
10 Commits
b698ff85b4
...
v6.0.0-alp
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b02df9a1e0 | ||
|
|
243ea6582a | ||
|
|
a63cf8c9d9 | ||
|
|
425d86a12f | ||
|
|
1b5691f2f5 | ||
|
|
dc026a7a2b | ||
|
|
a8a73249a5 | ||
|
|
ec3f93eeda | ||
|
|
4cf523a758 | ||
|
|
1d06bf76f3 |
@@ -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")
|
||||
|
||||
|
||||
@@ -138,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}",
|
||||
]
|
||||
@@ -173,10 +172,10 @@ def start_flash_process(flash_options: FlashOptions) -> None:
|
||||
Logger.print_error("See the console output above!", end="\n\n")
|
||||
|
||||
|
||||
def run_make_clean(kconfig = '.config') -> None:
|
||||
def run_make_clean() -> None:
|
||||
try:
|
||||
run(
|
||||
f"make KCONFIG_CONFIG={kconfig} clean",
|
||||
"make clean",
|
||||
cwd=KLIPPER_DIR,
|
||||
shell=True,
|
||||
check=True,
|
||||
@@ -186,10 +185,10 @@ def run_make_clean(kconfig = '.config') -> None:
|
||||
raise
|
||||
|
||||
|
||||
def run_make_menuconfig(kconfig = '.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,
|
||||
@@ -199,10 +198,10 @@ def run_make_menuconfig(kconfig = '.config') -> None:
|
||||
raise
|
||||
|
||||
|
||||
def run_make(kconfig = '.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
|
||||
|
||||
@@ -10,121 +10,34 @@ from __future__ import annotations
|
||||
|
||||
import textwrap
|
||||
from typing import List, Set, Type
|
||||
from os import path, listdir, mkdir
|
||||
from shutil import copyfile
|
||||
|
||||
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, print_back_footer
|
||||
from core.menus.base_menu import BaseMenu
|
||||
from core.types.color import Color
|
||||
from utils.sys_utils import (
|
||||
check_package_install,
|
||||
install_system_packages,
|
||||
update_system_package_lists,
|
||||
)
|
||||
from utils.input_utils import get_confirm, get_string_input, get_selection_input
|
||||
|
||||
|
||||
# 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 = path.join(KLIPPER_DIR, ".config")
|
||||
self.kconfig = self.kconfig_default if not path.isdir(self.kconfigs_dirname) 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.isdir(self.kconfigs_dirname):
|
||||
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)
|
||||
|
||||
self.configs = []
|
||||
option_index = 1
|
||||
for kconfig in listdir(self.kconfigs_dirname):
|
||||
if not kconfig.endswith(".config"):
|
||||
continue
|
||||
kconfig_path = path.join(self.kconfigs_dirname, kconfig)
|
||||
if path.isfile(kconfig_path):
|
||||
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:
|
||||
menu = textwrap.dedent(
|
||||
"""
|
||||
╟───────────────────────────────────────────────────────╢
|
||||
║ Found previously saved firmware configs ║
|
||||
║ ║
|
||||
║ You can select existing firmware config or create a ║
|
||||
║ new one. ║
|
||||
║ ║
|
||||
"""
|
||||
)[1:]
|
||||
|
||||
|
||||
start_index = 1
|
||||
for i, s in enumerate(self.configs):
|
||||
line = f"{start_index + i}) {s}"
|
||||
menu += f"║ {line:<54}║\n"
|
||||
|
||||
new_config = Color.apply("n) New firmware config", Color.YELLOW)
|
||||
menu += f"║ {new_config:<63}║\n"
|
||||
|
||||
menu += "║ ║\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.isfile(selection):
|
||||
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 = path.join(KLIPPER_DIR, ".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
|
||||
@@ -154,7 +67,7 @@ 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"
|
||||
@@ -185,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!")
|
||||
@@ -202,57 +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 = path.join(self.kconfigs_dirname, f"{input_name}.config")
|
||||
|
||||
if path.isfile(filename):
|
||||
if get_confirm(f"Firmware config {input_name} already exists, overwrite?", default_choice=False):
|
||||
break
|
||||
|
||||
if path.isdir(filename):
|
||||
Logger.print_error(f"Path {filename} exists and it's a directory")
|
||||
|
||||
if not path.exists(filename):
|
||||
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.exists(self.kconfigs_dirname):
|
||||
mkdir(self.kconfigs_dirname)
|
||||
|
||||
copyfile(self.kconfig_default, filename)
|
||||
|
||||
Logger.print_ok()
|
||||
Logger.print_ok(f"Firmware config successfully saved to {filename}")
|
||||
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ from __future__ import annotations
|
||||
import textwrap
|
||||
import time
|
||||
from typing import Type
|
||||
from os.path import basename
|
||||
|
||||
from components.klipper_firmware.firmware_utils import (
|
||||
find_firmware_file,
|
||||
@@ -37,7 +36,6 @@ from components.klipper_firmware.menus.klipper_flash_help_menu import (
|
||||
KlipperFlashMethodHelpMenu,
|
||||
KlipperMcuConnectionHelpMenu,
|
||||
)
|
||||
from components.klipper_firmware.menus.klipper_build_menu import KlipperKConfigMenu
|
||||
from core.logger import DialogType, Logger
|
||||
from core.menus import FooterType, Option
|
||||
from core.menus.base_menu import BaseMenu, MenuTitleStyle
|
||||
@@ -422,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 = basename(self.flash_options.selected_kconfig)
|
||||
color = Color.CYAN
|
||||
subheader = f"[{Color.apply('Overview', color)}]"
|
||||
menu = textwrap.dedent(
|
||||
@@ -455,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(
|
||||
"""
|
||||
║ ║
|
||||
|
||||
@@ -144,7 +144,7 @@ def install_client(
|
||||
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}'}",
|
||||
f"Open {client.display_name} now on: http://{get_ipv4_addr()}:{port}",
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
@@ -79,14 +79,14 @@ class BackupManager:
|
||||
|
||||
if source is None or not Path(source).exists():
|
||||
Logger.print_info("Source directory does not exist! Skipping ...")
|
||||
return None
|
||||
return
|
||||
|
||||
target = self.backup_root_dir if target is None else target
|
||||
try:
|
||||
date = get_current_date().get("date")
|
||||
time = get_current_date().get("time")
|
||||
backup_target = target.joinpath(f"{name.lower()}-{date}-{time}")
|
||||
shutil.copytree(source, backup_target, ignore=self.ignore_folders_func, ignore_dangling_symlinks=True)
|
||||
shutil.copytree(source, backup_target, ignore=self.ignore_folders_func)
|
||||
Logger.print_ok("Backup successful!")
|
||||
|
||||
return backup_target
|
||||
|
||||
@@ -14,7 +14,6 @@ from typing import Type
|
||||
from components.klipper import KLIPPER_DIR
|
||||
from components.klipper.klipper import Klipper
|
||||
from components.klipper_firmware.menus.klipper_build_menu import (
|
||||
KlipperKConfigMenu,
|
||||
KlipperBuildFirmwareMenu,
|
||||
)
|
||||
from components.klipper_firmware.menus.klipper_flash_menu import (
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
|
||||
@@ -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 ...")
|
||||
|
||||
@@ -43,8 +43,7 @@ def get_kiauh_version() -> str:
|
||||
Helper method to get the current KIAUH version by reading the latest tag
|
||||
:return: string of the latest tag
|
||||
"""
|
||||
lastest_tag: str = get_local_tags(Path(__file__).parent.parent)[-1]
|
||||
return lastest_tag
|
||||
return get_local_tags(Path(__file__).parent.parent)[-1]
|
||||
|
||||
|
||||
def convert_camelcase_to_kebabcase(name: str) -> str:
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import re
|
||||
import shutil
|
||||
import urllib.request
|
||||
from http.client import HTTPResponse
|
||||
@@ -119,7 +118,7 @@ def get_local_tags(repo_path: Path, _filter: str | None = None) -> List[str]:
|
||||
:return: List of tags
|
||||
"""
|
||||
try:
|
||||
cmd: List[str] = ["git", "tag", "-l"]
|
||||
cmd = ["git", "tag", "-l"]
|
||||
|
||||
if _filter is not None:
|
||||
cmd.append(f"'${_filter}'")
|
||||
@@ -130,10 +129,8 @@ def get_local_tags(repo_path: Path, _filter: str | None = None) -> List[str]:
|
||||
cwd=repo_path.as_posix(),
|
||||
).decode(encoding="utf-8")
|
||||
|
||||
tags: List[str] = result.split("\n")[:-1]
|
||||
|
||||
return sorted(tags, key=lambda x: [int(i) if i.isdigit() else i for i in
|
||||
re.split(r'(\d+)', x)])
|
||||
tags = result.split("\n")
|
||||
return tags[:-1]
|
||||
|
||||
except CalledProcessError:
|
||||
return []
|
||||
|
||||
@@ -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