mirror of
https://github.com/dw-0/kiauh.git
synced 2026-03-31 06:48:34 +05:00
Compare commits
2 Commits
81f409c5ca
...
84e5359895
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
84e5359895 | ||
|
|
e7141f91e8 |
@@ -7,6 +7,7 @@
|
|||||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||||
# ======================================================================= #
|
# ======================================================================= #
|
||||||
import re
|
import re
|
||||||
|
from pathlib import Path
|
||||||
from subprocess import (
|
from subprocess import (
|
||||||
DEVNULL,
|
DEVNULL,
|
||||||
PIPE,
|
PIPE,
|
||||||
@@ -173,7 +174,7 @@ def start_flash_process(flash_options: FlashOptions) -> None:
|
|||||||
Logger.print_error("See the console output above!", end="\n\n")
|
Logger.print_error("See the console output above!", end="\n\n")
|
||||||
|
|
||||||
|
|
||||||
def run_make_clean(kconfig = '.config') -> None:
|
def run_make_clean(kconfig=Path(KLIPPER_DIR.joinpath(".config"))) -> None:
|
||||||
try:
|
try:
|
||||||
run(
|
run(
|
||||||
f"make KCONFIG_CONFIG={kconfig} clean",
|
f"make KCONFIG_CONFIG={kconfig} clean",
|
||||||
@@ -186,7 +187,7 @@ def run_make_clean(kconfig = '.config') -> None:
|
|||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
def run_make_menuconfig(kconfig = '.config') -> None:
|
def run_make_menuconfig(kconfig=Path(KLIPPER_DIR.joinpath(".config"))) -> None:
|
||||||
try:
|
try:
|
||||||
run(
|
run(
|
||||||
f"make PYTHON=python3 KCONFIG_CONFIG={kconfig} menuconfig",
|
f"make PYTHON=python3 KCONFIG_CONFIG={kconfig} menuconfig",
|
||||||
@@ -199,7 +200,7 @@ def run_make_menuconfig(kconfig = '.config') -> None:
|
|||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
def run_make(kconfig = '.config') -> None:
|
def run_make(kconfig=Path(KLIPPER_DIR.joinpath(".config"))) -> None:
|
||||||
try:
|
try:
|
||||||
run(
|
run(
|
||||||
f"make PYTHON=python3 KCONFIG_CONFIG={kconfig}",
|
f"make PYTHON=python3 KCONFIG_CONFIG={kconfig}",
|
||||||
|
|||||||
@@ -9,9 +9,9 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import textwrap
|
import textwrap
|
||||||
from typing import List, Set, Type
|
from pathlib import Path
|
||||||
from os import path, listdir, mkdir
|
|
||||||
from shutil import copyfile
|
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, KLIPPER_KCONFIGS_DIR
|
||||||
from components.klipper_firmware.firmware_utils import (
|
from components.klipper_firmware.firmware_utils import (
|
||||||
@@ -22,14 +22,14 @@ from components.klipper_firmware.firmware_utils import (
|
|||||||
from components.klipper_firmware.flash_options import FlashOptions
|
from components.klipper_firmware.flash_options import FlashOptions
|
||||||
from core.logger import DialogType, Logger
|
from core.logger import DialogType, Logger
|
||||||
from core.menus import Option
|
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 core.types.color import Color
|
||||||
|
from utils.input_utils import get_confirm, get_string_input
|
||||||
from utils.sys_utils import (
|
from utils.sys_utils import (
|
||||||
check_package_install,
|
check_package_install,
|
||||||
install_system_packages,
|
install_system_packages,
|
||||||
update_system_package_lists,
|
update_system_package_lists,
|
||||||
)
|
)
|
||||||
from utils.input_utils import get_confirm, get_string_input, get_selection_input
|
|
||||||
|
|
||||||
|
|
||||||
# noinspection PyUnusedLocal
|
# noinspection PyUnusedLocal
|
||||||
@@ -42,8 +42,11 @@ class KlipperKConfigMenu(BaseMenu):
|
|||||||
self.previous_menu: Type[BaseMenu] | None = previous_menu
|
self.previous_menu: Type[BaseMenu] | None = previous_menu
|
||||||
self.flash_options = FlashOptions()
|
self.flash_options = FlashOptions()
|
||||||
self.kconfigs_dirname = KLIPPER_KCONFIGS_DIR
|
self.kconfigs_dirname = KLIPPER_KCONFIGS_DIR
|
||||||
self.kconfig_default = path.join(KLIPPER_DIR, ".config")
|
self.kconfig_default = KLIPPER_DIR.joinpath(".config")
|
||||||
self.kconfig = self.kconfig_default if not path.isdir(self.kconfigs_dirname) else None
|
self.configs: List[Path] = []
|
||||||
|
self.kconfig = (
|
||||||
|
self.kconfig_default if not Path(self.kconfigs_dirname).is_dir() else None
|
||||||
|
)
|
||||||
|
|
||||||
def run(self) -> None:
|
def run(self) -> None:
|
||||||
if not self.kconfig:
|
if not self.kconfig:
|
||||||
@@ -59,46 +62,53 @@ class KlipperKConfigMenu(BaseMenu):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def set_options(self) -> None:
|
def set_options(self) -> None:
|
||||||
if not path.isdir(self.kconfigs_dirname):
|
if not Path(self.kconfigs_dirname).is_dir():
|
||||||
return
|
return
|
||||||
|
|
||||||
self.input_label_txt = "Select config or action to continue (default=n)"
|
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.default_option = Option(
|
||||||
|
method=self.select_config, opt_data=self.kconfig_default
|
||||||
|
)
|
||||||
|
|
||||||
self.configs = []
|
|
||||||
option_index = 1
|
option_index = 1
|
||||||
for kconfig in listdir(self.kconfigs_dirname):
|
for kconfig in Path(self.kconfigs_dirname).iterdir():
|
||||||
if not kconfig.endswith(".config"):
|
if not kconfig.name.endswith(".config"):
|
||||||
continue
|
continue
|
||||||
kconfig_path = path.join(self.kconfigs_dirname, kconfig)
|
kconfig_path = self.kconfigs_dirname.joinpath(kconfig)
|
||||||
if path.isfile(kconfig_path):
|
if Path(kconfig_path).is_file():
|
||||||
self.configs += [kconfig]
|
self.configs += [kconfig]
|
||||||
self.options[str(option_index)] = Option(method=self.select_config, opt_data=kconfig_path)
|
self.options[str(option_index)] = Option(
|
||||||
|
method=self.select_config, opt_data=kconfig_path
|
||||||
|
)
|
||||||
option_index += 1
|
option_index += 1
|
||||||
self.options['n'] = Option(method=self.select_config, opt_data=self.kconfig_default)
|
self.options["n"] = Option(
|
||||||
|
method=self.select_config, opt_data=self.kconfig_default
|
||||||
|
)
|
||||||
|
|
||||||
def print_menu(self) -> None:
|
def print_menu(self) -> None:
|
||||||
|
cfg_found_str = Color.apply(
|
||||||
|
"Previously saved firmware configs found!", Color.GREEN
|
||||||
|
)
|
||||||
menu = textwrap.dedent(
|
menu = textwrap.dedent(
|
||||||
"""
|
f"""
|
||||||
╟───────────────────────────────────────────────────────╢
|
╟───────────────────────────────────────────────────────╢
|
||||||
║ Found previously saved firmware configs ║
|
║ {cfg_found_str:^62} ║
|
||||||
║ ║
|
|
||||||
║ You can select existing firmware config or create a ║
|
|
||||||
║ new one. ║
|
|
||||||
║ ║
|
║ ║
|
||||||
|
║ Select an existing config or create a new one. ║
|
||||||
|
╟───────────────────────────────────────────────────────╢
|
||||||
|
║ Available firmware configs: ║
|
||||||
"""
|
"""
|
||||||
)[1:]
|
)[1:]
|
||||||
|
|
||||||
|
|
||||||
start_index = 1
|
start_index = 1
|
||||||
for i, s in enumerate(self.configs):
|
for i, s in enumerate(self.configs):
|
||||||
line = f"{start_index + i}) {s}"
|
line = f"{start_index + i}) {s.name}"
|
||||||
menu += f"║ {line:<54}║\n"
|
menu += f"║ {line:<54}║\n"
|
||||||
|
|
||||||
new_config = Color.apply("n) New firmware config", Color.YELLOW)
|
|
||||||
menu += f"║ {new_config:<63}║\n"
|
|
||||||
|
|
||||||
|
new_config = Color.apply("N) Create new firmware config", Color.GREEN)
|
||||||
menu += "║ ║\n"
|
menu += "║ ║\n"
|
||||||
|
menu += f"║ {new_config:<62} ║\n"
|
||||||
|
|
||||||
menu += "╟───────────────────────────────────────────────────────╢\n"
|
menu += "╟───────────────────────────────────────────────────────╢\n"
|
||||||
|
|
||||||
print(menu, end="")
|
print(menu, end="")
|
||||||
@@ -107,14 +117,17 @@ class KlipperKConfigMenu(BaseMenu):
|
|||||||
selection: str | None = kwargs.get("opt_data", None)
|
selection: str | None = kwargs.get("opt_data", None)
|
||||||
if selection is None:
|
if selection is None:
|
||||||
raise Exception("opt_data is None")
|
raise Exception("opt_data is None")
|
||||||
if not path.isfile(selection) and selection != self.kconfig_default:
|
if not Path(selection).is_file() and selection != self.kconfig_default:
|
||||||
raise Exception("opt_data does not exists")
|
raise Exception("opt_data does not exists")
|
||||||
self.kconfig = selection
|
self.kconfig = selection
|
||||||
|
|
||||||
|
|
||||||
# noinspection PyUnusedLocal
|
# noinspection PyUnusedLocal
|
||||||
# noinspection PyMethodMayBeStatic
|
# noinspection PyMethodMayBeStatic
|
||||||
class KlipperBuildFirmwareMenu(BaseMenu):
|
class KlipperBuildFirmwareMenu(BaseMenu):
|
||||||
def __init__(self, kconfig: str | None = None, previous_menu: Type[BaseMenu] | None = None):
|
def __init__(
|
||||||
|
self, kconfig: str | None = None, previous_menu: Type[BaseMenu] | None = None
|
||||||
|
):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.title = "Build Firmware Menu"
|
self.title = "Build Firmware Menu"
|
||||||
self.title_color = Color.CYAN
|
self.title_color = Color.CYAN
|
||||||
@@ -123,7 +136,7 @@ class KlipperBuildFirmwareMenu(BaseMenu):
|
|||||||
self.missing_deps: List[str] = check_package_install(self.deps)
|
self.missing_deps: List[str] = check_package_install(self.deps)
|
||||||
self.flash_options = FlashOptions()
|
self.flash_options = FlashOptions()
|
||||||
self.kconfigs_dirname = KLIPPER_KCONFIGS_DIR
|
self.kconfigs_dirname = KLIPPER_KCONFIGS_DIR
|
||||||
self.kconfig_default = path.join(KLIPPER_DIR, ".config")
|
self.kconfig_default = KLIPPER_DIR.joinpath(".config")
|
||||||
self.kconfig = self.flash_options.selected_kconfig
|
self.kconfig = self.flash_options.selected_kconfig
|
||||||
|
|
||||||
def set_previous_menu(self, previous_menu: Type[BaseMenu] | None) -> None:
|
def set_previous_menu(self, previous_menu: Type[BaseMenu] | None) -> None:
|
||||||
@@ -202,7 +215,7 @@ class KlipperBuildFirmwareMenu(BaseMenu):
|
|||||||
finally:
|
finally:
|
||||||
if self.previous_menu is not None:
|
if self.previous_menu is not None:
|
||||||
self.previous_menu().run()
|
self.previous_menu().run()
|
||||||
|
|
||||||
def save_firmware_config(self) -> None:
|
def save_firmware_config(self) -> None:
|
||||||
Logger.print_dialog(
|
Logger.print_dialog(
|
||||||
DialogType.CUSTOM,
|
DialogType.CUSTOM,
|
||||||
@@ -212,7 +225,9 @@ class KlipperBuildFirmwareMenu(BaseMenu):
|
|||||||
],
|
],
|
||||||
custom_title="Save firmware config",
|
custom_title="Save firmware config",
|
||||||
)
|
)
|
||||||
if not get_confirm("Do you want to save firmware config?", default_choice=False):
|
if not get_confirm(
|
||||||
|
"Do you want to save firmware config?", default_choice=False
|
||||||
|
):
|
||||||
return
|
return
|
||||||
|
|
||||||
filename = self.kconfig_default
|
filename = self.kconfig_default
|
||||||
@@ -231,28 +246,31 @@ class KlipperBuildFirmwareMenu(BaseMenu):
|
|||||||
"Enter the new firmware config name",
|
"Enter the new firmware config name",
|
||||||
regex=r"^[a-z0-9]+([a-z0-9-]*[a-z0-9])?$",
|
regex=r"^[a-z0-9]+([a-z0-9-]*[a-z0-9])?$",
|
||||||
)
|
)
|
||||||
filename = path.join(self.kconfigs_dirname, f"{input_name}.config")
|
filename = self.kconfigs_dirname.joinpath(f"{input_name}.config")
|
||||||
|
|
||||||
if path.isfile(filename):
|
if Path(filename).is_file():
|
||||||
if get_confirm(f"Firmware config {input_name} already exists, overwrite?", default_choice=False):
|
if get_confirm(
|
||||||
|
f"Firmware config {input_name} already exists, overwrite?",
|
||||||
|
default_choice=False,
|
||||||
|
):
|
||||||
break
|
break
|
||||||
|
|
||||||
if path.isdir(filename):
|
if Path(filename).is_dir():
|
||||||
Logger.print_error(f"Path {filename} exists and it's a directory")
|
Logger.print_error(f"Path {filename} exists and it's a directory")
|
||||||
|
|
||||||
if not path.exists(filename):
|
if not Path(filename).exists():
|
||||||
break
|
break
|
||||||
|
|
||||||
if not get_confirm(f"Save firmware config to '{filename}'?", default_choice=True):
|
if not get_confirm(
|
||||||
|
f"Save firmware config to '{filename}'?", default_choice=True
|
||||||
|
):
|
||||||
Logger.print_info("Aborted saving firmware config ...")
|
Logger.print_info("Aborted saving firmware config ...")
|
||||||
return
|
return
|
||||||
|
|
||||||
if not path.exists(self.kconfigs_dirname):
|
if not Path(self.kconfigs_dirname).exists():
|
||||||
mkdir(self.kconfigs_dirname)
|
Path(self.kconfigs_dirname).mkdir()
|
||||||
|
|
||||||
copyfile(self.kconfig_default, filename)
|
copyfile(self.kconfig_default, filename)
|
||||||
|
|
||||||
Logger.print_ok()
|
Logger.print_ok()
|
||||||
Logger.print_ok(f"Firmware config successfully saved to {filename}")
|
Logger.print_ok(f"Firmware config successfully saved to {filename}")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import textwrap
|
import textwrap
|
||||||
import time
|
import time
|
||||||
|
from pathlib import Path
|
||||||
from typing import Type
|
from typing import Type
|
||||||
from os.path import basename
|
|
||||||
|
|
||||||
from components.klipper_firmware.firmware_utils import (
|
from components.klipper_firmware.firmware_utils import (
|
||||||
find_firmware_file,
|
find_firmware_file,
|
||||||
@@ -37,7 +37,6 @@ from components.klipper_firmware.menus.klipper_flash_help_menu import (
|
|||||||
KlipperFlashMethodHelpMenu,
|
KlipperFlashMethodHelpMenu,
|
||||||
KlipperMcuConnectionHelpMenu,
|
KlipperMcuConnectionHelpMenu,
|
||||||
)
|
)
|
||||||
from components.klipper_firmware.menus.klipper_build_menu import KlipperKConfigMenu
|
|
||||||
from core.logger import DialogType, Logger
|
from core.logger import DialogType, Logger
|
||||||
from core.menus import FooterType, Option
|
from core.menus import FooterType, Option
|
||||||
from core.menus.base_menu import BaseMenu, MenuTitleStyle
|
from core.menus.base_menu import BaseMenu, MenuTitleStyle
|
||||||
@@ -422,7 +421,7 @@ class KlipperFlashOverviewMenu(BaseMenu):
|
|||||||
mcu = self.flash_options.selected_mcu.split("/")[-1]
|
mcu = self.flash_options.selected_mcu.split("/")[-1]
|
||||||
board = self.flash_options.selected_board
|
board = self.flash_options.selected_board
|
||||||
baudrate = self.flash_options.selected_baudrate
|
baudrate = self.flash_options.selected_baudrate
|
||||||
kconfig = basename(self.flash_options.selected_kconfig)
|
kconfig = Path(self.flash_options.selected_kconfig).name
|
||||||
color = Color.CYAN
|
color = Color.CYAN
|
||||||
subheader = f"[{Color.apply('Overview', color)}]"
|
subheader = f"[{Color.apply('Overview', color)}]"
|
||||||
menu = textwrap.dedent(
|
menu = textwrap.dedent(
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ from typing import Type
|
|||||||
from components.klipper import KLIPPER_DIR
|
from components.klipper import KLIPPER_DIR
|
||||||
from components.klipper.klipper import Klipper
|
from components.klipper.klipper import Klipper
|
||||||
from components.klipper_firmware.menus.klipper_build_menu import (
|
from components.klipper_firmware.menus.klipper_build_menu import (
|
||||||
KlipperKConfigMenu,
|
|
||||||
KlipperBuildFirmwareMenu,
|
KlipperBuildFirmwareMenu,
|
||||||
|
KlipperKConfigMenu,
|
||||||
)
|
)
|
||||||
from components.klipper_firmware.menus.klipper_flash_menu import (
|
from components.klipper_firmware.menus.klipper_flash_menu import (
|
||||||
KlipperFlashMethodMenu,
|
KlipperFlashMethodMenu,
|
||||||
|
|||||||
Reference in New Issue
Block a user