Compare commits

...

17 Commits

Author SHA1 Message Date
dw-0
89b48168f4 fix: do not drop SAVE_CONFIG block when editing and writing config files (#723)
Squashed 'kiauh/core/submodules/simple_config_parser/' changes from 4a6e5f2..f5eee99

f5eee99 feat: add support for parsing and handling `SAVE_CONFIG` blocks (#4)
8170583 refactor(api)!: `getval` now returns a string, `getvals` returns list of strings

git-subtree-dir: kiauh/core/submodules/simple_config_parser
git-subtree-split: f5eee99b0f04717c6bbf30c1256d70ad019223d5
2025-09-06 13:12:20 +02:00
Oleg Gurev
195b7fa926 fix: add moonraker-hmi and moonraker-telegram-bot to the blacklist (#720)
* Add moonraker-hmi and moonraker-telegram-bot to the blacklist of moonraker service detection function

* fix: add "hmi" to SUFFIX_BLACKLIST to prevent instance name conflicts

Signed-off-by: Dominik Willner <th33xitus@gmail.com>

---------

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
Co-authored-by: dw-0 <th33xitus@gmail.com>
2025-08-31 11:30:16 +02:00
dw-0
12919c7140 feat(extension): add website and repo metadata for extensions, update links formatting in menu
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2025-08-30 22:02:12 +02:00
dw-0
e590f668e6 fix(common): return default version if no tags exist in get_kiauh_version
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2025-08-28 18:28:40 +02:00
Tovi
075f2d384b docs(readme): add chinese readme instructions (#707)
* add chinese readme

* translated raspberry pi to chinese
2025-08-28 17:45:39 +02:00
dw-0
afdde34721 feat(core): add repository management to settings (#718)
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2025-08-28 16:22:02 +02:00
dw-0
393dd1d5bf feat(extension): add OctoPrint installer (#716)
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2025-08-28 16:21:42 +02:00
dw-0
8170057434 fix(moonraker): correctly patch trusted_clients options
fixes #711 #709

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2025-08-03 10:07:13 +02:00
Maksym Pyrozhok
985b66d41f chore: fix typos (#695)
Fix typo.
2025-07-12 19:36:38 +02:00
dw-0
f95d2586bf fix(webclient): add config.json to moonraker persistent files (#699)
fixes #694

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2025-06-28 10:12:28 +02:00
dw-0
f5141e7eff fix(mainsail): check for json configured as instanceDB (#698)
fix(mainsail): check for json configures as instanceDB

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2025-06-27 22:37:44 +02:00
dw-0
33113e72e9 fix: exception raised on pip warning (#688)
pip seems to write to stderr on warnings, caused by retries. even if the process exits with 0.

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2025-05-31 17:44:02 +02:00
dw-0
6f59fd06aa fix: do not upgrade pip before installing packages (#680)
pip 25 seems to introduce some compatibility issues.

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2025-05-02 20:08:32 +02:00
dw-0
56ea43ccb6 refactor: improve typesafety KiauhSettings
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2025-04-14 21:19:38 +02:00
dw-0
25e22c993f chore(scp): update SimpleConfigParser
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2025-04-14 21:15:12 +02:00
dw-0
ead521b377 refactor: replace mypy with pyright
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2025-04-14 21:07:56 +02:00
dw-0
3c952ccc12 refactor: use sane fallbacks on missing kiauh config options
for some options a warning is print if the fallback is used

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2025-04-12 15:12:11 +02:00
47 changed files with 1299 additions and 247 deletions

206
README_zh.md Normal file
View File

@@ -0,0 +1,206 @@
# KIAUH - Klipper 安装与更新助手
<p align="center">
<a>
<img src="https://raw.githubusercontent.com/dw-0/kiauh/master/resources/screenshots/kiauh.png" alt="KIAUH logo" height="181">
<h1 align="center">Klipper Installation And Update Helper</h1>
</a>
</p>
<p align="center">
一个方便的安装脚本让安装Klipper以及更多组件变得轻松
</p>
<p align="center">
<a><img src="https://img.shields.io/github/license/dw-0/kiauh"></a>
<a><img src="https://img.shields.io/github/stars/dw-0/kiauh"></a>
<a><img src="https://img.shields.io/github/forks/dw-0/kiauh"></a>
<a><img src="https://img.shields.io/github/languages/top/dw-0/kiauh?logo=gnubash&logoColor=white"></a>
<a><img src="https://img.shields.io/github/v/tag/dw-0/kiauh"></a>
<br />
<a><img src="https://img.shields.io/github/last-commit/dw-0/kiauh"></a>
<a><img src="https://img.shields.io/github/contributors/dw-0/kiauh"></a>
</p>
## 📄 使用说明
### 📋 系统要求
KIAUH 是一个帮助您在 Linux 系统上安装 Klipper 的脚本工具,
它需要一个已经写入树莓派或其他单板计算机SD 卡的 Linux 系统。
如果您使用树莓派,推荐使用 `Raspberry Pi OS Lite (32位或64位)` 系统镜像。
[官方 Raspberry Pi Imager](https://www.raspberrypi.com/software/) 是将此类镜像写入 SD 卡的最简单方式。
* 下载、安装并启动 Raspberry Pi Imager 后,
选择 `Choose OS -> Raspberry Pi OS (other)`:
<p align="center">
<img src="https://raw.githubusercontent.com/dw-0/kiauh/master/resources/screenshots/rpi_imager1.png" alt="KIAUH logo" height="350">
</p>
* 然后选择 `Raspberry Pi OS Lite (32位)` (或如果您想使用64位版本):
<p align="center">
<img src="https://raw.githubusercontent.com/dw-0/kiauh/master/resources/screenshots/rpi_imager2.png" alt="KIAUH logo" height="350">
</p>
* 返回 Raspberry Pi Imager 主界面,选择对应的 SD 卡作为写入目标。
* 确保点击左下角的齿轮图标(在主菜单中)
启用 SSH 并配置 Wi-Fi。
* 如果您需要更多关于使用 Raspberry Pi Imager 的帮助,请访问 [官方文档](https://www.raspberrypi.com/documentation/computers/getting-started.html)。
这些步骤**仅适用于**您实际使用树莓派的情况。如果您想使用其他单板计算机(如香橙派或其他 Pi 衍生产品),
请查找如何将合适的 Linux 镜像写入 SD 卡(通常使用 Balena Etcher
同时确保 KIAUH 能够在您要安装的 Linux 发行版上运行。
您在使用基于 Debian 11 Bullseye 的系统时可能会获得最佳体验。
请阅读本文档下方的注意事项。
### 💾 下载并使用 KIAUH
**📢 免责声明:使用此脚本的风险由您自行承担!**
* **第一步:**
要下载此脚本,需要先安装 git。
如果您不确定是否已安装 git请运行以下命令
```shell
sudo apt-get update && sudo apt-get install git -y
```
* **第二步:**
安装完 git 后,
使用以下命令将 KIAUH 下载到您的主目录:
```shell
cd ~ && git clone https://github.com/dw-0/kiauh.git
```
* **第三步:**
最后,通过运行以下命令启动 KIAUH
```shell
./kiauh/kiauh.sh
```
* **第四步:**
您现在应该会看到 KIAUH 的主菜单。
根据您的选择,
您会看到几个可选操作。
要选择某个操作,只需在 "Perform action" 提示后输入对应的数字并按回车键确认。
## ❗ 注意事项
### **📋 请查看 [更新日志](docs/changelog.md) 以了解可能的重要更新!**
- 主要在 Raspberry Pi OS Lite (Debian 10 Buster / Debian 11 Bullseye) 上测试
- 其他基于 Debian 的发行版(如 Ubuntu 20 到 22也可能正常工作
- 据报告在 Armbian 上也可用,但未进行详细测试
- 在使用此脚本的过程中,
您会被要求输入 sudo 密码。
因为有几个功能需要 sudo 权限。
## 🌐 相关资源与更多信息
<table align="center">
<tr>
<th><h3><a href="https://github.com/Klipper3d/klipper">Klipper</a></h3></th>
<th><h3><a href="https://github.com/Arksine/moonraker">Moonraker</a></h3></th>
<th><h3><a href="https://github.com/mainsail-crew/mainsail">Mainsail</a></h3></th>
</tr>
<tr>
<th><img src="https://raw.githubusercontent.com/Klipper3d/klipper/master/docs/img/klipper-logo.png" alt="Klipper Logo" height="64"></th>
<th><img src="https://avatars.githubusercontent.com/u/9563098?v=4" alt="Arksine avatar" height="64"></th>
<th><img src="https://raw.githubusercontent.com/mainsail-crew/docs/master/assets/img/logo.png" alt="Mainsail Logo" height="64"></th>
</tr>
<tr>
<th>由 <a href="https://github.com/KevinOConnor">KevinOConnor</a></th>
<th>由 <a href="https://github.com/Arksine">Arksine</a></th>
<th>由 <a href="https://github.com/mainsail-crew">mainsail-crew</a></th>
</tr>
<tr>
<th><h3><a href="https://github.com/fluidd-core/fluidd">Fluidd</a></h3></th>
<th><h3><a href="https://github.com/jordanruthe/KlipperScreen">KlipperScreen</a></h3></th>
<th><h3><a href="https://github.com/OctoPrint/OctoPrint">OctoPrint</a></h3></th>
</tr>
<tr>
<th><img src="https://raw.githubusercontent.com/fluidd-core/fluidd/master/docs/assets/images/logo.svg" alt="Fluidd Logo" height="64"></th>
<th><img src="https://avatars.githubusercontent.com/u/31575189?v=4" alt="jordanruthe avatar" height="64"></th>
<th><img src="https://raw.githubusercontent.com/OctoPrint/OctoPrint/master/docs/images/octoprint-logo.png" alt="OctoPrint Logo" height="64"></th>
</tr>
<tr>
<th>由 <a href="https://github.com/fluidd-core">fluidd-core</a></th>
<th>由 <a href="https://github.com/jordanruthe">jordanruthe</a></th>
<th>由 <a href="https://github.com/OctoPrint">OctoPrint</a></th>
</tr>
<tr>
<th><h3><a href="https://github.com/nlef/moonraker-telegram-bot">Moonraker-Telegram-Bot</a></h3></th>
<th><h3><a href="https://github.com/Kragrathea/pgcode">PrettyGCode for Klipper</a></h3></th>
<th><h3><a href="https://github.com/TheSpaghettiDetective/moonraker-obico">Obico for Klipper</a></h3></th>
</tr>
<tr>
<th><img src="https://avatars.githubusercontent.com/u/52351624?v=4" alt="nlef avatar" height="64"></th>
<th><img src="https://avatars.githubusercontent.com/u/5917231?v=4" alt="Kragrathea avatar" height="64"></th>
<th><img src="https://avatars.githubusercontent.com/u/46323662?s=200&v=4" alt="Obico logo" height="64"></th>
</tr>
<tr>
<th>由 <a href="https://github.com/nlef">nlef</a></th>
<th>由 <a href="https://github.com/Kragrathea">Kragrathea</a></th>
<th>由 <a href="https://github.com/TheSpaghettiDetective">Obico</a></th>
</tr>
<tr>
<th><h3><a href="https://github.com/Clon1998/mobileraker_companion">Mobileraker's Companion</a></h3></th>
<th><h3><a href="https://octoeverywhere.com/?source=kiauh_readme">OctoEverywhere For Klipper</a></h3></th>
<th><h3><a href="https://github.com/crysxd/OctoApp-Plugin">OctoApp For Klipper</a></h3></th>
</tr>
<tr>
<th><a href="https://github.com/Clon1998/mobileraker_companion"><img src="https://raw.githubusercontent.com/Clon1998/mobileraker/master/assets/icon/mr_appicon.png" alt="Mobileraker Logo" height="64"></a></th>
<th><a href="https://octoeverywhere.com/?source=kiauh_readme"><img src="https://octoeverywhere.com/img/logo.svg" alt="OctoEverywhere Logo" height="64"></a></th>
<th><a href="https://octoapp.eu/?source=kiauh_readme"><img src="https://octoapp.eu/octoapp.webp" alt="OctoApp Logo" height="64"></a></th>
</tr>
<tr>
<th>由 <a href="https://github.com/Clon1998">Patrick Schmidt</a></th>
<th>由 <a href="https://github.com/QuinnDamerell">Quinn Damerell</a></th>
<th>由 <a href="https://github.com/crysxd">Christian Würthner</a></th>
</tr>
<tr>
<th><h3><a href="https://github.com/staubgeborener/klipper-backup">Klipper-Backup</a></h3></th>
<th><h3><a href="https://simplyprint.io/">SimplyPrint for Klipper</a></h3></th>
</tr>
<tr>
<th><a href="https://github.com/staubgeborener/klipper-backup"><img src="https://avatars.githubusercontent.com/u/28908603?v=4" alt="Staubgeroner Avatar" height="64"></a></th>
<th><a href="https://github.com/SimplyPrint"><img src="https://avatars.githubusercontent.com/u/64896552?s=200&v=4" alt="" height="64"></a></th>
</tr>
<tr>
<th>由 <a href="https://github.com/Staubgeborener">Staubgeborener</a></th>
<th>由 <a href="https://github.com/SimplyPrint">SimplyPrint</a></th>
</tr>
</table>
## 🎖️ 贡献者
<div align="center">
<a href="https://github.com/dw-0/kiauh/graphs/contributors">
<img src="https://contrib.rocks/image?repo=dw-0/kiauh" alt=""/>
</a>
</div>
<div align="center">
<img src="https://repobeats.axiom.co/api/embed/a1afbda9190c04a90cf4bd3061e5573bc836cb05.svg" alt="Repobeats analytics image"/>
</div>
## ✨ 特别感谢
* 非常感谢 [lixxbox](https://github.com/lixxbox) 设计了如此出色的 KIAUH 标志!
* 同时,非常感谢所有通过 [Ko-fi](https://ko-fi.com/dw__0) 支持我的工作的人!
* 最后但同样重要的是:感谢所有为 Klipper 社区做出贡献的成员,以及喜欢和分享这个项目的朋友们!
<h4 align="center">特别感谢 JetBrains 为本项目提供其出色的软件赞助!</h4>
<p align="center">
<a href="https://www.jetbrains.com/community/opensource/#support" target="_blank">
<img src="https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.png" alt="JetBrains Logo (Main) logo." height="128">
</a>
</p>

View File

@@ -126,7 +126,7 @@ def create_example_moonraker_conf(
scp.read_file(target)
trusted_clients: List[str] = [
f" {'.'.join(ip)}\n",
*scp.getval("authorization", "trusted_clients"),
*scp.getvals("authorization", "trusted_clients"),
]
scp.set_option("server", "port", str(port))

View File

@@ -102,6 +102,7 @@ def install_client(
section=f"update_manager {client.name}",
instances=mr_instances,
options=[
("persistent_files", ["config.json"]),
("type", "web"),
("channel", "stable"),
("repo", str(client.repo_path)),

View File

@@ -119,7 +119,7 @@ def enable_mainsail_remotemode() -> None:
with open(c_json, "r") as f:
config_data = json.load(f)
if config_data["instancesDB"] == "browser":
if config_data["instancesDB"] == "browser" or config_data["instancesDB"] == "json":
Logger.print_info("Remote mode already configured. Skipped ...")
return

View File

@@ -16,8 +16,9 @@ from typing import List
from utils.fs_utils import get_data_dir
SUFFIX_BLACKLIST: List[str] = ["None", "mcu", "obico", "bambu", "companion"]
# suffixes that are not allowed to be used for instances
# because they would cause conflicts with other components or are reserved
SUFFIX_BLACKLIST: List[str] = ["None", "mcu", "obico", "bambu", "companion", "hmi"]
@dataclass(repr=True)
class BaseInstance:

View File

@@ -10,14 +10,17 @@ from __future__ import annotations
from typing import List, Literal, Type
from core.logger import Logger
from core.logger import Logger, DialogType
from core.menus import Option
from core.menus.base_menu import BaseMenu
from core.settings.kiauh_settings import KiauhSettings, Repository
from core.types.color import Color
from procedures.switch_repo import run_switch_repo_routine
from utils.input_utils import get_string_input, get_number_input, get_confirm
# noinspection PyUnusedLocal
# noinspection PyMethodMayBeStatic
class RepoSelectMenu(BaseMenu):
def __init__(
self,
@@ -48,26 +51,27 @@ class RepoSelectMenu(BaseMenu):
def set_options(self) -> None:
self.options = {}
if not self.repos:
return
if self.repos:
for idx, repo in enumerate(self.repos, start=1):
self.options[str(idx)] = Option(
method=self.select_repository, opt_data=repo
)
self.options["a"] = Option(method=self.add_repository)
self.options["r"] = Option(method=self.remove_repository)
self.options["b"] = Option(method=self.go_back)
def print_menu(self) -> None:
menu = "╟───────────────────────────────────────────────────────╢\n"
menu += "║ Available Repositories: ║\n"
menu += "╟───────────────────────────────────────────────────────╢\n"
for idx, repo in enumerate(self.repos, start=1):
url = f"● Repo: {repo.url.replace('.git', '')}"
branch = f"└► Branch: {repo.branch}"
menu += f"{idx}) {Color.apply(url, Color.CYAN):<59}\n"
menu += f"{Color.apply(branch, Color.CYAN):<59}\n"
menu += "╟───────────────────────────────────────────────────────╢\n"
menu += "║ A) Add repository ║\n"
menu += "║ R) Remove repository ║\n"
menu += "╟───────────────────────────────────────────────────────╢\n"
print(menu, end="")
@@ -77,3 +81,82 @@ class RepoSelectMenu(BaseMenu):
f"Switching to {self.name.capitalize()}'s new source repository ..."
)
run_switch_repo_routine(self.name, repo.url, repo.branch)
def add_repository(self, **kwargs) -> None:
while True:
Logger.print_dialog(
DialogType.CUSTOM,
custom_title="Enter the repository URL",
content=[
"NOTE: There is no input validation in place, "
"please check your input for correctness",
],
)
url = get_string_input("Repository URL", allow_special_chars=True).strip()
Logger.print_dialog(
DialogType.CUSTOM,
custom_title="Enter the branch name",
content=[ "Press Enter to use the default branch (master)." ],
center_content=False,
)
branch = get_string_input("Branch", allow_special_chars=True, default="master").strip()
Logger.print_dialog(
DialogType.CUSTOM,
custom_title="Summary",
content=[
f"● URL: {url}",
f"● Branch: {branch}",
],
)
confirm = get_confirm("Save repository")
if confirm:
repo = Repository(url, branch)
if self.name == "klipper":
self.settings.klipper.repositories.append(repo)
self.settings.save()
self.repos = self.settings.klipper.repositories
else:
self.settings.moonraker.repositories.append(repo)
self.settings.save()
self.repos = self.settings.moonraker.repositories
Logger.print_ok("Repository added and saved.")
# Refresh menu to show new repo immediately and update options
self.set_options()
self.run()
break
else:
Logger.print_info("Operation cancelled by user.")
break
def remove_repository(self, **kwargs) -> None:
repos = self.repos
if not repos:
Logger.print_info("No repositories configured.")
return
repo_lines = [f"{idx}) {repo.url} [{repo.branch}]" for idx, repo in enumerate(repos, start=1)]
Logger.print_dialog(
DialogType.CUSTOM,
custom_title="Available Repositories",
content=[*repo_lines],
)
idx = get_number_input("Select the repository to remove", 1, len(repos))
removed = repos.pop(idx - 1)
if self.name == "klipper":
self.settings.klipper.repositories = repos
self.settings.save()
self.repos = self.settings.klipper.repositories
else:
self.settings.moonraker.repositories = repos
self.settings.save()
self.repos = self.settings.moonraker.repositories
Logger.print_ok(f"Removed repository: {removed.url} [{removed.branch}]")
# Refresh menu to show updated repo list and options
self.set_options()
self.run()
def go_back(self, **kwargs) -> None:
from core.menus.settings_menu import SettingsMenu
SettingsMenu().run()

View File

@@ -117,20 +117,12 @@ class SettingsMenu(BaseMenu):
)
def switch_klipper_repo(self, **kwargs) -> None:
name = "Klipper"
repos = self.settings.klipper.repositories
if not repos:
self._warn_no_repos(name)
return
RepoSelectMenu(name.lower(), repos=repos, previous_menu=self.__class__).run()
RepoSelectMenu("klipper", repos=repos, previous_menu=self.__class__).run()
def switch_moonraker_repo(self, **kwargs) -> None:
name = "Moonraker"
repos = self.settings.moonraker.repositories
if not repos:
self._warn_no_repos(name)
return
RepoSelectMenu(name.lower(), repos=repos, previous_menu=self.__class__).run()
RepoSelectMenu("moonraker", repos=repos, previous_menu=self.__class__).run()
def toggle_mainsail_release(self, **kwargs) -> None:
self.mainsail_unstable = not self.mainsail_unstable

View File

@@ -8,14 +8,15 @@
# ======================================================================= #
from __future__ import annotations
import shutil
from dataclasses import dataclass, field
from typing import Any, List
from typing import Any, Callable, List, TypeVar
from components.klipper import KLIPPER_REPO_URL
from components.moonraker import MOONRAKER_REPO_URL
from core.backup_manager.backup_manager import BackupManager
from core.logger import DialogType, Logger
from core.submodules.simple_config_parser.src.simple_config_parser.simple_config_parser import (
NoOptionError,
NoSectionError,
SimpleConfigParser,
)
from utils.input_utils import get_confirm
@@ -26,13 +27,7 @@ from kiauh import PROJECT_ROOT
DEFAULT_CFG = PROJECT_ROOT.joinpath("default.kiauh.cfg")
CUSTOM_CFG = PROJECT_ROOT.joinpath("kiauh.cfg")
class NoValueError(Exception):
"""Raised when a required value is not defined for an option"""
def __init__(self, section: str, option: str):
msg = f"Missing value for option '{option}' in section '{section}'"
super().__init__(msg)
T = TypeVar("T")
class InvalidValueError(Exception):
@@ -77,6 +72,7 @@ class WebUiSettings:
# noinspection PyMethodMayBeStatic
class KiauhSettings:
__instance = None
__initialized = False
def __new__(cls, *args, **kwargs) -> "KiauhSettings":
if cls.__instance is None:
@@ -94,11 +90,10 @@ class KiauhSettings:
return getattr(self, item)
def __init__(self) -> None:
if not hasattr(self, "__initialized"):
self.__initialized = False
if self.__initialized:
return
self.__initialized = True
self.config = SimpleConfigParser()
self.kiauh = AppSettings()
self.klipper = KlipperSettings()
@@ -106,8 +101,9 @@ class KiauhSettings:
self.mainsail = WebUiSettings()
self.fluidd = WebUiSettings()
self._load_config()
self.__read_config_set_internal_state()
# todo: refactor this, at least rename to something else!
def get(self, section: str, option: str) -> str | int | bool:
"""
Get a value from the settings state by providing the section and option name as
@@ -125,139 +121,175 @@ class KiauhSettings:
raise
def save(self) -> None:
self._set_config_options_state()
self.config.write_file(CUSTOM_CFG)
self._load_config()
self.__write_internal_state_to_cfg()
self.__read_config_set_internal_state()
def _load_config(self) -> None:
def __read_config_set_internal_state(self) -> None:
if not CUSTOM_CFG.exists() and not DEFAULT_CFG.exists():
self.__kill()
cfg = CUSTOM_CFG if CUSTOM_CFG.exists() else DEFAULT_CFG
self.config.read_file(cfg)
needs_migration = self._check_deprecated_repo_config()
if needs_migration:
self._prompt_migration_dialog()
return
else:
# Only validate if no migration was needed
self._validate_cfg()
self.__set_internal_state()
def _validate_cfg(self) -> None:
def __err_and_kill(error: str) -> None:
Logger.print_error(f"Error validating kiauh.cfg: {error}")
Logger.print_dialog(
DialogType.ERROR,
[
"No KIAUH configuration file found! Please make sure you have at least "
"one of the following configuration files in KIAUH's root directory:",
"● default.kiauh.cfg",
"● kiauh.cfg",
],
)
kill()
try:
self._validate_bool("kiauh", "backup_before_update")
# copy default config to custom config if it does not exist
if not CUSTOM_CFG.exists():
shutil.copyfile(DEFAULT_CFG, CUSTOM_CFG)
self._validate_repositories("klipper", "repositories")
self._validate_repositories("moonraker", "repositories")
self.config.read_file(CUSTOM_CFG)
self._validate_int("mainsail", "port")
self._validate_bool("mainsail", "unstable_releases")
# check if there are deprecated repo_url and branch options in the kiauh.cfg
if self._check_deprecated_repo_config():
self._prompt_migration_dialog()
self._validate_int("fluidd", "port")
self._validate_bool("fluidd", "unstable_releases")
except ValueError:
err = f"Invalid value for option '{self._v_option}' in section '{self._v_section}'"
__err_and_kill(err)
except NoSectionError:
err = f"Missing section '{self._v_section}' in config file"
__err_and_kill(err)
except NoOptionError:
err = f"Missing option '{self._v_option}' in section '{self._v_section}'"
__err_and_kill(err)
except NoValueError:
err = f"Missing value for option '{self._v_option}' in section '{self._v_section}'"
__err_and_kill(err)
def _validate_bool(self, section: str, option: str) -> None:
self._v_section, self._v_option = (section, option)
(bool(self.config.getboolean(section, option)))
def _validate_int(self, section: str, option: str) -> None:
self._v_section, self._v_option = (section, option)
int(self.config.getint(section, option))
def _validate_str(self, section: str, option: str) -> None:
self._v_section, self._v_option = (section, option)
v = self.config.getval(section, option)
if not v:
raise ValueError
def _validate_repositories(self, section: str, option: str) -> None:
self._v_section, self._v_option = (section, option)
repos = self.config.getval(section, option)
if not repos:
raise NoValueError(section, option)
for repo in repos:
if repo.strip().startswith("#") or repo.strip().startswith(";"):
continue
try:
if "," in repo:
url, branch = repo.strip().split(",")
if not url:
raise InvalidValueError(section, option, repo)
else:
url = repo.strip()
if not url:
raise InvalidValueError(section, option, repo)
except ValueError:
raise InvalidValueError(section, option, repo)
self.__set_internal_state()
def __set_internal_state(self) -> None:
self.kiauh.backup_before_update = self.config.getboolean(
"kiauh", "backup_before_update"
# parse Kiauh options
self.kiauh.backup_before_update = self.__read_from_cfg(
"kiauh",
"backup_before_update",
self.config.getboolean,
False,
)
self.moonraker.optional_speedups = self.config.getboolean(
"moonraker", "optional_speedups", True
# parse Klipper options
self.klipper.use_python_binary = self.__read_from_cfg(
"klipper",
"use_python_binary",
self.config.getval,
None,
True,
)
kl_repos: List[str] = self.__read_from_cfg(
"klipper",
"repositories",
self.config.getvals,
[KLIPPER_REPO_URL],
)
self.klipper.repositories = self.__set_repo_state("klipper", kl_repos)
# parse Moonraker options
self.moonraker.use_python_binary = self.__read_from_cfg(
"moonraker",
"use_python_binary",
self.config.getval,
None,
True,
)
self.moonraker.optional_speedups = self.__read_from_cfg(
"moonraker",
"optional_speedups",
self.config.getboolean,
True,
)
mr_repos: List[str] = self.__read_from_cfg(
"moonraker",
"repositories",
self.config.getvals,
[MOONRAKER_REPO_URL],
)
self.moonraker.repositories = self.__set_repo_state("moonraker", mr_repos)
# parse Mainsail options
self.mainsail.port = self.__read_from_cfg(
"mainsail",
"port",
self.config.getint,
80,
)
self.mainsail.unstable_releases = self.__read_from_cfg(
"mainsail",
"unstable_releases",
self.config.getboolean,
False,
)
kl_repos = self.config.getval("klipper", "repositories")
self.klipper.repositories = self.__set_repo_state(kl_repos)
mr_repos = self.config.getval("moonraker", "repositories")
self.moonraker.repositories = self.__set_repo_state(mr_repos)
self.klipper.use_python_binary = self.config.getval(
"klipper", "use_python_binary", None
# parse Fluidd options
self.fluidd.port = self.__read_from_cfg(
"fluidd",
"port",
self.config.getint,
80,
)
self.moonraker.use_python_binary = self.config.getval(
"moonraker", "use_python_binary", None
self.fluidd.unstable_releases = self.__read_from_cfg(
"fluidd",
"unstable_releases",
self.config.getboolean,
False,
)
self.mainsail.port = self.config.getint("mainsail", "port")
self.mainsail.unstable_releases = self.config.getboolean(
"mainsail", "unstable_releases"
)
self.fluidd.port = self.config.getint("fluidd", "port")
self.fluidd.unstable_releases = self.config.getboolean(
"fluidd", "unstable_releases"
)
def __check_option_exists(
self, section: str, option: str, fallback: Any, silent: bool = False
) -> bool:
has_section = self.config.has_section(section)
has_option = self.config.has_option(section, option)
def __set_repo_state(self, repos: List[str]) -> List[Repository]:
if not (has_section and has_option):
if not silent:
Logger.print_warn(
f"Option '{option}' in section '{section}' not defined. Falling back to '{fallback}'."
)
return False
return True
def __read_bool_from_cfg(
self,
section: str,
option: str,
fallback: bool | None = None,
silent: bool = False,
) -> bool | None:
if not self.__check_option_exists(section, option, fallback, silent):
return fallback
return self.config.getboolean(section, option, fallback)
def __read_from_cfg(
self,
section: str,
option: str,
getter: Callable[[str, str, T | None], T],
fallback: T = None,
silent: bool = False,
) -> T:
if not self.__check_option_exists(section, option, fallback, silent):
return fallback
return getter(section, option, fallback)
def __set_repo_state(self, section: str, repos: List[str]) -> List[Repository]:
_repos: List[Repository] = []
for repo in repos:
try:
if repo.strip().startswith("#") or repo.strip().startswith(";"):
continue
if "," in repo:
url, branch = repo.strip().split(",")
if not branch:
branch = "master"
else:
url = repo.strip()
branch = "master"
# url must not be empty otherwise it's considered
# as an unrecoverable, invalid configuration
if not url:
raise InvalidValueError(section, "repositories", repo)
_repos.append(Repository(url.strip(), branch.strip()))
except InvalidValueError as e:
Logger.print_error(f"Error parsing kiauh.cfg: {e}")
kill()
return _repos
def _set_config_options_state(self) -> None:
def __write_internal_state_to_cfg(self) -> None:
"""Updates the config with current settings, preserving values that haven't been modified"""
if self.kiauh.backup_before_update is not None:
self.config.set_option(
@@ -295,6 +327,8 @@ class KiauhSettings:
"fluidd", "unstable_releases", str(self.fluidd.unstable_releases)
)
self.config.write_file(CUSTOM_CFG)
def _check_deprecated_repo_config(self) -> bool:
# repo_url and branch are deprecated - 2025.03.23
for section in ["klipper", "moonraker"]:
@@ -306,22 +340,23 @@ class KiauhSettings:
def _prompt_migration_dialog(self) -> None:
migration_1: List[str] = [
"The old 'repo_url' and 'branch' options are now combined under 'repositories'.",
"Options 'repo_url' and 'branch' are now combined into a 'repositories' option.",
"\n\n",
"Example format:",
"● Old format:",
" [klipper]",
" repo_url: https://github.com/Klipper3d/klipper",
" branch: master",
"\n\n",
"● New format:",
" [klipper]",
" repositories:",
" https://github.com/Klipper3d/klipper, master",
"\n\n",
"[moonraker]",
"repositories:",
" https://github.com/Arksine/moonraker, master",
]
Logger.print_dialog(
DialogType.ATTENTION,
[
"Deprecated repository configuration found!",
"KAIUH can now attempt to automatically migrate your configuration.",
"Deprecated kiauh.cfg configuration found!",
"KAIUH can now attempt to automatically migrate the configuration.",
"\n\n",
*migration_1,
],
@@ -332,7 +367,7 @@ class KiauhSettings:
Logger.print_dialog(
DialogType.ERROR,
[
"Please update your configuration file manually.",
"Please update the configuration file manually.",
],
center_content=True,
)
@@ -373,23 +408,7 @@ class KiauhSettings:
self.config.write_file(CUSTOM_CFG)
self.config.read_file(CUSTOM_CFG) # reload config
# Validate the migrated config
self._validate_cfg()
self.__set_internal_state()
except Exception as e:
Logger.print_error(f"Error migrating configuration: {e}")
Logger.print_error("Please migrate manually.")
kill()
def __kill(self) -> None:
Logger.print_dialog(
DialogType.ERROR,
[
"No KIAUH configuration file found! Please make sure you have at least "
"one of the following configuration files in KIAUH's root directory:",
"● default.kiauh.cfg",
"● kiauh.cfg",
],
)
kill()

View File

@@ -12,6 +12,7 @@ Specialized for handling Klipper style config files.
- Option Block: A line starting with a word, followed by a `:` or `=` and a newline
- Comment: A line starting with a `#` or `;`
- Blank: A line containing only whitespace characters
- SaveConfig: Klippers auto-generated SAVE_CONFIG section that can be found at the very end of the config file
---

View File

@@ -49,6 +49,9 @@ LINE_COMMENT_RE = re.compile(r"^\s*[#;].*")
# - the line MUST contain only whitespace characters
EMPTY_LINE_RE = re.compile(r"^\s*$")
SAVE_CONFIG_START_RE = re.compile(r"^#\*# <-+ SAVE_CONFIG -+>$")
SAVE_CONFIG_CONTENT_RE = re.compile(r"^#\*#.*$")
BOOLEAN_STATES = {
"1": True,
"yes": True,

View File

@@ -18,7 +18,7 @@ from ..simple_config_parser.constants import (
LINE_COMMENT_RE,
OPTION_RE,
OPTIONS_BLOCK_START_RE,
SECTION_RE, LineType, INDENT,
SECTION_RE, LineType, INDENT, SAVE_CONFIG_START_RE, SAVE_CONFIG_CONTENT_RE,
)
_UNSET = object()
@@ -61,25 +61,34 @@ class SimpleConfigParser:
def __init__(self) -> None:
self.header: List[str] = []
self.save_config_block: List[str] = []
self.config: Dict = {}
self.current_section: str | None = None
self.current_opt_block: str | None = None
self.in_option_block: bool = False
def _match_section(self, line: str) -> bool:
"""Wheter or not the given line matches the definition of a section"""
"""Whether the given line matches the definition of a section"""
return SECTION_RE.match(line) is not None
def _match_option(self, line: str) -> bool:
"""Wheter or not the given line matches the definition of an option"""
"""Whether the given line matches the definition of an option"""
return OPTION_RE.match(line) is not None
def _match_options_block_start(self, line: str) -> bool:
"""Wheter or not the given line matches the definition of a multiline option"""
"""Whether the given line matches the definition of a multiline option"""
return OPTIONS_BLOCK_START_RE.match(line) is not None
def _match_save_config_start(self, line: str) -> bool:
"""Whether the given line matches the definition of a save config start"""
return SAVE_CONFIG_START_RE.match(line) is not None
def _match_save_config_content(self, line: str) -> bool:
"""Whether the given line matches the definition of a save config content"""
return SAVE_CONFIG_CONTENT_RE.match(line) is not None
def _match_line_comment(self, line: str) -> bool:
"""Wheter or not the given line matches the definition of a comment"""
"""Whether the given line matches the definition of a comment"""
return LINE_COMMENT_RE.match(line) is not None
def _match_empty_line(self, line: str) -> bool:
@@ -124,6 +133,14 @@ class SimpleConfigParser:
element["value"].append(line.strip()) # indentation is removed
break
elif self._match_save_config_start(line):
self.current_opt_block = None
self.save_config_block.append(line)
elif self._match_save_config_content(line):
self.current_opt_block = None
self.save_config_block.append(line)
elif self._match_empty_line(line) or self._match_line_comment(line):
self.current_opt_block = None
@@ -185,6 +202,11 @@ class SimpleConfigParser:
if not last_line.endswith("\n"):
f.write("\n")
if self.save_config_block:
for line in self.save_config_block:
f.write(line)
f.write("\n")
def get_sections(self) -> List[str]:
"""Return a list of all section names, but exclude any section starting with '#_'"""
return list(
@@ -314,9 +336,7 @@ class SimpleConfigParser:
elements.pop(i)
break
def getval(
self, section: str, option: str, fallback: str | _UNSET = _UNSET
) -> str | List[str]:
def getval(self, section: str, option: str, fallback: str | _UNSET = _UNSET) -> str:
"""
Return the value of the given option in the given section
@@ -329,22 +349,34 @@ class SimpleConfigParser:
if option not in self.get_options(section):
raise NoOptionError(option, section)
# Find the option in the elements list
for element in self.config[section]["elements"]:
if element["type"] in [LineType.OPTION.value, LineType.OPTION_BLOCK.value] and element["name"] == option:
raw_value = element["value"]
if isinstance(raw_value, str) and raw_value.endswith("\n"):
return raw_value[:-1].strip()
elif isinstance(raw_value, list):
values: List[str] = []
for i, val in enumerate(raw_value):
val = val.strip().strip("\n")
if len(val) < 1:
continue
values.append(val.strip())
return values
return str(raw_value)
if element["type"] is LineType.OPTION.value and element["name"] == option:
return str(element["value"].strip().replace("\n", ""))
return ""
except (NoSectionError, NoOptionError):
if fallback is _UNSET:
raise
return fallback
def getvals(self, section: str, option: str, fallback: List[str] | _UNSET = _UNSET) -> List[str]:
"""
Return the values of the given multi-line option in the given section
If the key is not found and 'fallback' is provided, it is used as
a fallback value.
"""
try:
if section not in self.get_sections():
raise NoSectionError(section)
if option not in self.get_options(section):
raise NoOptionError(option, section)
for element in self.config[section]["elements"]:
if element["type"] is LineType.OPTION_BLOCK.value and element["name"] == option:
return [val.strip() for val in element["value"] if val.strip()]
return []
except (NoSectionError, NoOptionError):
if fallback is _UNSET:
raise

View File

@@ -0,0 +1,116 @@
# a comment at the very top
# should be treated as the file header
# up to the first section, including all blank lines
[section_1]
option_1: value_1
option_1_1: True # this is a boolean
option_1_2: 5 ; this is an integer
option_1_3: 1.123 #;this is a float
[section_2] ; comment
option_2: value_2
; comment
[section_3]
option_3: value_3 # comment
[section_4]
# comment
option_4: value_4
[section number 5]
#option_5: value_5
option_5 = this.is.value-5
multi_option:
# these are multi-line values
value_5_1
value_5_2 ; here is a comment
value_5_3
option_5_1: value_5_1
[gcode_macro M117]
rename_existing: M117.1
gcode:
{% if rawparams %}
{% set escaped_msg = rawparams.split(';', 1)[0].split('\x23', 1)[0]|replace('"', '\\"') %}
SET_DISPLAY_TEXT MSG="{escaped_msg}"
RESPOND TYPE=command MSG="{escaped_msg}"
{% else %}
SET_DISPLAY_TEXT
{% endif %}
# SDCard 'looping' (aka Marlin M808 commands) support
#
# Support SDCard looping
[sdcard_loop]
[gcode_macro M486]
gcode:
# Parameters known to M486 are as follows:
# [C<flag>] Cancel the current object
# [P<index>] Cancel the object with the given index
# [S<index>] Set the index of the current object.
# If the object with the given index has been canceled, this will cause
# the firmware to skip to the next object. The value -1 is used to
# indicate something that isnt an object and shouldnt be skipped.
# [T<count>] Reset the state and set the number of objects
# [U<index>] Un-cancel the object with the given index. This command will be
# ignored if the object has already been skipped
{% if 'exclude_object' not in printer %}
{action_raise_error("[exclude_object] is not enabled")}
{% endif %}
{% if 'T' in params %}
EXCLUDE_OBJECT RESET=1
{% for i in range(params.T | int) %}
EXCLUDE_OBJECT_DEFINE NAME={i}
{% endfor %}
{% endif %}
{% if 'C' in params %}
EXCLUDE_OBJECT CURRENT=1
{% endif %}
{% if 'P' in params %}
EXCLUDE_OBJECT NAME={params.P}
{% endif %}
{% if 'S' in params %}
{% if params.S == '-1' %}
{% if printer.exclude_object.current_object %}
EXCLUDE_OBJECT_END NAME={printer.exclude_object.current_object}
{% endif %}
{% else %}
EXCLUDE_OBJECT_START NAME={params.S}
{% endif %}
{% endif %}
{% if 'U' in params %}
EXCLUDE_OBJECT RESET=1 NAME={params.U}
{% endif %}
#*# <---------------------- SAVE_CONFIG ---------------------->
#*# DO NOT EDIT THIS BLOCK OR BELOW. The contents are auto-generated.
#*#
#*# [bed_mesh default]
#*# version = 1
#*# points =
#*# -0.152500, -0.133125, -0.113125, -0.159375, -0.232500
#*# -0.095000, -0.078750, -0.068125, -0.133125, -0.235000
#*# -0.092500, -0.040625, 0.004375, -0.077500, -0.193125
#*# -0.073750, 0.023750, 0.085625, 0.026875, -0.085000
#*# -0.140625, 0.038125, 0.126250, 0.097500, 0.003750
#*# tension = 0.2
#*# min_x = 26.0
#*# algo = bicubic
#*# y_count = 5
#*# mesh_y_pps = 2
#*# min_y = 5.0
#*# x_count = 5
#*# max_y = 174.0
#*# mesh_x_pps = 2
#*# max_x = 194.0

View File

@@ -0,0 +1,22 @@
#*# any content
#*#
#*# DO NOT EDIT THIS BLOCK OR BELOW. The contents are auto-generated.
#*#
#*# [bed_mesh default]
#*# version = 1
#*# points =
#*# -0.152500, -0.133125, -0.113125, -0.159375, -0.232500
#*# -0.095000, -0.078750, -0.068125, -0.133125, -0.235000
#*# -0.092500, -0.040625, 0.004375, -0.077500, -0.193125
#*# -0.073750, 0.023750, 0.085625, 0.026875, -0.085000
#*# -0.140625, 0.038125, 0.126250, 0.097500, 0.003750
#*# tension = 0.2
#*# min_x = 26.0
#*# algo = bicubic
#*# y_count = 5
#*# mesh_y_pps = 2
#*# min_y = 5.0
#*# x_count = 5
#*# max_y = 174.0
#*# mesh_x_pps = 2
#*# max_x = 194.0

View File

@@ -0,0 +1,6 @@
#*# leading space prevents match
random
*# not starting with hash-star-hash
# *# spaced out
<- SAVE_CONFIG ->
;#*# semicolon first

View File

@@ -0,0 +1,37 @@
# ======================================================================= #
# Copyright (C) 2024 Dominik Willner <th33xitus@gmail.com> #
# #
# https://github.com/dw-0/simple-config-parser #
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
# ======================================================================= #
from pathlib import Path
import pytest
from src.simple_config_parser.simple_config_parser import SimpleConfigParser
from tests.utils import load_testdata_from_file
BASE_DIR = Path(__file__).parent.joinpath("test_data")
MATCHING_TEST_DATA_PATH = BASE_DIR.joinpath("matching_data.txt")
NON_MATCHING_TEST_DATA_PATH = BASE_DIR.joinpath("non_matching_data.txt")
@pytest.fixture
def parser():
return SimpleConfigParser()
def test_matching_lines(parser):
"""Alle Zeilen in matching_data.txt sollen als Save-Config-Content erkannt werden."""
matching_lines = load_testdata_from_file(MATCHING_TEST_DATA_PATH)
for line in matching_lines:
assert parser._match_save_config_content(line) is True, f"Line should be a save config content: {line!r}"
def test_non_matching_lines(parser):
"""Alle Zeilen in non_matching_data.txt sollen NICHT als Save-Config-Content erkannt werden."""
non_matching_lines = load_testdata_from_file(NON_MATCHING_TEST_DATA_PATH)
for line in non_matching_lines:
assert parser._match_save_config_content(line) is False, f"Line should not be a save config content: {line!r}"

View File

@@ -0,0 +1,6 @@
#*# <- SAVE_CONFIG ->
#*# <---- SAVE_CONFIG ---->
#*# <------------------- SAVE_CONFIG ------------------->
#*# <---------------------- SAVE_CONFIG ---------------------->
#*# <----- SAVE_CONFIG ->
#*# <- SAVE_CONFIG ----------------->

View File

@@ -0,0 +1,13 @@
#*#<- SAVE_CONFIG ->
#*# <-SAVE_CONFIG ->
#*# <- SAVE_CONFIG->
#*# <- SAVE_CONFIG -> extra
#*# SAVE_CONFIG ---->
#*# < SAVE_CONFIG >
# *# <- SAVE_CONFIG ->
<- SAVE_CONFIG ->
random text
#*# <---------------------- SAVE_CONFIG ---------------------->
#*# <---------------------- SAVE_CONFIG ----------------------> #*#
#*# <-------------------------------------------->
#*# SAVE_CONFIG

View File

@@ -0,0 +1,37 @@
# ======================================================================= #
# Copyright (C) 2024 Dominik Willner <th33xitus@gmail.com> #
# #
# https://github.com/dw-0/simple-config-parser #
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
# ======================================================================= #
from pathlib import Path
import pytest
from src.simple_config_parser.simple_config_parser import SimpleConfigParser
from tests.utils import load_testdata_from_file
BASE_DIR = Path(__file__).parent.joinpath("test_data")
MATCHING_TEST_DATA_PATH = BASE_DIR.joinpath("matching_data.txt")
NON_MATCHING_TEST_DATA_PATH = BASE_DIR.joinpath("non_matching_data.txt")
@pytest.fixture
def parser():
return SimpleConfigParser()
def test_matching_lines(parser):
"""Test that all lines in the matching data file are correctly identified as save config start lines."""
matching_lines = load_testdata_from_file(MATCHING_TEST_DATA_PATH)
for line in matching_lines:
assert parser._match_save_config_start(line) is True, f"Line should be a save config start: {line!r}"
def test_non_matching_lines(parser):
"""Test that all lines in the non-matching data file are correctly identified as not save config start lines."""
non_matching_lines = load_testdata_from_file(NON_MATCHING_TEST_DATA_PATH)
for line in non_matching_lines:
assert parser._match_save_config_start(line) is False, f"Line should not be a save config start: {line!r}"

View File

@@ -13,7 +13,7 @@ from src.simple_config_parser.simple_config_parser import SimpleConfigParser
from tests.utils import load_testdata_from_file
BASE_DIR = Path(__file__).parent.parent.joinpath("assets")
CONFIG_FILES = ["test_config_1.cfg", "test_config_2.cfg", "test_config_3.cfg"]
CONFIG_FILES = ["test_config_1.cfg", "test_config_2.cfg", "test_config_3.cfg", "test_config_4.cfg"]
@pytest.fixture(params=CONFIG_FILES)

View File

@@ -51,7 +51,7 @@ def test_getval(parser):
assert parser.getval("section_2", "option_2") == "value_2"
# test multiline option values
ml_val = parser.getval("section number 5", "multi_option")
ml_val = parser.getvals("section number 5", "multi_option")
assert isinstance(ml_val, list)
assert len(ml_val) > 0
@@ -164,7 +164,7 @@ def test_set_new_option(parser):
assert parser.getval("new_section", "very_new_option") == "very_new_value"
parser.set_option("section_2", "array_option", ["value_1", "value_2", "value_3"])
assert parser.getval("section_2", "array_option") == [
assert parser.getvals("section_2", "array_option") == [
"value_1",
"value_2",
"value_3",

View File

@@ -143,6 +143,31 @@ class ExtensionSubmenu(BaseMenu):
"""
)[1:]
menu += f"{description_text}\n"
# add links if available
website: str = (self.extension.metadata.get("website") or "").strip()
repo: str = (self.extension.metadata.get("repo") or "").strip()
if website or repo:
links_lines: List[str] = ["Links:"]
if website:
links_lines.append(f"{website}")
if repo:
links_lines.append(f"{repo}")
links_text = Logger.format_content(
links_lines,
line_width,
border_left="",
border_right="",
)
menu += textwrap.dedent(
"""
╟───────────────────────────────────────────────────────╢
"""
)[1:]
menu += f"{links_text}\n"
menu += textwrap.dedent(
"""
╟───────────────────────────────────────────────────────╢

View File

@@ -4,6 +4,7 @@
"module": "gcode_shell_cmd_extension",
"maintained_by": "dw-0",
"display_name": "G-Code Shell Command",
"description": ["Run a shell commands from gcode."]
"description": ["Run a shell commands from gcode."],
"updates": false
}
}

View File

@@ -5,6 +5,8 @@
"maintained_by": "Staubgeborener",
"display_name": "Klipper-Backup",
"description": ["Backup all your Klipper files to GitHub"],
"website": "https://klipperbackup.xyz",
"repo": "https://github.com/Staubgeborener/klipper-backup",
"updates": true
}
}

View File

@@ -4,6 +4,8 @@
"module": "mainsail_theme_installer_extension",
"maintained_by": "dw-0",
"display_name": "Mainsail Theme Installer",
"description": ["Install Mainsail Themes maintained by the Mainsail community."]
"description": ["Install Mainsail Themes maintained by the Mainsail community."],
"website": "https://docs.mainsail.xyz/theming/themes",
"updates": false
}
}

View File

@@ -7,6 +7,7 @@
"description": [
"Companion for Mobileraker, enabling push notification for Klipper using Moonraker."
],
"repo": "https://github.com/Clon1998/mobileraker_companion",
"updates": true
}
}

View File

@@ -11,6 +11,8 @@
"- 25FPS High-Def Webcam Streaming",
"- Free 4.9-Star Mobile App"
],
"website": "https://obico.io",
"repo": "github.com/TheSpaghettiDetective/moonraker-obico",
"updates": true
}
}

View File

@@ -12,6 +12,7 @@
"- Live Gcode preview",
"- And much much more!"
],
"repo": "https://github.com/crysxd/OctoApp-Plugin",
"updates": true
}
}

View File

@@ -11,6 +11,8 @@
"- Real-time Notifications",
"- Live Streaming, and More!"
],
"website": "https://octoeverywhere.com",
"repo": "github.com/QuinnDamerell/OctoPrint-OctoEverywhere",
"updates": true
}
}

View File

@@ -0,0 +1,22 @@
# ======================================================================= #
# Copyright (C) 2020 - 2025 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 pathlib import Path
# Constants
OP_DEFAULT_PORT = 5000
# OctoPrint instance naming/prefixes
OP_ENV_PREFIX = "OctoPrint"
OP_BASEDIR_PREFIX = ".octoprint"
# Service/log filenames
OP_LOG_NAME = "octoprint.log"
# Files/paths (computed per-instance where applicable)
OP_SUDOERS_FILE = Path("/etc/sudoers.d/octoprint-shutdown")

View File

@@ -0,0 +1,18 @@
{
"metadata": {
"index": 12,
"module": "octoprint_extension",
"maintained_by": "dw-0",
"display_name": "OctoPrint",
"description": [
"Open-source web interface to control and monitor your 3D printer",
"- Upload and manage G-code, start/pause/cancel prints",
"- Live webcam view and timelapse support",
"- Real-time temperature graphs and printer status",
"- Powerful plugin ecosystem"
],
"website": "https://octoprint.org",
"repo": "https://github.com/OctoPrint/OctoPrint",
"updates": false
}
}

View File

@@ -0,0 +1,116 @@
# ======================================================================= #
# Copyright (C) 2020 - 2025 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 __future__ import annotations
from dataclasses import dataclass, field
from pathlib import Path
from textwrap import dedent
from components.klipper.klipper import Klipper
from core.constants import CURRENT_USER
from core.instance_manager.base_instance import BaseInstance
from core.logger import Logger
from extensions.octoprint import (
OP_BASEDIR_PREFIX,
OP_ENV_PREFIX,
OP_LOG_NAME,
)
from utils.fs_utils import create_folders
from utils.sys_utils import create_service_file, get_service_file_path
@dataclass
class Octoprint:
suffix: str
base: BaseInstance = field(init=False, repr=False)
service_file_path: Path = field(init=False)
log_file_name = OP_LOG_NAME
env_dir: Path = field(init=False)
basedir: Path = field(init=False)
cfg_file: Path = field(init=False)
def __post_init__(self):
self.base = BaseInstance(Klipper, self.suffix)
self.base.log_file_name = self.log_file_name
self.service_file_path = get_service_file_path(Octoprint, self.suffix)
# OctoPrint stores its data under ~/.octoprint[_SUFFIX]
self.basedir = (
Path.home().joinpath(OP_BASEDIR_PREFIX)
if self.suffix == ""
else Path.home().joinpath(f"{OP_BASEDIR_PREFIX}_{self.suffix}")
)
self.cfg_file = self.basedir.joinpath("config.yaml")
# OctoPrint virtualenv lives under ~/OctoPrint[_SUFFIX]
self.env_dir = (
Path.home().joinpath(OP_ENV_PREFIX)
if self.suffix == ""
else Path.home().joinpath(f"{OP_ENV_PREFIX}_{self.suffix}")
)
def create(self, port: int) -> None:
Logger.print_status(
f"Creating OctoPrint instance '{self.service_file_path.stem}' ..."
)
# Ensure basedir exists and config.yaml is present
create_folders([self.basedir])
if not self.cfg_file.exists():
Logger.print_status("Creating config.yaml ...")
self.cfg_file.write_text(self._prep_config_yaml())
Logger.print_ok("config.yaml created!")
else:
Logger.print_info("config.yaml already exists. Skipped ...")
create_service_file(self.service_file_path.name, self._prep_service_content(port))
def _prep_service_content(self, port: int) -> str:
basedir = self.basedir.as_posix()
cfg = self.cfg_file.as_posix()
octo_exec = self.env_dir.joinpath("bin/octoprint").as_posix()
return dedent(
f"""\
[Unit]
Description=Starts OctoPrint on startup
After=network-online.target
Wants=network-online.target
[Service]
Environment="LC_ALL=C.UTF-8"
Environment="LANG=C.UTF-8"
Type=simple
User={CURRENT_USER}
ExecStart={octo_exec} --basedir {basedir} --config {cfg} --port={port} serve
[Install]
WantedBy=multi-user.target
"""
)
def _prep_config_yaml(self) -> str:
printer = self.base.comms_dir.joinpath("klippy.serial").as_posix()
restart_service = self.service_file_path.stem
return dedent(
f"""\
serial:
additionalPorts:
- {printer}
disconnectOnErrors: false
port: {printer}
server:
commands:
serverRestartCommand: sudo service {restart_service} restart
systemRestartCommand: sudo shutdown -r now
systemShutdownCommand: sudo shutdown -h now
"""
)

View File

@@ -0,0 +1,286 @@
# ======================================================================= #
# Copyright (C) 2020 - 2025 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 __future__ import annotations
import re
from typing import Dict, List, Optional, Set
from components.klipper.klipper import Klipper
from core.instance_manager.instance_manager import InstanceManager
from core.logger import DialogType, Logger
from core.types.color import Color
from core.menus.base_menu import print_back_footer
from extensions.base_extension import BaseExtension
from extensions.octoprint import (
OP_SUDOERS_FILE, OP_DEFAULT_PORT,
)
from extensions.octoprint.octoprint import Octoprint
from utils.common import check_install_dependencies
from utils.fs_utils import run_remove_routines, remove_with_sudo
from utils.input_utils import get_selection_input, get_confirm
from utils.instance_utils import get_instances
from utils.sys_utils import (
create_python_venv,
get_ipv4_addr,
install_python_packages,
)
# noinspection PyMethodMayBeStatic
class OctoprintExtension(BaseExtension):
def install_extension(self, **kwargs) -> None:
Logger.print_status("Installing OctoPrint ...")
klipper_instances: List[Klipper] = get_instances(Klipper)
if not klipper_instances:
Logger.print_dialog(
DialogType.WARNING,
[
"Klipper not found! Please install Klipper first.",
],
)
return
existing_ops: List[Octoprint] = get_instances(Octoprint)
existing_by_suffix: Dict[str, Octoprint] = {op.suffix: op for op in existing_ops}
candidates: List[Klipper] = [k for k in klipper_instances if k.suffix not in existing_by_suffix]
chosen: List[Klipper] = []
if len(klipper_instances) == 1:
k = klipper_instances[0]
if k.suffix in existing_by_suffix:
if not get_confirm(
f"OctoPrint already exists for '{k.service_file_path.stem}'. Reinstall?",
default_choice=True,
allow_go_back=True,
):
Logger.print_info("Aborted OctoPrint installation.")
return
chosen = [k]
else:
while True:
dialog = "╔═══════════════════════════════════════════════════════╗\n"
headline = Color.apply(
"The following Klipper instances were found:", Color.GREEN
)
dialog += f"{headline:^64}\n"
dialog += "╟───────────────────────────────────────────────────────╢\n"
if candidates:
line_all = Color.apply("a) Select all (install for all missing)", Color.YELLOW)
dialog += f"{line_all:<63}\n"
dialog += "║ ║\n"
index_map: Dict[str, Klipper] = {}
for i, k in enumerate(klipper_instances, start=1):
mapping = existing_by_suffix.get(k.suffix)
suffix = f" <-> {mapping.service_file_path.stem}" if mapping else ""
line = Color.apply(f"{i}) {k.service_file_path.stem}{suffix}", Color.CYAN)
dialog += f"{line:<63}\n"
index_map[str(i)] = k
dialog += "╟───────────────────────────────────────────────────────╢\n"
print(dialog, end="")
print_back_footer()
allowed = list(index_map.keys()) + ["b"] + (["a"] if candidates else [])
choice = get_selection_input("Choose instance to install OctoPrint for", allowed)
if choice == "b":
Logger.print_info("Aborted OctoPrint installation.")
return
if choice == "a":
chosen = candidates
break
selected = index_map[choice]
if selected.suffix in existing_by_suffix:
confirm = get_confirm(
f"OctoPrint already exists for '{selected.service_file_path.stem}'. Reinstall?",
default_choice=True,
allow_go_back=True,
)
if not confirm:
# back to menu
continue
chosen = [selected]
break
deps = {
"git",
"wget",
"python3-pip",
"python3-dev",
"libyaml-dev",
"build-essential",
"python3-setuptools",
"python3-virtualenv",
}
check_install_dependencies(deps)
# Determine used ports from existing OctoPrint services and prepare regex
used_ports: Set[int] = set()
port_re = re.compile(r"--port=(\d+)")
for op in existing_ops:
try:
content = op.service_file_path.read_text()
m = port_re.search(content)
if m:
used_ports.add(int(m.group(1)))
except OSError:
pass
# noinspection PyShadowingNames
def read_existing_port(suffix: str) -> Optional[int]:
op = existing_by_suffix.get(suffix)
if not op:
return None
try:
content = op.service_file_path.read_text()
m = port_re.search(content)
return int(m.group(1)) if m else None
except OSError:
return None
def next_free_port(start: int, used: Set[int]) -> int:
p = start
while p in used:
p += 1
used.add(p)
return p
created_ops: List[Octoprint] = []
for k in chosen:
# Keep existing port on reinstall, otherwise assign next free one
existing_port = read_existing_port(k.suffix)
port = existing_port if existing_port is not None else next_free_port(OP_DEFAULT_PORT, used_ports)
instance = Octoprint(suffix=k.suffix)
if create_python_venv(instance.env_dir, force=False):
Logger.print_ok(
f"Virtualenv created: {instance.env_dir}", prefix=False
)
else:
Logger.print_info(
f"Virtualenv exists: {instance.env_dir}. Skipping creation ..."
)
install_python_packages(instance.env_dir, ["octoprint"])
instance.create(port=port)
created_ops.append(instance)
for inst in created_ops:
try:
InstanceManager.enable(inst)
InstanceManager.start(inst)
except Exception as e:
Logger.print_error(
f"Failed to enable/start {inst.service_file_path.name}: {e}"
)
ip = get_ipv4_addr()
lines = ["Access your new OctoPrint instance(s) at:"]
for inst in created_ops:
try:
content = inst.service_file_path.read_text()
m = port_re.search(content)
if m:
# noinspection HttpUrlsUsage
lines.append(f"{inst.service_file_path.stem}: http://{ip}:{m.group(1)}")
except OSError:
pass
Logger.print_dialog(DialogType.SUCCESS, lines, center_content=False)
def remove_extension(self, **kwargs) -> None:
Logger.print_status("Removing OctoPrint ...")
try:
op_instances: List[Octoprint] = get_instances(Octoprint)
if not op_instances:
Logger.print_info("No OctoPrint instances found. Skipped ...")
return
remove_all = False
if len(op_instances) == 1:
to_remove = op_instances
else:
dialog = "╔═══════════════════════════════════════════════════════╗\n"
headline = Color.apply(
"The following OctoPrint instances were found:", Color.GREEN
)
dialog += f"{headline:^64}\n"
dialog += "╟───────────────────────────────────────────────────────╢\n"
select_all = Color.apply("a) Select all", Color.YELLOW)
dialog += f"{select_all:<63}\n"
dialog += "║ ║\n"
for i, inst in enumerate(op_instances, start=1):
line = Color.apply(
f"{i}) {inst.service_file_path.stem}", Color.CYAN
)
dialog += f"{line:<63}\n"
dialog += "╟───────────────────────────────────────────────────────╢\n"
print(dialog, end="")
print_back_footer()
allowed = [str(i) for i in range(1, len(op_instances) + 1)]
allowed.extend(["a", "b"])
choice = get_selection_input("Choose instance to remove", allowed)
if choice == "a":
remove_all = True
to_remove = op_instances
elif choice == "b":
Logger.print_info("Aborted OctoPrint removal.")
return
else:
idx = int(choice) - 1
to_remove = [op_instances[idx]]
for inst in to_remove:
Logger.print_status(
f"Removing instance {inst.service_file_path.stem} ..."
)
try:
InstanceManager.remove(inst)
except Exception as e:
Logger.print_error(
f"Failed to remove service {inst.service_file_path.name}: {e}"
)
# Remove only this instance's env and basedir
if inst.env_dir.exists():
Logger.print_status(f"Removing {inst.env_dir} ...")
run_remove_routines(inst.env_dir)
if inst.basedir.exists():
Logger.print_status(f"Removing {inst.basedir} ...")
run_remove_routines(inst.basedir)
# Remove sudoers file only if no instances remain
remaining = get_instances(Octoprint)
if not remaining and OP_SUDOERS_FILE.exists():
Logger.print_status(f"Removing {OP_SUDOERS_FILE} ...")
remove_with_sudo(OP_SUDOERS_FILE)
Logger.print_dialog(
DialogType.SUCCESS,
[
"Selected OctoPrint instance(s) successfully removed!"
if not remove_all
else "All OctoPrint instances successfully removed!",
],
center_content=True,
)
except Exception as e:
Logger.print_error(f"Error during OctoPrint removal: {e}")

View File

@@ -5,6 +5,7 @@
"maintained_by": "Kragrathea",
"display_name": "PrettyGCode for Klipper",
"description": ["3D G-Code viewer for Klipper"],
"repo": "https://github.com/Kragrathea/pgcode",
"updates": true
}
}

View File

@@ -8,6 +8,9 @@
"3D Printer Cloud Management Software.",
"\n\n",
"3D printing doesn't have to be a complicated, analog, SD card-filled experience; step into the future of modern 3D printing"
]
],
"website": "https://simplyprint.io",
"repo": "https://github.com/SimplyPrint",
"updates": false
}
}

View File

@@ -13,6 +13,7 @@
"\n\n",
"Note: This extension installs Spoolman using Docker. Docker must be installed on your system before installing Spoolman."
],
"repo": "https://github.com/Donkie/Spoolman",
"updates": true
}
}

View File

@@ -5,7 +5,7 @@
"maintained_by": "nlef",
"display_name": "Moonraker Telegram Bot",
"description": ["Control your printer with the Telegram messenger app."],
"project_url": "https://github.com/nlef/moonraker-telegram-bot",
"repo": "https://github.com/nlef/moonraker-telegram-bot",
"updates": true
}
}

View File

@@ -42,10 +42,13 @@ from utils.sys_utils import (
def get_kiauh_version() -> str:
"""
Helper method to get the current KIAUH version by reading the latest tag
:return: string of the latest tag
:return: string of the latest tag or a default value if no tags exist
"""
lastest_tag: str = get_local_tags(Path(__file__).parent.parent)[-1]
return lastest_tag
tags = get_local_tags(Path(__file__).parent.parent)
if tags:
return tags[-1]
else:
return "v?.?.?"
def convert_camelcase_to_kebabcase(name: str) -> str:

View File

@@ -11,7 +11,7 @@ from __future__ import annotations
import shutil
import tempfile
from pathlib import Path
from typing import List, Tuple
from typing import List, Tuple, Union
from core.logger import Logger
from core.submodules.simple_config_parser.src.simple_config_parser.simple_config_parser import (
@@ -19,7 +19,7 @@ from core.submodules.simple_config_parser.src.simple_config_parser.simple_config
)
from utils.instance_type import InstanceType
ConfigOption = Tuple[str, str]
ConfigOption = Tuple[str, Union[str, List[str]]]
def add_config_section(

View File

@@ -15,6 +15,7 @@ from extensions.obico.moonraker_obico import MoonrakerObico
from extensions.octoeverywhere.octoeverywhere import Octoeverywhere
from extensions.octoapp.octoapp import Octoapp
from extensions.telegram_bot.moonraker_telegram_bot import MoonrakerTelegramBot
from extensions.octoprint.octoprint import Octoprint
InstanceType = TypeVar(
"InstanceType",
@@ -24,4 +25,5 @@ InstanceType = TypeVar(
MoonrakerObico,
Octoeverywhere,
Octoapp,
Octoprint,
)

View File

@@ -184,9 +184,6 @@ def install_python_requirements(target: Path, requirements: Path) -> None:
:return: None
"""
try:
# always update pip before installing requirements
update_python_pip(target)
Logger.print_status("Installing Python requirements ...")
command = [
target.joinpath("bin/pip").as_posix(),
@@ -196,7 +193,7 @@ def install_python_requirements(target: Path, requirements: Path) -> None:
]
result = run(command, stderr=PIPE, text=True)
if result.returncode != 0 or result.stderr:
if result.returncode != 0:
Logger.print_error(f"{result.stderr}", False)
raise VenvCreationFailedException("Installing Python requirements failed!")
@@ -216,9 +213,6 @@ def install_python_packages(target: Path, packages: List[str]) -> None:
:return: None
"""
try:
# always update pip before installing requirements
update_python_pip(target)
Logger.print_status("Installing Python requirements ...")
command = [
target.joinpath("bin/pip").as_posix(),
@@ -228,7 +222,7 @@ def install_python_packages(target: Path, packages: List[str]) -> None:
command.append(pkg)
result = run(command, stderr=PIPE, text=True)
if result.returncode != 0 or result.stderr:
if result.returncode != 0:
Logger.print_error(f"{result.stderr}", False)
raise VenvCreationFailedException("Installing Python requirements failed!")

View File

@@ -2,7 +2,7 @@
requires-python = ">=3.8"
[project.optional-dependencies]
dev=["ruff", "mypy"]
dev=["ruff", "pyright"]
[tool.ruff]
required-version = ">=0.9.10"
@@ -20,14 +20,3 @@ quote-style = "double"
[tool.ruff.lint]
extend-select = ["I"]
[tool.mypy]
python_version = "3.8"
platform = "linux"
# strict = true # TODO: enable this once everything is else is handled
check_untyped_defs = true
ignore_missing_imports = true
warn_redundant_casts = true
warn_unused_ignores = true
warn_return_any = true
warn_unreachable = true

6
pyrightconfig.json Normal file
View File

@@ -0,0 +1,6 @@
{
"pythonVersion": "3.8",
"pythonPlatform": "Linux",
"typeCheckingMode": "standard",
"venvPath": "./.kiauh-env"
}

2
requirements-dev.txt Normal file
View File

@@ -0,0 +1,2 @@
ruff (>=0.9.10)
pyright

View File

@@ -280,7 +280,6 @@ function create_klipper_virtualenv() {
status_msg "Installing $("python${python_version}" -V) virtual environment..."
if virtualenv -p "python${python_version}" "${KLIPPY_ENV}"; then
(( python_version == 3 )) && "${KLIPPY_ENV}"/bin/pip install -U pip
"${KLIPPY_ENV}"/bin/pip install -r "${KLIPPER_DIR}"/scripts/klippy-requirements.txt
else
log_error "failure while creating python3 klippy-env"

View File

@@ -126,7 +126,7 @@ function update_klipperscreen() {
git checkout -f master && ok_msg "Checkout successfull"
if [[ $(md5sum "${KLIPPERSCREEN_DIR}/scripts/KlipperScreen-requirements.txt" | cut -d " " -f1) != "${old_md5}" ]]; then
status_msg "New dependecies detected..."
status_msg "New dependencies detected..."
"${KLIPPERSCREEN_ENV}"/bin/pip install -r "${KLIPPERSCREEN_DIR}/scripts/KlipperScreen-requirements.txt"
ok_msg "Dependencies have been installed!"
fi

View File

@@ -133,7 +133,7 @@ function update_mobileraker() {
git checkout -f main && ok_msg "Checkout successfull"
if [[ $(md5sum "${MOBILERAKER_DIR}/scripts/mobileraker-requirements.txt" | cut -d " " -f1) != "${old_md5}" ]]; then
status_msg "New dependecies detected..."
status_msg "New dependencies detected..."
"${MOBILERAKER_ENV}"/bin/pip install -r "${MOBILERAKER_DIR}/scripts/mobileraker-requirements.txt"
ok_msg "Dependencies have been installed!"
fi

View File

@@ -27,7 +27,7 @@ function moonraker_systemd() {
###
# any moonraker client that uses "moonraker" in its own name must be blacklisted using
# this variable, otherwise they will be falsely recognized as moonraker instances
blacklist="obico"
blacklist="obico|hmi|telegram-bot"
ignore="${SYSTEMD}/moonraker-(${blacklist}).service"
match="${SYSTEMD}/moonraker(-[0-9a-zA-Z]+)?.service"
@@ -336,7 +336,6 @@ function create_moonraker_virtualenv() {
[[ -d ${MOONRAKER_ENV} ]] && rm -rf "${MOONRAKER_ENV}"
if virtualenv -p /usr/bin/python3 "${MOONRAKER_ENV}"; then
"${MOONRAKER_ENV}"/bin/pip install -U pip
"${MOONRAKER_ENV}"/bin/pip install -r "${MOONRAKER_DIR}/scripts/moonraker-requirements.txt"
else
log_error "failure while creating python3 moonraker-env"