mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-15 03:24:29 +05:00
Compare commits
21 Commits
v6.0.0-bet
...
v6.0.0-rc.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8851bd68f8 | ||
|
|
9168ad88a6 | ||
|
|
03c0d46a2e | ||
|
|
8a8afc60ee | ||
|
|
5b68710b23 | ||
|
|
6cee0252ee | ||
|
|
aff63665de | ||
|
|
1ed1e0fc4c | ||
|
|
81ac102644 | ||
|
|
89b48168f4 | ||
|
|
195b7fa926 | ||
|
|
12919c7140 | ||
|
|
e590f668e6 | ||
|
|
075f2d384b | ||
|
|
afdde34721 | ||
|
|
393dd1d5bf | ||
|
|
8170057434 | ||
|
|
985b66d41f | ||
|
|
f95d2586bf | ||
|
|
f5141e7eff | ||
|
|
33113e72e9 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -10,3 +10,4 @@ __pycache__
|
|||||||
*.code-workspace
|
*.code-workspace
|
||||||
*.iml
|
*.iml
|
||||||
kiauh.cfg
|
kiauh.cfg
|
||||||
|
klipper_repos.txt
|
||||||
|
|||||||
206
README_zh.md
Normal file
206
README_zh.md
Normal 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>
|
||||||
10
kiauh.sh
10
kiauh.sh
@@ -123,19 +123,19 @@ function main() {
|
|||||||
launch_kiauh_v6
|
launch_kiauh_v6
|
||||||
else
|
else
|
||||||
top_border
|
top_border
|
||||||
echo -e "| ${green}KIAUH v6.0.0-alpha1 is available now!${white} |"
|
echo -e "| ${green}KIAUH v6.0.0-rc.2 is available now!${white} |"
|
||||||
hr
|
hr
|
||||||
echo -e "| View Changelog: ${magenta}https://git.io/JnmlX${white} |"
|
echo -e "| View Changelog: ${magenta}https://git.io/JnmlX${white} |"
|
||||||
blank_line
|
blank_line
|
||||||
echo -e "| KIAUH v6 was completely rewritten from the ground up. |"
|
echo -e "| KIAUH v6 was completely rewritten from the ground up. |"
|
||||||
echo -e "| It's based on Python 3.8 and has many improvements. |"
|
echo -e "| It's based on Python 3.8 and has many improvements. |"
|
||||||
blank_line
|
blank_line
|
||||||
echo -e "| ${yellow}NOTE: Version 6 is still in alpha, so bugs may occur!${white} |"
|
echo -e "| ${yellow}NOTE: Version 6 is still not final yet, but most bugs${white} |"
|
||||||
echo -e "| ${yellow}Yet, your feedback and bug reports are very much${white} |"
|
echo -e "| ${yellow}should be fixed by now. Still, if you encounter any${white} |"
|
||||||
echo -e "| ${yellow}appreciated and will help finalize the release.${white} |"
|
echo -e "| ${yellow}issues, please report them so they can get fixed.${white} |"
|
||||||
hr
|
hr
|
||||||
echo -e "| Would you like to try out KIAUH v6? |"
|
echo -e "| Would you like to try out KIAUH v6? |"
|
||||||
echo -e "| 1) Yes |"
|
echo -e "| 1) Yes (recommended - v5 is sunsetting soon) |"
|
||||||
echo -e "| 2) No |"
|
echo -e "| 2) No |"
|
||||||
echo -e "| 3) Yes, remember my choice for next time |"
|
echo -e "| 3) Yes, remember my choice for next time |"
|
||||||
echo -e "| 4) No, remember my choice for next time |"
|
echo -e "| 4) No, remember my choice for next time |"
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from core.backup_manager import BACKUP_ROOT_DIR
|
|
||||||
from core.constants import SYSTEMD
|
from core.constants import SYSTEMD
|
||||||
|
|
||||||
# repo
|
# repo
|
||||||
@@ -20,7 +19,6 @@ CROWSNEST_SERVICE_NAME = "crowsnest.service"
|
|||||||
|
|
||||||
# directories
|
# directories
|
||||||
CROWSNEST_DIR = Path.home().joinpath("crowsnest")
|
CROWSNEST_DIR = Path.home().joinpath("crowsnest")
|
||||||
CROWSNEST_BACKUP_DIR = BACKUP_ROOT_DIR.joinpath("crowsnest-backups")
|
|
||||||
|
|
||||||
# files
|
# files
|
||||||
CROWSNEST_MULTI_CONFIG = CROWSNEST_DIR.joinpath("tools/.config")
|
CROWSNEST_MULTI_CONFIG = CROWSNEST_DIR.joinpath("tools/.config")
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ from subprocess import CalledProcessError, run
|
|||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from components.crowsnest import (
|
from components.crowsnest import (
|
||||||
CROWSNEST_BACKUP_DIR,
|
|
||||||
CROWSNEST_BIN_FILE,
|
CROWSNEST_BIN_FILE,
|
||||||
CROWSNEST_DIR,
|
CROWSNEST_DIR,
|
||||||
CROWSNEST_INSTALL_SCRIPT,
|
CROWSNEST_INSTALL_SCRIPT,
|
||||||
@@ -26,8 +25,8 @@ from components.crowsnest import (
|
|||||||
CROWSNEST_SERVICE_NAME,
|
CROWSNEST_SERVICE_NAME,
|
||||||
)
|
)
|
||||||
from components.klipper.klipper import Klipper
|
from components.klipper.klipper import Klipper
|
||||||
from core.backup_manager.backup_manager import BackupManager
|
|
||||||
from core.logger import DialogType, Logger
|
from core.logger import DialogType, Logger
|
||||||
|
from core.services.backup_service import BackupService
|
||||||
from core.settings.kiauh_settings import KiauhSettings
|
from core.settings.kiauh_settings import KiauhSettings
|
||||||
from core.types.component_status import ComponentStatus
|
from core.types.component_status import ComponentStatus
|
||||||
from utils.common import (
|
from utils.common import (
|
||||||
@@ -127,11 +126,11 @@ def update_crowsnest() -> None:
|
|||||||
|
|
||||||
settings = KiauhSettings()
|
settings = KiauhSettings()
|
||||||
if settings.kiauh.backup_before_update:
|
if settings.kiauh.backup_before_update:
|
||||||
bm = BackupManager()
|
svc = BackupService()
|
||||||
bm.backup_directory(
|
svc.backup_directory(
|
||||||
CROWSNEST_DIR.name,
|
source_path=CROWSNEST_DIR,
|
||||||
source=CROWSNEST_DIR,
|
target_path="crowsnest",
|
||||||
target=CROWSNEST_BACKUP_DIR,
|
backup_name="crowsnest",
|
||||||
)
|
)
|
||||||
|
|
||||||
git_pull_wrapper(CROWSNEST_DIR)
|
git_pull_wrapper(CROWSNEST_DIR)
|
||||||
|
|||||||
@@ -9,8 +9,6 @@
|
|||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from core.backup_manager import BACKUP_ROOT_DIR
|
|
||||||
|
|
||||||
MODULE_PATH = Path(__file__).resolve().parent
|
MODULE_PATH = Path(__file__).resolve().parent
|
||||||
|
|
||||||
KLIPPER_REPO_URL = "https://github.com/Klipper3d/klipper.git"
|
KLIPPER_REPO_URL = "https://github.com/Klipper3d/klipper.git"
|
||||||
@@ -27,7 +25,6 @@ KLIPPER_SERVICE_NAME = "klipper.service"
|
|||||||
KLIPPER_DIR = Path.home().joinpath("klipper")
|
KLIPPER_DIR = Path.home().joinpath("klipper")
|
||||||
KLIPPER_KCONFIGS_DIR = Path.home().joinpath("klipper-kconfigs")
|
KLIPPER_KCONFIGS_DIR = Path.home().joinpath("klipper-kconfigs")
|
||||||
KLIPPER_ENV_DIR = Path.home().joinpath("klippy-env")
|
KLIPPER_ENV_DIR = Path.home().joinpath("klippy-env")
|
||||||
KLIPPER_BACKUP_DIR = BACKUP_ROOT_DIR.joinpath("klipper-backups")
|
|
||||||
|
|
||||||
# files
|
# files
|
||||||
KLIPPER_REQ_FILE = KLIPPER_DIR.joinpath("scripts/klippy-requirements.txt")
|
KLIPPER_REQ_FILE = KLIPPER_DIR.joinpath("scripts/klippy-requirements.txt")
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ from subprocess import CalledProcessError, run
|
|||||||
from typing import Dict, List
|
from typing import Dict, List
|
||||||
|
|
||||||
from components.klipper import (
|
from components.klipper import (
|
||||||
KLIPPER_BACKUP_DIR,
|
|
||||||
KLIPPER_DIR,
|
KLIPPER_DIR,
|
||||||
KLIPPER_ENV_DIR,
|
KLIPPER_ENV_DIR,
|
||||||
KLIPPER_INSTALL_SCRIPT,
|
KLIPPER_INSTALL_SCRIPT,
|
||||||
@@ -31,10 +30,10 @@ from components.webui_client.base_data import BaseWebClient
|
|||||||
from components.webui_client.client_config.client_config_setup import (
|
from components.webui_client.client_config.client_config_setup import (
|
||||||
create_client_config_symlink,
|
create_client_config_symlink,
|
||||||
)
|
)
|
||||||
from core.backup_manager.backup_manager import BackupManager
|
|
||||||
from core.constants import CURRENT_USER
|
from core.constants import CURRENT_USER
|
||||||
from core.instance_manager.base_instance import SUFFIX_BLACKLIST
|
from core.instance_manager.base_instance import SUFFIX_BLACKLIST
|
||||||
from core.logger import DialogType, Logger
|
from core.logger import DialogType, Logger
|
||||||
|
from core.services.backup_service import BackupService
|
||||||
from core.submodules.simple_config_parser.src.simple_config_parser.simple_config_parser import (
|
from core.submodules.simple_config_parser.src.simple_config_parser.simple_config_parser import (
|
||||||
SimpleConfigParser,
|
SimpleConfigParser,
|
||||||
)
|
)
|
||||||
@@ -198,9 +197,17 @@ def create_example_printer_cfg(
|
|||||||
|
|
||||||
|
|
||||||
def backup_klipper_dir() -> None:
|
def backup_klipper_dir() -> None:
|
||||||
bm = BackupManager()
|
svc = BackupService()
|
||||||
bm.backup_directory("klipper", source=KLIPPER_DIR, target=KLIPPER_BACKUP_DIR)
|
svc.backup_directory(
|
||||||
bm.backup_directory("klippy-env", source=KLIPPER_ENV_DIR, target=KLIPPER_BACKUP_DIR)
|
source_path=KLIPPER_DIR,
|
||||||
|
backup_name="klipper",
|
||||||
|
target_path="klipper",
|
||||||
|
)
|
||||||
|
svc.backup_directory(
|
||||||
|
source_path=KLIPPER_ENV_DIR,
|
||||||
|
backup_name="klippy-env",
|
||||||
|
target_path="klipper",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def install_klipper_packages() -> None:
|
def install_klipper_packages() -> None:
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
# ======================================================================= #
|
# ======================================================================= #
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from core.backup_manager import BACKUP_ROOT_DIR
|
|
||||||
from core.constants import SYSTEMD
|
from core.constants import SYSTEMD
|
||||||
|
|
||||||
# repo
|
# repo
|
||||||
@@ -22,7 +21,6 @@ KLIPPERSCREEN_LOG_NAME = "KlipperScreen.log"
|
|||||||
# directories
|
# directories
|
||||||
KLIPPERSCREEN_DIR = Path.home().joinpath("KlipperScreen")
|
KLIPPERSCREEN_DIR = Path.home().joinpath("KlipperScreen")
|
||||||
KLIPPERSCREEN_ENV_DIR = Path.home().joinpath(".KlipperScreen-env")
|
KLIPPERSCREEN_ENV_DIR = Path.home().joinpath(".KlipperScreen-env")
|
||||||
KLIPPERSCREEN_BACKUP_DIR = BACKUP_ROOT_DIR.joinpath("klipperscreen-backups")
|
|
||||||
|
|
||||||
# files
|
# files
|
||||||
KLIPPERSCREEN_REQ_FILE = KLIPPERSCREEN_DIR.joinpath(
|
KLIPPERSCREEN_REQ_FILE = KLIPPERSCREEN_DIR.joinpath(
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ from typing import List
|
|||||||
|
|
||||||
from components.klipper.klipper import Klipper
|
from components.klipper.klipper import Klipper
|
||||||
from components.klipperscreen import (
|
from components.klipperscreen import (
|
||||||
KLIPPERSCREEN_BACKUP_DIR,
|
|
||||||
KLIPPERSCREEN_DIR,
|
KLIPPERSCREEN_DIR,
|
||||||
KLIPPERSCREEN_ENV_DIR,
|
KLIPPERSCREEN_ENV_DIR,
|
||||||
KLIPPERSCREEN_INSTALL_SCRIPT,
|
KLIPPERSCREEN_INSTALL_SCRIPT,
|
||||||
@@ -25,10 +24,10 @@ from components.klipperscreen import (
|
|||||||
KLIPPERSCREEN_UPDATER_SECTION_NAME,
|
KLIPPERSCREEN_UPDATER_SECTION_NAME,
|
||||||
)
|
)
|
||||||
from components.moonraker.moonraker import Moonraker
|
from components.moonraker.moonraker import Moonraker
|
||||||
from core.backup_manager.backup_manager import BackupManager
|
|
||||||
from core.constants import SYSTEMD
|
from core.constants import SYSTEMD
|
||||||
from core.instance_manager.instance_manager import InstanceManager
|
from core.instance_manager.instance_manager import InstanceManager
|
||||||
from core.logger import DialogType, Logger
|
from core.logger import DialogType, Logger
|
||||||
|
from core.services.backup_service import BackupService
|
||||||
from core.settings.kiauh_settings import KiauhSettings
|
from core.settings.kiauh_settings import KiauhSettings
|
||||||
from core.types.component_status import ComponentStatus
|
from core.types.component_status import ComponentStatus
|
||||||
from utils.common import (
|
from utils.common import (
|
||||||
@@ -97,6 +96,7 @@ def install_klipperscreen() -> None:
|
|||||||
|
|
||||||
|
|
||||||
def patch_klipperscreen_update_manager(instances: List[Moonraker]) -> None:
|
def patch_klipperscreen_update_manager(instances: List[Moonraker]) -> None:
|
||||||
|
BackupService().backup_moonraker_conf()
|
||||||
add_config_section(
|
add_config_section(
|
||||||
section=KLIPPERSCREEN_UPDATER_SECTION_NAME,
|
section=KLIPPERSCREEN_UPDATER_SECTION_NAME,
|
||||||
instances=instances,
|
instances=instances,
|
||||||
@@ -183,6 +183,7 @@ def remove_klipperscreen() -> None:
|
|||||||
mr_instances: List[Moonraker] = get_instances(Moonraker)
|
mr_instances: List[Moonraker] = get_instances(Moonraker)
|
||||||
if mr_instances:
|
if mr_instances:
|
||||||
Logger.print_status("Removing KlipperScreen from update manager ...")
|
Logger.print_status("Removing KlipperScreen from update manager ...")
|
||||||
|
BackupService().backup_moonraker_conf()
|
||||||
remove_config_section("update_manager KlipperScreen", mr_instances)
|
remove_config_section("update_manager KlipperScreen", mr_instances)
|
||||||
Logger.print_ok("KlipperScreen successfully removed from update manager!")
|
Logger.print_ok("KlipperScreen successfully removed from update manager!")
|
||||||
|
|
||||||
@@ -193,14 +194,14 @@ def remove_klipperscreen() -> None:
|
|||||||
|
|
||||||
|
|
||||||
def backup_klipperscreen_dir() -> None:
|
def backup_klipperscreen_dir() -> None:
|
||||||
bm = BackupManager()
|
svc = BackupService()
|
||||||
bm.backup_directory(
|
svc.backup_directory(
|
||||||
KLIPPERSCREEN_DIR.name,
|
source_path=KLIPPERSCREEN_DIR,
|
||||||
source=KLIPPERSCREEN_DIR,
|
backup_name="KlipperScreen",
|
||||||
target=KLIPPERSCREEN_BACKUP_DIR,
|
target_path="KlipperScreen",
|
||||||
)
|
)
|
||||||
bm.backup_directory(
|
svc.backup_directory(
|
||||||
KLIPPERSCREEN_ENV_DIR.name,
|
source_path=KLIPPERSCREEN_ENV_DIR,
|
||||||
source=KLIPPERSCREEN_ENV_DIR,
|
backup_name="KlipperScreen-env",
|
||||||
target=KLIPPERSCREEN_BACKUP_DIR,
|
target_path="KlipperScreen",
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -9,8 +9,6 @@
|
|||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from core.backup_manager import BACKUP_ROOT_DIR
|
|
||||||
|
|
||||||
MODULE_PATH = Path(__file__).resolve().parent
|
MODULE_PATH = Path(__file__).resolve().parent
|
||||||
|
|
||||||
MOONRAKER_REPO_URL = "https://github.com/Arksine/moonraker.git"
|
MOONRAKER_REPO_URL = "https://github.com/Arksine/moonraker.git"
|
||||||
@@ -25,8 +23,6 @@ MOONRAKER_ENV_FILE_NAME = "moonraker.env"
|
|||||||
# directories
|
# directories
|
||||||
MOONRAKER_DIR = Path.home().joinpath("moonraker")
|
MOONRAKER_DIR = Path.home().joinpath("moonraker")
|
||||||
MOONRAKER_ENV_DIR = Path.home().joinpath("moonraker-env")
|
MOONRAKER_ENV_DIR = Path.home().joinpath("moonraker-env")
|
||||||
MOONRAKER_BACKUP_DIR = BACKUP_ROOT_DIR.joinpath("moonraker-backups")
|
|
||||||
MOONRAKER_DB_BACKUP_DIR = BACKUP_ROOT_DIR.joinpath("moonraker-db-backups")
|
|
||||||
|
|
||||||
# files
|
# files
|
||||||
MOONRAKER_INSTALL_SCRIPT = MOONRAKER_DIR.joinpath("scripts/install-moonraker.sh")
|
MOONRAKER_INSTALL_SCRIPT = MOONRAKER_DIR.joinpath("scripts/install-moonraker.sh")
|
||||||
|
|||||||
@@ -61,6 +61,9 @@ class SysDepsParser:
|
|||||||
version = distro_info.get("distro_version")
|
version = distro_info.get("distro_version")
|
||||||
if version:
|
if version:
|
||||||
self.distro_version = _convert_version(version)
|
self.distro_version = _convert_version(version)
|
||||||
|
self.vendor: str = ""
|
||||||
|
if pathlib.Path("/etc/rpi-issue").is_file():
|
||||||
|
self.vendor = "raspberry-pi"
|
||||||
|
|
||||||
def _parse_spec(self, full_spec: str) -> str | None:
|
def _parse_spec(self, full_spec: str) -> str | None:
|
||||||
parts = full_spec.split(";", maxsplit=1)
|
parts = full_spec.split(";", maxsplit=1)
|
||||||
@@ -109,6 +112,9 @@ class SysDepsParser:
|
|||||||
elif req_var == "distro_id":
|
elif req_var == "distro_id":
|
||||||
left_op: str | Tuple[int | str, ...] = self.distro_id
|
left_op: str | Tuple[int | str, ...] = self.distro_id
|
||||||
right_op = dep_parts[2].strip().strip("\"'")
|
right_op = dep_parts[2].strip().strip("\"'")
|
||||||
|
elif req_var == "vendor":
|
||||||
|
left_op = self.vendor
|
||||||
|
right_op = dep_parts[2].strip().strip("\"'")
|
||||||
elif req_var == "distro_version":
|
elif req_var == "distro_version":
|
||||||
if not self.distro_version:
|
if not self.distro_version:
|
||||||
logging.info(
|
logging.info(
|
||||||
|
|||||||
@@ -14,8 +14,6 @@ from typing import Dict, List, Optional
|
|||||||
|
|
||||||
from components.moonraker import (
|
from components.moonraker import (
|
||||||
MODULE_PATH,
|
MODULE_PATH,
|
||||||
MOONRAKER_BACKUP_DIR,
|
|
||||||
MOONRAKER_DB_BACKUP_DIR,
|
|
||||||
MOONRAKER_DEFAULT_PORT,
|
MOONRAKER_DEFAULT_PORT,
|
||||||
MOONRAKER_DEPS_JSON_FILE,
|
MOONRAKER_DEPS_JSON_FILE,
|
||||||
MOONRAKER_DIR,
|
MOONRAKER_DIR,
|
||||||
@@ -25,8 +23,8 @@ from components.moonraker import (
|
|||||||
from components.moonraker.moonraker import Moonraker
|
from components.moonraker.moonraker import Moonraker
|
||||||
from components.moonraker.utils.sysdeps_parser import SysDepsParser
|
from components.moonraker.utils.sysdeps_parser import SysDepsParser
|
||||||
from components.webui_client.base_data import BaseWebClient
|
from components.webui_client.base_data import BaseWebClient
|
||||||
from core.backup_manager.backup_manager import BackupManager
|
|
||||||
from core.logger import Logger
|
from core.logger import Logger
|
||||||
|
from core.services.backup_service import BackupService
|
||||||
from core.submodules.simple_config_parser.src.simple_config_parser.simple_config_parser import (
|
from core.submodules.simple_config_parser.src.simple_config_parser.simple_config_parser import (
|
||||||
SimpleConfigParser,
|
SimpleConfigParser,
|
||||||
)
|
)
|
||||||
@@ -126,7 +124,7 @@ def create_example_moonraker_conf(
|
|||||||
scp.read_file(target)
|
scp.read_file(target)
|
||||||
trusted_clients: List[str] = [
|
trusted_clients: List[str] = [
|
||||||
f" {'.'.join(ip)}\n",
|
f" {'.'.join(ip)}\n",
|
||||||
*scp.getval("authorization", "trusted_clients"),
|
*scp.getvals("authorization", "trusted_clients"),
|
||||||
]
|
]
|
||||||
|
|
||||||
scp.set_option("server", "port", str(port))
|
scp.set_option("server", "port", str(port))
|
||||||
@@ -168,21 +166,55 @@ def create_example_moonraker_conf(
|
|||||||
|
|
||||||
|
|
||||||
def backup_moonraker_dir() -> None:
|
def backup_moonraker_dir() -> None:
|
||||||
bm = BackupManager()
|
svc = BackupService()
|
||||||
bm.backup_directory("moonraker", source=MOONRAKER_DIR, target=MOONRAKER_BACKUP_DIR)
|
svc.backup_directory(
|
||||||
bm.backup_directory(
|
source_path=MOONRAKER_DIR, backup_name="moonraker", target_path="moonraker"
|
||||||
"moonraker-env", source=MOONRAKER_ENV_DIR, target=MOONRAKER_BACKUP_DIR
|
)
|
||||||
|
svc.backup_directory(
|
||||||
|
source_path=MOONRAKER_ENV_DIR,
|
||||||
|
backup_name="moonraker-env",
|
||||||
|
target_path="moonraker",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def backup_moonraker_db_dir() -> None:
|
def backup_moonraker_db_dir() -> None:
|
||||||
instances: List[Moonraker] = get_instances(Moonraker)
|
instances: List[Moonraker] = get_instances(Moonraker)
|
||||||
bm = BackupManager()
|
svc = BackupService()
|
||||||
|
|
||||||
|
if not instances:
|
||||||
|
# fallback: search for printer data directories in the user's home directory
|
||||||
|
Logger.print_info("No Moonraker instances found via systemd services.")
|
||||||
|
Logger.print_info(
|
||||||
|
"Attempting to find printer data directories in home directory..."
|
||||||
|
)
|
||||||
|
|
||||||
|
home_dir = Path.home()
|
||||||
|
printer_data_dirs = []
|
||||||
|
|
||||||
|
for pattern in ["printer_data", "printer_*_data"]:
|
||||||
|
for data_dir in home_dir.glob(pattern):
|
||||||
|
if data_dir.is_dir():
|
||||||
|
printer_data_dirs.append(data_dir)
|
||||||
|
|
||||||
|
if not printer_data_dirs:
|
||||||
|
Logger.print_info("Unable to find directory to backup!")
|
||||||
|
Logger.print_info("No printer data directories found in home directory.")
|
||||||
|
return
|
||||||
|
|
||||||
|
for data_dir in printer_data_dirs:
|
||||||
|
svc.backup_directory(
|
||||||
|
source_path=data_dir.joinpath("database"),
|
||||||
|
target_path=data_dir.name,
|
||||||
|
backup_name="database",
|
||||||
|
)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
for instance in instances:
|
for instance in instances:
|
||||||
name = f"database-{instance.data_dir.name}"
|
svc.backup_directory(
|
||||||
bm.backup_directory(
|
source_path=instance.db_dir,
|
||||||
name, source=instance.db_dir, target=MOONRAKER_DB_BACKUP_DIR
|
target_path=f"{instance.data_dir.name}",
|
||||||
|
backup_name="database",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ class BaseWebClient(ABC):
|
|||||||
display_name: str
|
display_name: str
|
||||||
client_dir: Path
|
client_dir: Path
|
||||||
config_file: Path
|
config_file: Path
|
||||||
backup_dir: Path
|
|
||||||
repo_path: str
|
repo_path: str
|
||||||
download_url: str
|
download_url: str
|
||||||
nginx_config: Path
|
nginx_config: Path
|
||||||
@@ -52,6 +51,5 @@ class BaseWebClientConfig(ABC):
|
|||||||
display_name: str
|
display_name: str
|
||||||
config_filename: str
|
config_filename: str
|
||||||
config_dir: Path
|
config_dir: Path
|
||||||
backup_dir: Path
|
|
||||||
repo_url: str
|
repo_url: str
|
||||||
config_section: str
|
config_section: str
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ from components.klipper.klipper import Klipper
|
|||||||
from components.moonraker.moonraker import Moonraker
|
from components.moonraker.moonraker import Moonraker
|
||||||
from components.webui_client.base_data import BaseWebClientConfig
|
from components.webui_client.base_data import BaseWebClientConfig
|
||||||
from core.logger import Logger
|
from core.logger import Logger
|
||||||
|
from core.services.backup_service import BackupService
|
||||||
from core.services.message_service import Message
|
from core.services.message_service import Message
|
||||||
from core.types.color import Color
|
from core.types.color import Color
|
||||||
from utils.config_utils import remove_config_section
|
from utils.config_utils import remove_config_section
|
||||||
@@ -35,6 +36,8 @@ def run_client_config_removal(
|
|||||||
if run_remove_routines(client_config.config_dir):
|
if run_remove_routines(client_config.config_dir):
|
||||||
completion_msg.text.append(f"● {client_config.display_name} removed")
|
completion_msg.text.append(f"● {client_config.display_name} removed")
|
||||||
|
|
||||||
|
BackupService().backup_printer_config_dir()
|
||||||
|
|
||||||
completion_msg = remove_moonraker_config_section(
|
completion_msg = remove_moonraker_config_section(
|
||||||
completion_msg, client_config, mr_instances
|
completion_msg, client_config, mr_instances
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ from components.webui_client.client_utils import (
|
|||||||
)
|
)
|
||||||
from core.instance_manager.instance_manager import InstanceManager
|
from core.instance_manager.instance_manager import InstanceManager
|
||||||
from core.logger import Logger
|
from core.logger import Logger
|
||||||
|
from core.services.backup_service import BackupService
|
||||||
from core.settings.kiauh_settings import KiauhSettings
|
from core.settings.kiauh_settings import KiauhSettings
|
||||||
from utils.common import backup_printer_config_dir
|
|
||||||
from utils.config_utils import add_config_section, add_config_section_at_top
|
from utils.config_utils import add_config_section, add_config_section_at_top
|
||||||
from utils.fs_utils import create_symlink
|
from utils.fs_utils import create_symlink
|
||||||
from utils.git_utils import git_clone_wrapper, git_pull_wrapper
|
from utils.git_utils import git_clone_wrapper, git_pull_wrapper
|
||||||
@@ -57,7 +57,7 @@ def install_client_config(client_data: BaseWebClient, cfg_backup=True) -> None:
|
|||||||
create_client_config_symlink(client_config, kl_instances)
|
create_client_config_symlink(client_config, kl_instances)
|
||||||
|
|
||||||
if cfg_backup:
|
if cfg_backup:
|
||||||
backup_printer_config_dir()
|
BackupService().backup_printer_config_dir()
|
||||||
|
|
||||||
add_config_section(
|
add_config_section(
|
||||||
section=f"update_manager {client_config.name}",
|
section=f"update_manager {client_config.name}",
|
||||||
|
|||||||
@@ -16,9 +16,9 @@ from components.webui_client.base_data import (
|
|||||||
from components.webui_client.client_config.client_config_remove import (
|
from components.webui_client.client_config.client_config_remove import (
|
||||||
run_client_config_removal,
|
run_client_config_removal,
|
||||||
)
|
)
|
||||||
from core.backup_manager.backup_manager import BackupManager
|
|
||||||
from core.constants import NGINX_SITES_AVAILABLE, NGINX_SITES_ENABLED
|
from core.constants import NGINX_SITES_AVAILABLE, NGINX_SITES_ENABLED
|
||||||
from core.logger import Logger
|
from core.logger import Logger
|
||||||
|
from core.services.backup_service import BackupService
|
||||||
from core.services.message_service import Message
|
from core.services.message_service import Message
|
||||||
from core.types.color import Color
|
from core.types.color import Color
|
||||||
from utils.config_utils import remove_config_section
|
from utils.config_utils import remove_config_section
|
||||||
@@ -43,8 +43,19 @@ def run_client_removal(
|
|||||||
kl_instances: List[Klipper] = get_instances(Klipper)
|
kl_instances: List[Klipper] = get_instances(Klipper)
|
||||||
|
|
||||||
if backup_config:
|
if backup_config:
|
||||||
bm = BackupManager()
|
version = ""
|
||||||
if bm.backup_file(client.config_file):
|
src = client.client_dir
|
||||||
|
if src.joinpath(".version").exists():
|
||||||
|
with open(src.joinpath(".version"), "r") as v:
|
||||||
|
version = v.readlines()[0]
|
||||||
|
|
||||||
|
svc = BackupService()
|
||||||
|
target_path = svc.backup_root.joinpath(f"{client.client_dir.name}_{version}")
|
||||||
|
success = svc.backup_file(
|
||||||
|
source_path=client.config_file,
|
||||||
|
target_path=target_path,
|
||||||
|
)
|
||||||
|
if success:
|
||||||
completion_msg.text.append(f"● {client.config_file.name} backup created")
|
completion_msg.text.append(f"● {client.config_file.name} backup created")
|
||||||
|
|
||||||
if remove_client:
|
if remove_client:
|
||||||
@@ -56,6 +67,7 @@ def run_client_removal(
|
|||||||
if remove_client_nginx_logs(client, kl_instances):
|
if remove_client_nginx_logs(client, kl_instances):
|
||||||
completion_msg.text.append("● NGINX logs removed")
|
completion_msg.text.append("● NGINX logs removed")
|
||||||
|
|
||||||
|
BackupService().backup_moonraker_conf()
|
||||||
section = f"update_manager {client_name}"
|
section = f"update_manager {client_name}"
|
||||||
handled_instances: List[Moonraker] = remove_config_section(
|
handled_instances: List[Moonraker] = remove_config_section(
|
||||||
section, mr_instances
|
section, mr_instances
|
||||||
|
|||||||
@@ -37,9 +37,10 @@ from components.webui_client.client_utils import (
|
|||||||
)
|
)
|
||||||
from core.instance_manager.instance_manager import InstanceManager
|
from core.instance_manager.instance_manager import InstanceManager
|
||||||
from core.logger import DialogType, Logger
|
from core.logger import DialogType, Logger
|
||||||
|
from core.services.backup_service import BackupService
|
||||||
from core.settings.kiauh_settings import KiauhSettings
|
from core.settings.kiauh_settings import KiauhSettings
|
||||||
from core.types.color import Color
|
from core.types.color import Color
|
||||||
from utils.common import backup_printer_config_dir, check_install_dependencies
|
from utils.common import check_install_dependencies
|
||||||
from utils.config_utils import add_config_section
|
from utils.config_utils import add_config_section
|
||||||
from utils.fs_utils import unzip
|
from utils.fs_utils import unzip
|
||||||
from utils.input_utils import get_confirm
|
from utils.input_utils import get_confirm
|
||||||
@@ -97,11 +98,12 @@ def install_client(
|
|||||||
if enable_remotemode and client.client == WebClientType.MAINSAIL:
|
if enable_remotemode and client.client == WebClientType.MAINSAIL:
|
||||||
enable_mainsail_remotemode()
|
enable_mainsail_remotemode()
|
||||||
|
|
||||||
backup_printer_config_dir()
|
BackupService().backup_printer_config_dir()
|
||||||
add_config_section(
|
add_config_section(
|
||||||
section=f"update_manager {client.name}",
|
section=f"update_manager {client.name}",
|
||||||
instances=mr_instances,
|
instances=mr_instances,
|
||||||
options=[
|
options=[
|
||||||
|
("persistent_files", ["config.json"]),
|
||||||
("type", "web"),
|
("type", "web"),
|
||||||
("channel", "stable"),
|
("channel", "stable"),
|
||||||
("repo", str(client.repo_path)),
|
("repo", str(client.repo_path)),
|
||||||
|
|||||||
@@ -24,13 +24,13 @@ from components.webui_client.base_data import (
|
|||||||
from components.webui_client.client_dialogs import print_client_port_select_dialog
|
from components.webui_client.client_dialogs import print_client_port_select_dialog
|
||||||
from components.webui_client.fluidd_data import FluiddData
|
from components.webui_client.fluidd_data import FluiddData
|
||||||
from components.webui_client.mainsail_data import MainsailData
|
from components.webui_client.mainsail_data import MainsailData
|
||||||
from core.backup_manager.backup_manager import BackupManager
|
|
||||||
from core.constants import (
|
from core.constants import (
|
||||||
NGINX_CONFD,
|
NGINX_CONFD,
|
||||||
NGINX_SITES_AVAILABLE,
|
NGINX_SITES_AVAILABLE,
|
||||||
NGINX_SITES_ENABLED,
|
NGINX_SITES_ENABLED,
|
||||||
)
|
)
|
||||||
from core.logger import Logger
|
from core.logger import Logger
|
||||||
|
from core.services.backup_service import BackupService
|
||||||
from core.settings.kiauh_settings import KiauhSettings, WebUiSettings
|
from core.settings.kiauh_settings import KiauhSettings, WebUiSettings
|
||||||
from core.submodules.simple_config_parser.src.simple_config_parser.simple_config_parser import (
|
from core.submodules.simple_config_parser.src.simple_config_parser.simple_config_parser import (
|
||||||
SimpleConfigParser,
|
SimpleConfigParser,
|
||||||
@@ -119,7 +119,7 @@ def enable_mainsail_remotemode() -> None:
|
|||||||
with open(c_json, "r") as f:
|
with open(c_json, "r") as f:
|
||||||
config_data = json.load(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 ...")
|
Logger.print_info("Remote mode already configured. Skipped ...")
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -175,26 +175,39 @@ def get_remote_client_version(client: BaseWebClient) -> str | None:
|
|||||||
|
|
||||||
|
|
||||||
def backup_client_data(client: BaseWebClient) -> None:
|
def backup_client_data(client: BaseWebClient) -> None:
|
||||||
name = client.name
|
version = ""
|
||||||
src = client.client_dir
|
src = client.client_dir
|
||||||
dest = client.backup_dir
|
if src.joinpath(".version").exists():
|
||||||
|
with open(src.joinpath(".version"), "r") as v:
|
||||||
|
version = v.readlines()[0]
|
||||||
|
|
||||||
with open(src.joinpath(".version"), "r") as v:
|
svc = BackupService()
|
||||||
version = v.readlines()[0]
|
target_path = svc.backup_root.joinpath(f"{client.client_dir.name}_{version}")
|
||||||
|
svc.backup_directory(
|
||||||
bm = BackupManager()
|
source_path=client.client_dir,
|
||||||
bm.backup_directory(f"{name}-{version}", src, dest)
|
target_path=target_path,
|
||||||
bm.backup_file(client.config_file, dest)
|
backup_name=client.name,
|
||||||
bm.backup_file(NGINX_SITES_AVAILABLE.joinpath(name), dest)
|
)
|
||||||
|
svc.backup_file(
|
||||||
|
source_path=client.config_file,
|
||||||
|
target_path=target_path,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def backup_client_config_data(client: BaseWebClient) -> None:
|
def backup_client_config_data(client: BaseWebClient) -> None:
|
||||||
client_config = client.client_config
|
version = ""
|
||||||
name = client_config.name
|
src = client.client_dir
|
||||||
source = client_config.config_dir
|
if src.joinpath(".version").exists():
|
||||||
target = client_config.backup_dir
|
with open(src.joinpath(".version"), "r") as v:
|
||||||
bm = BackupManager()
|
version = v.readlines()[0]
|
||||||
bm.backup_directory(name, source, target)
|
|
||||||
|
svc = BackupService()
|
||||||
|
target_path = svc.backup_root.joinpath(f"{client.client_dir.name}_{version}")
|
||||||
|
svc.backup_directory(
|
||||||
|
source_path=client.client_config.config_dir,
|
||||||
|
target_path=target_path,
|
||||||
|
backup_name=client.client_config.name,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def get_existing_clients() -> List[BaseWebClient]:
|
def get_existing_clients() -> List[BaseWebClient]:
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ from components.webui_client.base_data import (
|
|||||||
WebClientConfigType,
|
WebClientConfigType,
|
||||||
WebClientType,
|
WebClientType,
|
||||||
)
|
)
|
||||||
from core.backup_manager import BACKUP_ROOT_DIR
|
|
||||||
from core.constants import NGINX_SITES_AVAILABLE
|
from core.constants import NGINX_SITES_AVAILABLE
|
||||||
|
|
||||||
|
|
||||||
@@ -30,7 +29,6 @@ class FluiddConfigWeb(BaseWebClientConfig):
|
|||||||
config_dir: Path = Path.home().joinpath("fluidd-config")
|
config_dir: Path = Path.home().joinpath("fluidd-config")
|
||||||
config_filename: str = "fluidd.cfg"
|
config_filename: str = "fluidd.cfg"
|
||||||
config_section: str = f"include {config_filename}"
|
config_section: str = f"include {config_filename}"
|
||||||
backup_dir: Path = BACKUP_ROOT_DIR.joinpath("fluidd-config-backups")
|
|
||||||
repo_url: str = "https://github.com/fluidd-core/fluidd-config.git"
|
repo_url: str = "https://github.com/fluidd-core/fluidd-config.git"
|
||||||
|
|
||||||
|
|
||||||
@@ -43,7 +41,6 @@ class FluiddData(BaseWebClient):
|
|||||||
display_name: str = name.capitalize()
|
display_name: str = name.capitalize()
|
||||||
client_dir: Path = Path.home().joinpath("fluidd")
|
client_dir: Path = Path.home().joinpath("fluidd")
|
||||||
config_file: Path = client_dir.joinpath("config.json")
|
config_file: Path = client_dir.joinpath("config.json")
|
||||||
backup_dir: Path = BACKUP_ROOT_DIR.joinpath("fluidd-backups")
|
|
||||||
repo_path: str = "fluidd-core/fluidd"
|
repo_path: str = "fluidd-core/fluidd"
|
||||||
nginx_config: Path = NGINX_SITES_AVAILABLE.joinpath("fluidd")
|
nginx_config: Path = NGINX_SITES_AVAILABLE.joinpath("fluidd")
|
||||||
nginx_access_log: Path = Path("/var/log/nginx/fluidd-access.log")
|
nginx_access_log: Path = Path("/var/log/nginx/fluidd-access.log")
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ from components.webui_client.base_data import (
|
|||||||
WebClientConfigType,
|
WebClientConfigType,
|
||||||
WebClientType,
|
WebClientType,
|
||||||
)
|
)
|
||||||
from core.backup_manager import BACKUP_ROOT_DIR
|
|
||||||
from core.constants import NGINX_SITES_AVAILABLE
|
from core.constants import NGINX_SITES_AVAILABLE
|
||||||
|
|
||||||
|
|
||||||
@@ -30,7 +29,6 @@ class MainsailConfigWeb(BaseWebClientConfig):
|
|||||||
config_dir: Path = Path.home().joinpath("mainsail-config")
|
config_dir: Path = Path.home().joinpath("mainsail-config")
|
||||||
config_filename: str = "mainsail.cfg"
|
config_filename: str = "mainsail.cfg"
|
||||||
config_section: str = f"include {config_filename}"
|
config_section: str = f"include {config_filename}"
|
||||||
backup_dir: Path = BACKUP_ROOT_DIR.joinpath("mainsail-config-backups")
|
|
||||||
repo_url: str = "https://github.com/mainsail-crew/mainsail-config.git"
|
repo_url: str = "https://github.com/mainsail-crew/mainsail-config.git"
|
||||||
|
|
||||||
|
|
||||||
@@ -43,7 +41,6 @@ class MainsailData(BaseWebClient):
|
|||||||
display_name: str = name.capitalize()
|
display_name: str = name.capitalize()
|
||||||
client_dir: Path = Path.home().joinpath("mainsail")
|
client_dir: Path = Path.home().joinpath("mainsail")
|
||||||
config_file: Path = client_dir.joinpath("config.json")
|
config_file: Path = client_dir.joinpath("config.json")
|
||||||
backup_dir: Path = BACKUP_ROOT_DIR.joinpath("mainsail-backups")
|
|
||||||
repo_path: str = "mainsail-crew/mainsail"
|
repo_path: str = "mainsail-crew/mainsail"
|
||||||
nginx_config: Path = NGINX_SITES_AVAILABLE.joinpath("mainsail")
|
nginx_config: Path = NGINX_SITES_AVAILABLE.joinpath("mainsail")
|
||||||
nginx_access_log: Path = Path("/var/log/nginx/mainsail-access.log")
|
nginx_access_log: Path = Path("/var/log/nginx/mainsail-access.log")
|
||||||
|
|||||||
@@ -1,108 +0,0 @@
|
|||||||
# ======================================================================= #
|
|
||||||
# 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 shutil
|
|
||||||
from pathlib import Path
|
|
||||||
from typing import List
|
|
||||||
|
|
||||||
from core.backup_manager import BACKUP_ROOT_DIR
|
|
||||||
from core.logger import Logger
|
|
||||||
from utils.common import get_current_date
|
|
||||||
|
|
||||||
|
|
||||||
class BackupManagerException(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
# noinspection PyUnusedLocal
|
|
||||||
# noinspection PyMethodMayBeStatic
|
|
||||||
class BackupManager:
|
|
||||||
def __init__(self, backup_root_dir: Path = BACKUP_ROOT_DIR):
|
|
||||||
self._backup_root_dir: Path = backup_root_dir
|
|
||||||
self._ignore_folders: List[str] = []
|
|
||||||
|
|
||||||
@property
|
|
||||||
def backup_root_dir(self) -> Path:
|
|
||||||
return self._backup_root_dir
|
|
||||||
|
|
||||||
@backup_root_dir.setter
|
|
||||||
def backup_root_dir(self, value: Path):
|
|
||||||
self._backup_root_dir = value
|
|
||||||
|
|
||||||
@property
|
|
||||||
def ignore_folders(self) -> List[str]:
|
|
||||||
return self._ignore_folders
|
|
||||||
|
|
||||||
@ignore_folders.setter
|
|
||||||
def ignore_folders(self, value: List[str]):
|
|
||||||
self._ignore_folders = value
|
|
||||||
|
|
||||||
def backup_file(
|
|
||||||
self, file: Path, target: Path | None = None, custom_filename=None
|
|
||||||
) -> bool:
|
|
||||||
Logger.print_status(f"Creating backup of {file} ...")
|
|
||||||
|
|
||||||
if not file.exists():
|
|
||||||
Logger.print_info("File does not exist! Skipping ...")
|
|
||||||
return False
|
|
||||||
|
|
||||||
target = self.backup_root_dir if target is None else target
|
|
||||||
|
|
||||||
if Path(file).is_file():
|
|
||||||
date = get_current_date().get("date")
|
|
||||||
time = get_current_date().get("time")
|
|
||||||
filename = f"{file.stem}-{date}-{time}{file.suffix}"
|
|
||||||
filename = custom_filename if custom_filename is not None else filename
|
|
||||||
try:
|
|
||||||
Path(target).mkdir(exist_ok=True)
|
|
||||||
shutil.copyfile(file, target.joinpath(filename))
|
|
||||||
Logger.print_ok("Backup successful!")
|
|
||||||
return True
|
|
||||||
except OSError as e:
|
|
||||||
Logger.print_error(f"Unable to backup '{file}':\n{e}")
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
Logger.print_info(f"File '{file}' not found ...")
|
|
||||||
return False
|
|
||||||
|
|
||||||
def backup_directory(
|
|
||||||
self, name: str, source: Path, target: Path | None = None
|
|
||||||
) -> Path | None:
|
|
||||||
Logger.print_status(f"Creating backup of {name} in {target} ...")
|
|
||||||
|
|
||||||
if source is None or not Path(source).exists():
|
|
||||||
Logger.print_info("Source directory does not exist! Skipping ...")
|
|
||||||
return None
|
|
||||||
|
|
||||||
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,
|
|
||||||
)
|
|
||||||
Logger.print_ok("Backup successful!")
|
|
||||||
|
|
||||||
return backup_target
|
|
||||||
|
|
||||||
except OSError as e:
|
|
||||||
Logger.print_error(f"Unable to backup directory '{source}':\n{e}")
|
|
||||||
raise BackupManagerException(f"Unable to backup directory '{source}':\n{e}")
|
|
||||||
|
|
||||||
def ignore_folders_func(self, dirpath, filenames) -> List[str]:
|
|
||||||
return (
|
|
||||||
[f for f in filenames if f in self._ignore_folders]
|
|
||||||
if self._ignore_folders
|
|
||||||
else []
|
|
||||||
)
|
|
||||||
@@ -11,8 +11,6 @@ import os
|
|||||||
import pwd
|
import pwd
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from core.backup_manager import BACKUP_ROOT_DIR
|
|
||||||
|
|
||||||
# global dependencies
|
# global dependencies
|
||||||
GLOBAL_DEPS = ["git", "wget", "curl", "unzip", "dfu-util", "python3-virtualenv"]
|
GLOBAL_DEPS = ["git", "wget", "curl", "unzip", "dfu-util", "python3-virtualenv"]
|
||||||
|
|
||||||
@@ -24,7 +22,6 @@ CURRENT_USER = pwd.getpwuid(os.getuid())[0]
|
|||||||
|
|
||||||
# dirs
|
# dirs
|
||||||
SYSTEMD = Path("/etc/systemd/system")
|
SYSTEMD = Path("/etc/systemd/system")
|
||||||
PRINTER_DATA_BACKUP_DIR = BACKUP_ROOT_DIR.joinpath("printer-data-backups")
|
|
||||||
NGINX_SITES_AVAILABLE = Path("/etc/nginx/sites-available")
|
NGINX_SITES_AVAILABLE = Path("/etc/nginx/sites-available")
|
||||||
NGINX_SITES_ENABLED = Path("/etc/nginx/sites-enabled")
|
NGINX_SITES_ENABLED = Path("/etc/nginx/sites-enabled")
|
||||||
NGINX_CONFD = Path("/etc/nginx/conf.d")
|
NGINX_CONFD = Path("/etc/nginx/conf.d")
|
||||||
|
|||||||
@@ -16,8 +16,9 @@ from typing import List
|
|||||||
|
|
||||||
from utils.fs_utils import get_data_dir
|
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)
|
@dataclass(repr=True)
|
||||||
class BaseInstance:
|
class BaseInstance:
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ from components.webui_client.fluidd_data import FluiddData
|
|||||||
from components.webui_client.mainsail_data import MainsailData
|
from components.webui_client.mainsail_data import MainsailData
|
||||||
from core.menus import Option
|
from core.menus import Option
|
||||||
from core.menus.base_menu import BaseMenu
|
from core.menus.base_menu import BaseMenu
|
||||||
|
from core.services.backup_service import BackupService
|
||||||
from core.types.color import Color
|
from core.types.color import Color
|
||||||
from utils.common import backup_printer_config_dir
|
|
||||||
|
|
||||||
|
|
||||||
# noinspection PyUnusedLocal
|
# noinspection PyUnusedLocal
|
||||||
@@ -86,7 +86,7 @@ class BackupMenu(BaseMenu):
|
|||||||
backup_moonraker_dir()
|
backup_moonraker_dir()
|
||||||
|
|
||||||
def backup_printer_config(self, **kwargs) -> None:
|
def backup_printer_config(self, **kwargs) -> None:
|
||||||
backup_printer_config_dir()
|
BackupService().backup_printer_config_dir()
|
||||||
|
|
||||||
def backup_moonraker_db(self, **kwargs) -> None:
|
def backup_moonraker_db(self, **kwargs) -> None:
|
||||||
backup_moonraker_db_dir()
|
backup_moonraker_db_dir()
|
||||||
|
|||||||
@@ -10,14 +10,17 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from typing import List, Literal, Type
|
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 import Option
|
||||||
from core.menus.base_menu import BaseMenu
|
from core.menus.base_menu import BaseMenu
|
||||||
from core.settings.kiauh_settings import KiauhSettings, Repository
|
from core.settings.kiauh_settings import KiauhSettings, Repository
|
||||||
from core.types.color import Color
|
from core.types.color import Color
|
||||||
from procedures.switch_repo import run_switch_repo_routine
|
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):
|
class RepoSelectMenu(BaseMenu):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
@@ -48,26 +51,27 @@ class RepoSelectMenu(BaseMenu):
|
|||||||
|
|
||||||
def set_options(self) -> None:
|
def set_options(self) -> None:
|
||||||
self.options = {}
|
self.options = {}
|
||||||
|
if self.repos:
|
||||||
if not self.repos:
|
for idx, repo in enumerate(self.repos, start=1):
|
||||||
return
|
self.options[str(idx)] = Option(
|
||||||
|
method=self.select_repository, opt_data=repo
|
||||||
for idx, repo in enumerate(self.repos, start=1):
|
)
|
||||||
self.options[str(idx)] = Option(
|
self.options["a"] = Option(method=self.add_repository)
|
||||||
method=self.select_repository, opt_data=repo
|
self.options["r"] = Option(method=self.remove_repository)
|
||||||
)
|
self.options["b"] = Option(method=self.go_back)
|
||||||
|
|
||||||
def print_menu(self) -> None:
|
def print_menu(self) -> None:
|
||||||
menu = "╟───────────────────────────────────────────────────────╢\n"
|
menu = "╟───────────────────────────────────────────────────────╢\n"
|
||||||
menu += "║ Available Repositories: ║\n"
|
menu += "║ Available Repositories: ║\n"
|
||||||
menu += "╟───────────────────────────────────────────────────────╢\n"
|
menu += "╟───────────────────────────────────────────────────────╢\n"
|
||||||
|
|
||||||
for idx, repo in enumerate(self.repos, start=1):
|
for idx, repo in enumerate(self.repos, start=1):
|
||||||
url = f"● Repo: {repo.url.replace('.git', '')}"
|
url = f"● Repo: {repo.url.replace('.git', '')}"
|
||||||
branch = f"└► Branch: {repo.branch}"
|
branch = f"└► Branch: {repo.branch}"
|
||||||
menu += f"║ {idx}) {Color.apply(url, Color.CYAN):<59} ║\n"
|
menu += f"║ {idx}) {Color.apply(url, Color.CYAN):<59} ║\n"
|
||||||
menu += f"║ {Color.apply(branch, 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"
|
menu += "╟───────────────────────────────────────────────────────╢\n"
|
||||||
print(menu, end="")
|
print(menu, end="")
|
||||||
|
|
||||||
@@ -77,3 +81,82 @@ class RepoSelectMenu(BaseMenu):
|
|||||||
f"Switching to {self.name.capitalize()}'s new source repository ..."
|
f"Switching to {self.name.capitalize()}'s new source repository ..."
|
||||||
)
|
)
|
||||||
run_switch_repo_routine(self.name, repo.url, repo.branch)
|
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()
|
||||||
|
|||||||
@@ -117,20 +117,12 @@ class SettingsMenu(BaseMenu):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def switch_klipper_repo(self, **kwargs) -> None:
|
def switch_klipper_repo(self, **kwargs) -> None:
|
||||||
name = "Klipper"
|
|
||||||
repos = self.settings.klipper.repositories
|
repos = self.settings.klipper.repositories
|
||||||
if not repos:
|
RepoSelectMenu("klipper", repos=repos, previous_menu=self.__class__).run()
|
||||||
self._warn_no_repos(name)
|
|
||||||
return
|
|
||||||
RepoSelectMenu(name.lower(), repos=repos, previous_menu=self.__class__).run()
|
|
||||||
|
|
||||||
def switch_moonraker_repo(self, **kwargs) -> None:
|
def switch_moonraker_repo(self, **kwargs) -> None:
|
||||||
name = "Moonraker"
|
|
||||||
repos = self.settings.moonraker.repositories
|
repos = self.settings.moonraker.repositories
|
||||||
if not repos:
|
RepoSelectMenu("moonraker", repos=repos, previous_menu=self.__class__).run()
|
||||||
self._warn_no_repos(name)
|
|
||||||
return
|
|
||||||
RepoSelectMenu(name.lower(), repos=repos, previous_menu=self.__class__).run()
|
|
||||||
|
|
||||||
def toggle_mainsail_release(self, **kwargs) -> None:
|
def toggle_mainsail_release(self, **kwargs) -> None:
|
||||||
self.mainsail_unstable = not self.mainsail_unstable
|
self.mainsail_unstable = not self.mainsail_unstable
|
||||||
|
|||||||
189
kiauh/core/services/backup_service.py
Normal file
189
kiauh/core/services/backup_service.py
Normal file
@@ -0,0 +1,189 @@
|
|||||||
|
# ======================================================================= #
|
||||||
|
# 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 shutil
|
||||||
|
from datetime import datetime
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import List, Optional
|
||||||
|
|
||||||
|
from components.klipper.klipper import Klipper
|
||||||
|
from components.moonraker.moonraker import Moonraker
|
||||||
|
from core.logger import Logger
|
||||||
|
from utils.instance_utils import get_instances
|
||||||
|
|
||||||
|
|
||||||
|
class BackupService:
|
||||||
|
def __init__(self):
|
||||||
|
self._backup_root = Path.home().joinpath("kiauh_backups")
|
||||||
|
|
||||||
|
@property
|
||||||
|
def backup_root(self) -> Path:
|
||||||
|
return self._backup_root
|
||||||
|
|
||||||
|
@property
|
||||||
|
def timestamp(self) -> str:
|
||||||
|
return datetime.now().strftime("%Y%m%d-%H%M%S")
|
||||||
|
|
||||||
|
################################################
|
||||||
|
# GENERIC BACKUP METHODS
|
||||||
|
################################################
|
||||||
|
|
||||||
|
def backup_file(
|
||||||
|
self,
|
||||||
|
source_path: Path,
|
||||||
|
target_path: Optional[Path | str] = None,
|
||||||
|
target_name: Optional[str] = None,
|
||||||
|
) -> bool:
|
||||||
|
source_path = Path(source_path)
|
||||||
|
|
||||||
|
Logger.print_status(f"Creating backup of {source_path} ...")
|
||||||
|
|
||||||
|
if not source_path.exists():
|
||||||
|
Logger.print_info(
|
||||||
|
f"File '{source_path}' does not exist! Skipping backup..."
|
||||||
|
)
|
||||||
|
return False
|
||||||
|
|
||||||
|
if not source_path.is_file():
|
||||||
|
Logger.print_info(f"'{source_path}' is not a file! Skipping backup...")
|
||||||
|
return False
|
||||||
|
|
||||||
|
try:
|
||||||
|
self._backup_root.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
|
filename = (
|
||||||
|
target_name
|
||||||
|
or f"{source_path.stem}_{self.timestamp}{source_path.suffix}"
|
||||||
|
)
|
||||||
|
if target_path is not None:
|
||||||
|
backup_path = self._backup_root.joinpath(target_path, filename)
|
||||||
|
else:
|
||||||
|
backup_path = self._backup_root.joinpath(filename)
|
||||||
|
|
||||||
|
backup_path.mkdir(parents=True, exist_ok=True)
|
||||||
|
shutil.copy2(source_path, backup_path)
|
||||||
|
|
||||||
|
Logger.print_ok(
|
||||||
|
f"Successfully backed up '{source_path}' to '{backup_path}'"
|
||||||
|
)
|
||||||
|
return True
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
Logger.print_error(f"Failed to backup '{source_path}': {e}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
def backup_directory(
|
||||||
|
self,
|
||||||
|
source_path: Path,
|
||||||
|
backup_name: str,
|
||||||
|
target_path: Optional[Path | str] = None,
|
||||||
|
) -> Optional[Path]:
|
||||||
|
source_path = Path(source_path)
|
||||||
|
|
||||||
|
Logger.print_status(f"Creating backup of {source_path} ...")
|
||||||
|
|
||||||
|
if not source_path.exists():
|
||||||
|
Logger.print_info(
|
||||||
|
f"Directory '{source_path}' does not exist! Skipping backup..."
|
||||||
|
)
|
||||||
|
return None
|
||||||
|
|
||||||
|
if not source_path.is_dir():
|
||||||
|
Logger.print_info(f"'{source_path}' is not a directory! Skipping backup...")
|
||||||
|
return None
|
||||||
|
|
||||||
|
try:
|
||||||
|
self._backup_root.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
|
backup_dir_name = f"{backup_name}_{self.timestamp}"
|
||||||
|
|
||||||
|
if target_path is not None:
|
||||||
|
backup_path = self._backup_root.joinpath(target_path, backup_dir_name)
|
||||||
|
else:
|
||||||
|
backup_path = self._backup_root.joinpath(backup_dir_name)
|
||||||
|
|
||||||
|
shutil.copytree(source_path, backup_path)
|
||||||
|
|
||||||
|
Logger.print_ok(
|
||||||
|
f"Successfully backed up '{source_path}' to '{backup_path}'"
|
||||||
|
)
|
||||||
|
return backup_path
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
Logger.print_error(f"Failed to backup directory '{source_path}': {e}")
|
||||||
|
return None
|
||||||
|
|
||||||
|
################################################
|
||||||
|
# SPECIFIC BACKUP METHODS
|
||||||
|
################################################
|
||||||
|
|
||||||
|
def backup_printer_cfg(self):
|
||||||
|
klipper_instances: List[Klipper] = get_instances(Klipper)
|
||||||
|
for instance in klipper_instances:
|
||||||
|
target_path: Path = self._backup_root.joinpath(
|
||||||
|
instance.data_dir.name, f"config_{self.timestamp}"
|
||||||
|
)
|
||||||
|
self.backup_file(
|
||||||
|
source_path=instance.cfg_file,
|
||||||
|
target_path=target_path,
|
||||||
|
target_name=instance.cfg_file.name,
|
||||||
|
)
|
||||||
|
|
||||||
|
def backup_moonraker_conf(self):
|
||||||
|
moonraker_instances: List[Moonraker] = get_instances(Moonraker)
|
||||||
|
for instance in moonraker_instances:
|
||||||
|
target_path: Path = self._backup_root.joinpath(
|
||||||
|
instance.data_dir.name, f"config_{self.timestamp}"
|
||||||
|
)
|
||||||
|
self.backup_file(
|
||||||
|
source_path=instance.cfg_file,
|
||||||
|
target_path=target_path,
|
||||||
|
target_name=instance.cfg_file.name,
|
||||||
|
)
|
||||||
|
|
||||||
|
def backup_printer_config_dir(self) -> None:
|
||||||
|
instances: List[Klipper] = get_instances(Klipper)
|
||||||
|
if not instances:
|
||||||
|
# fallback: search for printer data directories in the user's home directory
|
||||||
|
Logger.print_info("No Klipper instances found via systemd services.")
|
||||||
|
Logger.print_info(
|
||||||
|
"Attempting to find printer data directories in home directory..."
|
||||||
|
)
|
||||||
|
|
||||||
|
home_dir = Path.home()
|
||||||
|
printer_data_dirs = []
|
||||||
|
|
||||||
|
for pattern in ["printer_data", "printer_*_data"]:
|
||||||
|
for data_dir in home_dir.glob(pattern):
|
||||||
|
if data_dir.is_dir():
|
||||||
|
printer_data_dirs.append(data_dir)
|
||||||
|
|
||||||
|
if not printer_data_dirs:
|
||||||
|
Logger.print_info("Unable to find directory to backup!")
|
||||||
|
Logger.print_info(
|
||||||
|
"No printer data directories found in home directory."
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
|
for data_dir in printer_data_dirs:
|
||||||
|
self.backup_directory(
|
||||||
|
source_path=data_dir.joinpath("config"),
|
||||||
|
target_path=data_dir.name,
|
||||||
|
backup_name="config",
|
||||||
|
)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
for instance in instances:
|
||||||
|
self.backup_directory(
|
||||||
|
source_path=instance.base.cfg_dir,
|
||||||
|
target_path=f"{instance.data_dir.name}",
|
||||||
|
backup_name="config",
|
||||||
|
)
|
||||||
@@ -14,8 +14,8 @@ from typing import Any, Callable, List, TypeVar
|
|||||||
|
|
||||||
from components.klipper import KLIPPER_REPO_URL
|
from components.klipper import KLIPPER_REPO_URL
|
||||||
from components.moonraker import MOONRAKER_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.logger import DialogType, Logger
|
||||||
|
from core.services.backup_service import BackupService
|
||||||
from core.submodules.simple_config_parser.src.simple_config_parser.simple_config_parser import (
|
from core.submodules.simple_config_parser.src.simple_config_parser.simple_config_parser import (
|
||||||
SimpleConfigParser,
|
SimpleConfigParser,
|
||||||
)
|
)
|
||||||
@@ -374,8 +374,8 @@ class KiauhSettings:
|
|||||||
kill()
|
kill()
|
||||||
|
|
||||||
def _migrate_repo_config(self) -> None:
|
def _migrate_repo_config(self) -> None:
|
||||||
bm = BackupManager()
|
svc = BackupService()
|
||||||
if not bm.backup_file(CUSTOM_CFG):
|
if not svc.backup_file(CUSTOM_CFG):
|
||||||
Logger.print_dialog(
|
Logger.print_dialog(
|
||||||
DialogType.ERROR,
|
DialogType.ERROR,
|
||||||
[
|
[
|
||||||
|
|||||||
@@ -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
|
- Option Block: A line starting with a word, followed by a `:` or `=` and a newline
|
||||||
- Comment: A line starting with a `#` or `;`
|
- Comment: A line starting with a `#` or `;`
|
||||||
- Blank: A line containing only whitespace characters
|
- 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
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -49,6 +49,9 @@ LINE_COMMENT_RE = re.compile(r"^\s*[#;].*")
|
|||||||
# - the line MUST contain only whitespace characters
|
# - the line MUST contain only whitespace characters
|
||||||
EMPTY_LINE_RE = re.compile(r"^\s*$")
|
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 = {
|
BOOLEAN_STATES = {
|
||||||
"1": True,
|
"1": True,
|
||||||
"yes": True,
|
"yes": True,
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ from ..simple_config_parser.constants import (
|
|||||||
LINE_COMMENT_RE,
|
LINE_COMMENT_RE,
|
||||||
OPTION_RE,
|
OPTION_RE,
|
||||||
OPTIONS_BLOCK_START_RE,
|
OPTIONS_BLOCK_START_RE,
|
||||||
SECTION_RE, LineType, INDENT,
|
SECTION_RE, LineType, INDENT, SAVE_CONFIG_START_RE, SAVE_CONFIG_CONTENT_RE,
|
||||||
)
|
)
|
||||||
|
|
||||||
_UNSET = object()
|
_UNSET = object()
|
||||||
@@ -61,25 +61,34 @@ class SimpleConfigParser:
|
|||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self.header: List[str] = []
|
self.header: List[str] = []
|
||||||
|
self.save_config_block: List[str] = []
|
||||||
self.config: Dict = {}
|
self.config: Dict = {}
|
||||||
self.current_section: str | None = None
|
self.current_section: str | None = None
|
||||||
self.current_opt_block: str | None = None
|
self.current_opt_block: str | None = None
|
||||||
self.in_option_block: bool = False
|
self.in_option_block: bool = False
|
||||||
|
|
||||||
def _match_section(self, line: str) -> bool:
|
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
|
return SECTION_RE.match(line) is not None
|
||||||
|
|
||||||
def _match_option(self, line: str) -> bool:
|
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
|
return OPTION_RE.match(line) is not None
|
||||||
|
|
||||||
def _match_options_block_start(self, line: str) -> bool:
|
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
|
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:
|
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
|
return LINE_COMMENT_RE.match(line) is not None
|
||||||
|
|
||||||
def _match_empty_line(self, line: str) -> bool:
|
def _match_empty_line(self, line: str) -> bool:
|
||||||
@@ -124,6 +133,14 @@ class SimpleConfigParser:
|
|||||||
element["value"].append(line.strip()) # indentation is removed
|
element["value"].append(line.strip()) # indentation is removed
|
||||||
break
|
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):
|
elif self._match_empty_line(line) or self._match_line_comment(line):
|
||||||
self.current_opt_block = None
|
self.current_opt_block = None
|
||||||
|
|
||||||
@@ -185,6 +202,11 @@ class SimpleConfigParser:
|
|||||||
if not last_line.endswith("\n"):
|
if not last_line.endswith("\n"):
|
||||||
f.write("\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]:
|
def get_sections(self) -> List[str]:
|
||||||
"""Return a list of all section names, but exclude any section starting with '#_'"""
|
"""Return a list of all section names, but exclude any section starting with '#_'"""
|
||||||
return list(
|
return list(
|
||||||
|
|||||||
@@ -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 isn’t an object and shouldn’t 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
|
||||||
@@ -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
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
#*# leading space prevents match
|
||||||
|
random
|
||||||
|
*# not starting with hash-star-hash
|
||||||
|
# *# spaced out
|
||||||
|
<- SAVE_CONFIG ->
|
||||||
|
;#*# semicolon first
|
||||||
@@ -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}"
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
#*# <- SAVE_CONFIG ->
|
||||||
|
#*# <---- SAVE_CONFIG ---->
|
||||||
|
#*# <------------------- SAVE_CONFIG ------------------->
|
||||||
|
#*# <---------------------- SAVE_CONFIG ---------------------->
|
||||||
|
#*# <----- SAVE_CONFIG ->
|
||||||
|
#*# <- SAVE_CONFIG ----------------->
|
||||||
@@ -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
|
||||||
@@ -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}"
|
||||||
@@ -13,7 +13,7 @@ from src.simple_config_parser.simple_config_parser import SimpleConfigParser
|
|||||||
from tests.utils import load_testdata_from_file
|
from tests.utils import load_testdata_from_file
|
||||||
|
|
||||||
BASE_DIR = Path(__file__).parent.parent.joinpath("assets")
|
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)
|
@pytest.fixture(params=CONFIG_FILES)
|
||||||
|
|||||||
@@ -143,6 +143,31 @@ class ExtensionSubmenu(BaseMenu):
|
|||||||
"""
|
"""
|
||||||
)[1:]
|
)[1:]
|
||||||
menu += f"{description_text}\n"
|
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(
|
menu += textwrap.dedent(
|
||||||
"""
|
"""
|
||||||
╟───────────────────────────────────────────────────────╢
|
╟───────────────────────────────────────────────────────╢
|
||||||
|
|||||||
@@ -9,12 +9,13 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
|
from datetime import datetime
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from components.klipper.klipper import Klipper
|
from components.klipper.klipper import Klipper
|
||||||
from core.backup_manager.backup_manager import BackupManager
|
|
||||||
from core.instance_manager.instance_manager import InstanceManager
|
from core.instance_manager.instance_manager import InstanceManager
|
||||||
from core.logger import Logger
|
from core.logger import Logger
|
||||||
|
from core.services.backup_service import BackupService
|
||||||
from core.submodules.simple_config_parser.src.simple_config_parser.simple_config_parser import (
|
from core.submodules.simple_config_parser.src.simple_config_parser.simple_config_parser import (
|
||||||
SimpleConfigParser,
|
SimpleConfigParser,
|
||||||
)
|
)
|
||||||
@@ -109,11 +110,13 @@ class GcodeShellCmdExtension(BaseExtension):
|
|||||||
Logger.warn(f"Unable to create example config: {e}")
|
Logger.warn(f"Unable to create example config: {e}")
|
||||||
|
|
||||||
# backup each printer.cfg before modification
|
# backup each printer.cfg before modification
|
||||||
bm = BackupManager()
|
svc = BackupService()
|
||||||
|
timestamp = datetime.now().strftime("%Y%m%d-%H%M%S")
|
||||||
for instance in instances:
|
for instance in instances:
|
||||||
bm.backup_file(
|
svc.backup_file(
|
||||||
instance.cfg_file,
|
source_path=instance.cfg_file,
|
||||||
custom_filename=f"{instance.suffix}.printer.cfg",
|
target_path=f"{instance.data_dir.name}/config_{timestamp}",
|
||||||
|
target_name=instance.cfg_file.name,
|
||||||
)
|
)
|
||||||
|
|
||||||
# add section to printer.cfg if not already defined
|
# add section to printer.cfg if not already defined
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
"module": "gcode_shell_cmd_extension",
|
"module": "gcode_shell_cmd_extension",
|
||||||
"maintained_by": "dw-0",
|
"maintained_by": "dw-0",
|
||||||
"display_name": "G-Code Shell Command",
|
"display_name": "G-Code Shell Command",
|
||||||
"description": ["Run a shell commands from gcode."]
|
"description": ["Run a shell commands from gcode."],
|
||||||
|
"updates": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,8 @@
|
|||||||
"maintained_by": "Staubgeborener",
|
"maintained_by": "Staubgeborener",
|
||||||
"display_name": "Klipper-Backup",
|
"display_name": "Klipper-Backup",
|
||||||
"description": ["Backup all your Klipper files to GitHub"],
|
"description": ["Backup all your Klipper files to GitHub"],
|
||||||
|
"website": "https://klipperbackup.xyz",
|
||||||
|
"repo": "https://github.com/Staubgeborener/klipper-backup",
|
||||||
"updates": true
|
"updates": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
"module": "mainsail_theme_installer_extension",
|
"module": "mainsail_theme_installer_extension",
|
||||||
"maintained_by": "dw-0",
|
"maintained_by": "dw-0",
|
||||||
"display_name": "Mainsail Theme Installer",
|
"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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from core.backup_manager import BACKUP_ROOT_DIR
|
|
||||||
from core.constants import SYSTEMD
|
from core.constants import SYSTEMD
|
||||||
|
|
||||||
# repo
|
# repo
|
||||||
@@ -23,7 +22,6 @@ MOBILERAKER_LOG_NAME = "mobileraker.log"
|
|||||||
# directories
|
# directories
|
||||||
MOBILERAKER_DIR = Path.home().joinpath("mobileraker_companion")
|
MOBILERAKER_DIR = Path.home().joinpath("mobileraker_companion")
|
||||||
MOBILERAKER_ENV_DIR = Path.home().joinpath("mobileraker-env")
|
MOBILERAKER_ENV_DIR = Path.home().joinpath("mobileraker-env")
|
||||||
MOBILERAKER_BACKUP_DIR = BACKUP_ROOT_DIR.joinpath("mobileraker-backups")
|
|
||||||
|
|
||||||
# files
|
# files
|
||||||
MOBILERAKER_INSTALL_SCRIPT = MOBILERAKER_DIR.joinpath("scripts/install.sh")
|
MOBILERAKER_INSTALL_SCRIPT = MOBILERAKER_DIR.joinpath("scripts/install.sh")
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
"description": [
|
"description": [
|
||||||
"Companion for Mobileraker, enabling push notification for Klipper using Moonraker."
|
"Companion for Mobileraker, enabling push notification for Klipper using Moonraker."
|
||||||
],
|
],
|
||||||
|
"repo": "https://github.com/Clon1998/mobileraker_companion",
|
||||||
"updates": true
|
"updates": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,13 +13,12 @@ from typing import List
|
|||||||
|
|
||||||
from components.klipper.klipper import Klipper
|
from components.klipper.klipper import Klipper
|
||||||
from components.moonraker.moonraker import Moonraker
|
from components.moonraker.moonraker import Moonraker
|
||||||
from core.backup_manager.backup_manager import BackupManager
|
|
||||||
from core.instance_manager.instance_manager import InstanceManager
|
from core.instance_manager.instance_manager import InstanceManager
|
||||||
from core.logger import DialogType, Logger
|
from core.logger import DialogType, Logger
|
||||||
|
from core.services.backup_service import BackupService
|
||||||
from core.settings.kiauh_settings import KiauhSettings
|
from core.settings.kiauh_settings import KiauhSettings
|
||||||
from extensions.base_extension import BaseExtension
|
from extensions.base_extension import BaseExtension
|
||||||
from extensions.mobileraker import (
|
from extensions.mobileraker import (
|
||||||
MOBILERAKER_BACKUP_DIR,
|
|
||||||
MOBILERAKER_DIR,
|
MOBILERAKER_DIR,
|
||||||
MOBILERAKER_ENV_DIR,
|
MOBILERAKER_ENV_DIR,
|
||||||
MOBILERAKER_INSTALL_SCRIPT,
|
MOBILERAKER_INSTALL_SCRIPT,
|
||||||
@@ -152,6 +151,7 @@ class MobilerakerExtension(BaseExtension):
|
|||||||
Logger.print_status(
|
Logger.print_status(
|
||||||
"Removing Mobileraker's companion from update manager ..."
|
"Removing Mobileraker's companion from update manager ..."
|
||||||
)
|
)
|
||||||
|
BackupService().backup_moonraker_conf()
|
||||||
remove_config_section(MOBILERAKER_UPDATER_SECTION_NAME, mr_instances)
|
remove_config_section(MOBILERAKER_UPDATER_SECTION_NAME, mr_instances)
|
||||||
Logger.print_ok(
|
Logger.print_ok(
|
||||||
"Mobileraker's companion successfully removed from update manager!"
|
"Mobileraker's companion successfully removed from update manager!"
|
||||||
@@ -163,6 +163,7 @@ class MobilerakerExtension(BaseExtension):
|
|||||||
Logger.print_error(f"Error removing Mobileraker's companion:\n{e}")
|
Logger.print_error(f"Error removing Mobileraker's companion:\n{e}")
|
||||||
|
|
||||||
def _patch_mobileraker_update_manager(self, instances: List[Moonraker]) -> None:
|
def _patch_mobileraker_update_manager(self, instances: List[Moonraker]) -> None:
|
||||||
|
BackupService().backup_moonraker_conf()
|
||||||
add_config_section(
|
add_config_section(
|
||||||
section=MOBILERAKER_UPDATER_SECTION_NAME,
|
section=MOBILERAKER_UPDATER_SECTION_NAME,
|
||||||
instances=instances,
|
instances=instances,
|
||||||
@@ -179,14 +180,14 @@ class MobilerakerExtension(BaseExtension):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def _backup_mobileraker_dir(self) -> None:
|
def _backup_mobileraker_dir(self) -> None:
|
||||||
bm = BackupManager()
|
svc = BackupService()
|
||||||
bm.backup_directory(
|
svc.backup_directory(
|
||||||
MOBILERAKER_DIR.name,
|
source_path=MOBILERAKER_DIR,
|
||||||
source=MOBILERAKER_DIR,
|
backup_name="mobileraker",
|
||||||
target=MOBILERAKER_BACKUP_DIR,
|
target_path="mobileraker",
|
||||||
)
|
)
|
||||||
bm.backup_directory(
|
svc.backup_directory(
|
||||||
MOBILERAKER_ENV_DIR.name,
|
source_path=MOBILERAKER_ENV_DIR,
|
||||||
source=MOBILERAKER_ENV_DIR,
|
backup_name="mobileraker-env",
|
||||||
target=MOBILERAKER_BACKUP_DIR,
|
target_path="mobileraker",
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -11,6 +11,8 @@
|
|||||||
"- 25FPS High-Def Webcam Streaming",
|
"- 25FPS High-Def Webcam Streaming",
|
||||||
"- Free 4.9-Star Mobile App"
|
"- Free 4.9-Star Mobile App"
|
||||||
],
|
],
|
||||||
|
"website": "https://obico.io",
|
||||||
|
"repo": "github.com/TheSpaghettiDetective/moonraker-obico",
|
||||||
"updates": true
|
"updates": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ from components.moonraker.moonraker import Moonraker
|
|||||||
from core.instance_manager.base_instance import SUFFIX_BLACKLIST
|
from core.instance_manager.base_instance import SUFFIX_BLACKLIST
|
||||||
from core.instance_manager.instance_manager import InstanceManager
|
from core.instance_manager.instance_manager import InstanceManager
|
||||||
from core.logger import DialogType, Logger
|
from core.logger import DialogType, Logger
|
||||||
|
from core.services.backup_service import BackupService
|
||||||
from core.submodules.simple_config_parser.src.simple_config_parser.simple_config_parser import (
|
from core.submodules.simple_config_parser.src.simple_config_parser.simple_config_parser import (
|
||||||
SimpleConfigParser,
|
SimpleConfigParser,
|
||||||
)
|
)
|
||||||
@@ -31,7 +32,10 @@ from extensions.obico import (
|
|||||||
from extensions.obico.moonraker_obico import (
|
from extensions.obico.moonraker_obico import (
|
||||||
MoonrakerObico,
|
MoonrakerObico,
|
||||||
)
|
)
|
||||||
from utils.common import check_install_dependencies, moonraker_exists
|
from utils.common import (
|
||||||
|
check_install_dependencies,
|
||||||
|
moonraker_exists,
|
||||||
|
)
|
||||||
from utils.config_utils import (
|
from utils.config_utils import (
|
||||||
add_config_section,
|
add_config_section,
|
||||||
remove_config_section,
|
remove_config_section,
|
||||||
@@ -119,6 +123,8 @@ class ObicoExtension(BaseExtension):
|
|||||||
|
|
||||||
cmd_sysctl_manage("daemon-reload")
|
cmd_sysctl_manage("daemon-reload")
|
||||||
|
|
||||||
|
BackupService().backup_printer_config_dir()
|
||||||
|
|
||||||
# add to klippers config
|
# add to klippers config
|
||||||
self._patch_printer_cfg(kl_instances)
|
self._patch_printer_cfg(kl_instances)
|
||||||
InstanceManager.restart_all(kl_instances)
|
InstanceManager.restart_all(kl_instances)
|
||||||
@@ -165,6 +171,7 @@ class ObicoExtension(BaseExtension):
|
|||||||
self._remove_obico_instances(ob_instances)
|
self._remove_obico_instances(ob_instances)
|
||||||
self._remove_obico_dir()
|
self._remove_obico_dir()
|
||||||
self._remove_obico_env()
|
self._remove_obico_env()
|
||||||
|
BackupService().backup_printer_config_dir()
|
||||||
remove_config_section(f"include {OBICO_MACROS_CFG_NAME}", kl_instances)
|
remove_config_section(f"include {OBICO_MACROS_CFG_NAME}", kl_instances)
|
||||||
remove_config_section(f"include {OBICO_UPDATE_CFG_NAME}", mr_instances)
|
remove_config_section(f"include {OBICO_UPDATE_CFG_NAME}", mr_instances)
|
||||||
Logger.print_dialog(
|
Logger.print_dialog(
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
"- Live Gcode preview",
|
"- Live Gcode preview",
|
||||||
"- And much much more!"
|
"- And much much more!"
|
||||||
],
|
],
|
||||||
|
"repo": "https://github.com/crysxd/OctoApp-Plugin",
|
||||||
"updates": true
|
"updates": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ from components.klipper.klipper import Klipper
|
|||||||
from components.moonraker.moonraker import Moonraker
|
from components.moonraker.moonraker import Moonraker
|
||||||
from core.instance_manager.instance_manager import InstanceManager
|
from core.instance_manager.instance_manager import InstanceManager
|
||||||
from core.logger import DialogType, Logger
|
from core.logger import DialogType, Logger
|
||||||
|
from core.services.backup_service import BackupService
|
||||||
from extensions.base_extension import BaseExtension
|
from extensions.base_extension import BaseExtension
|
||||||
from extensions.octoapp import (
|
from extensions.octoapp import (
|
||||||
OA_DEPS_JSON_FILE,
|
OA_DEPS_JSON_FILE,
|
||||||
@@ -133,6 +134,7 @@ class OctoappExtension(BaseExtension):
|
|||||||
self._remove_OA_store_dirs()
|
self._remove_OA_store_dirs()
|
||||||
self._remove_OA_dir()
|
self._remove_OA_dir()
|
||||||
self._remove_OA_env()
|
self._remove_OA_env()
|
||||||
|
BackupService().backup_moonraker_conf()
|
||||||
remove_config_section(f"include {OA_SYS_CFG_NAME}", mr_instances)
|
remove_config_section(f"include {OA_SYS_CFG_NAME}", mr_instances)
|
||||||
run_remove_routines(OA_INSTALLER_LOG_FILE)
|
run_remove_routines(OA_INSTALLER_LOG_FILE)
|
||||||
Logger.print_dialog(
|
Logger.print_dialog(
|
||||||
|
|||||||
@@ -11,6 +11,8 @@
|
|||||||
"- Real-time Notifications",
|
"- Real-time Notifications",
|
||||||
"- Live Streaming, and More!"
|
"- Live Streaming, and More!"
|
||||||
],
|
],
|
||||||
|
"website": "https://octoeverywhere.com",
|
||||||
|
"repo": "github.com/QuinnDamerell/OctoPrint-OctoEverywhere",
|
||||||
"updates": true
|
"updates": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ from typing import List
|
|||||||
from components.moonraker.moonraker import Moonraker
|
from components.moonraker.moonraker import Moonraker
|
||||||
from core.instance_manager.instance_manager import InstanceManager
|
from core.instance_manager.instance_manager import InstanceManager
|
||||||
from core.logger import DialogType, Logger
|
from core.logger import DialogType, Logger
|
||||||
|
from core.services.backup_service import BackupService
|
||||||
from extensions.base_extension import BaseExtension
|
from extensions.base_extension import BaseExtension
|
||||||
from extensions.octoeverywhere import (
|
from extensions.octoeverywhere import (
|
||||||
OE_DEPS_JSON_FILE,
|
OE_DEPS_JSON_FILE,
|
||||||
@@ -133,6 +134,7 @@ class OctoeverywhereExtension(BaseExtension):
|
|||||||
self._remove_oe_instances(ob_instances)
|
self._remove_oe_instances(ob_instances)
|
||||||
self._remove_oe_dir()
|
self._remove_oe_dir()
|
||||||
self._remove_oe_env()
|
self._remove_oe_env()
|
||||||
|
BackupService().backup_moonraker_conf()
|
||||||
remove_config_section(f"include {OE_SYS_CFG_NAME}", mr_instances)
|
remove_config_section(f"include {OE_SYS_CFG_NAME}", mr_instances)
|
||||||
run_remove_routines(OE_INSTALLER_LOG_FILE)
|
run_remove_routines(OE_INSTALLER_LOG_FILE)
|
||||||
Logger.print_dialog(
|
Logger.print_dialog(
|
||||||
|
|||||||
@@ -6,7 +6,17 @@
|
|||||||
# #
|
# #
|
||||||
# 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 #
|
||||||
# ======================================================================= #
|
# ======================================================================= #
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
BACKUP_ROOT_DIR = Path.home().joinpath("kiauh-backups")
|
# 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")
|
||||||
18
kiauh/extensions/octoprint/metadata.json
Normal file
18
kiauh/extensions/octoprint/metadata.json
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
116
kiauh/extensions/octoprint/octoprint.py
Normal file
116
kiauh/extensions/octoprint/octoprint.py
Normal 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
|
||||||
|
"""
|
||||||
|
)
|
||||||
286
kiauh/extensions/octoprint/octoprint_extension.py
Normal file
286
kiauh/extensions/octoprint/octoprint_extension.py
Normal 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}")
|
||||||
@@ -5,6 +5,7 @@
|
|||||||
"maintained_by": "Kragrathea",
|
"maintained_by": "Kragrathea",
|
||||||
"display_name": "PrettyGCode for Klipper",
|
"display_name": "PrettyGCode for Klipper",
|
||||||
"description": ["3D G-Code viewer for Klipper"],
|
"description": ["3D G-Code viewer for Klipper"],
|
||||||
|
"repo": "https://github.com/Kragrathea/pgcode",
|
||||||
"updates": true
|
"updates": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,16 @@
|
|||||||
{
|
{
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"index": 10,
|
"index": 10,
|
||||||
"module": "simply_print_extension",
|
"module": "simply_print_extension",
|
||||||
"maintained_by": "dw-0",
|
"maintained_by": "dw-0",
|
||||||
"display_name": "SimplyPrint",
|
"display_name": "SimplyPrint",
|
||||||
"description": [
|
"description": [
|
||||||
"3D Printer Cloud Management Software.",
|
"3D Printer Cloud Management Software.",
|
||||||
"\n\n",
|
"\n\n",
|
||||||
"3D printing doesn't have to be a complicated, analog, SD card-filled experience; step into the future of modern 3D printing"
|
"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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,11 +11,12 @@ from typing import List
|
|||||||
from components.moonraker.moonraker import Moonraker
|
from components.moonraker.moonraker import Moonraker
|
||||||
from core.instance_manager.instance_manager import InstanceManager
|
from core.instance_manager.instance_manager import InstanceManager
|
||||||
from core.logger import DialogType, Logger
|
from core.logger import DialogType, Logger
|
||||||
|
from core.services.backup_service import BackupService
|
||||||
from core.submodules.simple_config_parser.src.simple_config_parser.simple_config_parser import (
|
from core.submodules.simple_config_parser.src.simple_config_parser.simple_config_parser import (
|
||||||
SimpleConfigParser,
|
SimpleConfigParser,
|
||||||
)
|
)
|
||||||
from extensions.base_extension import BaseExtension
|
from extensions.base_extension import BaseExtension
|
||||||
from utils.common import backup_printer_config_dir, moonraker_exists
|
from utils.common import moonraker_exists
|
||||||
from utils.input_utils import get_confirm
|
from utils.input_utils import get_confirm
|
||||||
|
|
||||||
|
|
||||||
@@ -112,10 +113,10 @@ class SimplyPrintExtension(BaseExtension):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
if is_install and not scp.has_section("simplyprint"):
|
if is_install and not scp.has_section("simplyprint"):
|
||||||
backup_printer_config_dir()
|
BackupService().backup_printer_config_dir()
|
||||||
scp.add_section(section)
|
scp.add_section(section)
|
||||||
elif not is_install and scp.has_section("simplyprint"):
|
elif not is_install and scp.has_section("simplyprint"):
|
||||||
backup_printer_config_dir()
|
BackupService().backup_printer_config_dir()
|
||||||
scp.remove_section(section)
|
scp.remove_section(section)
|
||||||
scp.write_file(moonraker.cfg_file)
|
scp.write_file(moonraker.cfg_file)
|
||||||
patched_files.append(moonraker.cfg_file)
|
patched_files.append(moonraker.cfg_file)
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
"\n\n",
|
"\n\n",
|
||||||
"Note: This extension installs Spoolman using Docker. Docker must be installed on your system before installing Spoolman."
|
"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
|
"updates": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,9 +15,9 @@ from components.moonraker.moonraker import Moonraker
|
|||||||
from components.moonraker.services.moonraker_instance_service import (
|
from components.moonraker.services.moonraker_instance_service import (
|
||||||
MoonrakerInstanceService,
|
MoonrakerInstanceService,
|
||||||
)
|
)
|
||||||
from core.backup_manager.backup_manager import BackupManager
|
|
||||||
from core.instance_manager.instance_manager import InstanceManager
|
from core.instance_manager.instance_manager import InstanceManager
|
||||||
from core.logger import DialogType, Logger
|
from core.logger import DialogType, Logger
|
||||||
|
from core.services.backup_service import BackupService
|
||||||
from extensions.base_extension import BaseExtension
|
from extensions.base_extension import BaseExtension
|
||||||
from extensions.spoolman import (
|
from extensions.spoolman import (
|
||||||
SPOOLMAN_COMPOSE_FILE,
|
SPOOLMAN_COMPOSE_FILE,
|
||||||
@@ -100,6 +100,7 @@ class SpoolmanExtension(BaseExtension):
|
|||||||
mr_instances: List[Moonraker] = mrsvc.get_all_instances()
|
mr_instances: List[Moonraker] = mrsvc.get_all_instances()
|
||||||
|
|
||||||
Logger.print_status("Removing Spoolman configuration from moonraker.conf...")
|
Logger.print_status("Removing Spoolman configuration from moonraker.conf...")
|
||||||
|
BackupService().backup_moonraker_conf()
|
||||||
remove_config_section("spoolman", mr_instances)
|
remove_config_section("spoolman", mr_instances)
|
||||||
|
|
||||||
Logger.print_status("Removing Spoolman from moonraker.asvc...")
|
Logger.print_status("Removing Spoolman from moonraker.asvc...")
|
||||||
@@ -123,16 +124,15 @@ class SpoolmanExtension(BaseExtension):
|
|||||||
"Failed to remove Spoolman image! Please remove it manually."
|
"Failed to remove Spoolman image! Please remove it manually."
|
||||||
)
|
)
|
||||||
|
|
||||||
# backup Spoolman directory to ~/spoolman_data-<timestamp> before removing it
|
|
||||||
try:
|
try:
|
||||||
bm = BackupManager()
|
svc = BackupService()
|
||||||
result = bm.backup_directory(
|
success = svc.backup_directory(
|
||||||
f"{SPOOLMAN_DIR.name}_data",
|
source_path=SPOOLMAN_DIR,
|
||||||
source=SPOOLMAN_DIR,
|
backup_name="spoolman",
|
||||||
target=SPOOLMAN_DIR.parent,
|
target_path="spoolman",
|
||||||
)
|
)
|
||||||
if result:
|
if success:
|
||||||
Logger.print_ok(f"Spoolman data backed up to {result}")
|
Logger.print_ok(f"Spoolman data backed up to {success}")
|
||||||
Logger.print_status("Removing Spoolman directory...")
|
Logger.print_status("Removing Spoolman directory...")
|
||||||
if run_remove_routines(SPOOLMAN_DIR):
|
if run_remove_routines(SPOOLMAN_DIR):
|
||||||
Logger.print_ok("Spoolman directory removed!")
|
Logger.print_ok("Spoolman directory removed!")
|
||||||
@@ -290,6 +290,7 @@ class SpoolmanExtension(BaseExtension):
|
|||||||
mrsvc.load_instances()
|
mrsvc.load_instances()
|
||||||
mr_instances = mrsvc.get_all_instances()
|
mr_instances = mrsvc.get_all_instances()
|
||||||
|
|
||||||
|
BackupService().backup_moonraker_conf()
|
||||||
# noinspection HttpUrlsUsage
|
# noinspection HttpUrlsUsage
|
||||||
add_config_section(
|
add_config_section(
|
||||||
section="spoolman",
|
section="spoolman",
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
"maintained_by": "nlef",
|
"maintained_by": "nlef",
|
||||||
"display_name": "Moonraker Telegram Bot",
|
"display_name": "Moonraker Telegram Bot",
|
||||||
"description": ["Control your printer with the Telegram messenger app."],
|
"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
|
"updates": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ from typing import List
|
|||||||
from components.moonraker.moonraker import Moonraker
|
from components.moonraker.moonraker import Moonraker
|
||||||
from core.instance_manager.instance_manager import InstanceManager
|
from core.instance_manager.instance_manager import InstanceManager
|
||||||
from core.logger import DialogType, Logger
|
from core.logger import DialogType, Logger
|
||||||
|
from core.services.backup_service import BackupService
|
||||||
from extensions.base_extension import BaseExtension
|
from extensions.base_extension import BaseExtension
|
||||||
from extensions.telegram_bot import TG_BOT_REPO, TG_BOT_REQ_FILE
|
from extensions.telegram_bot import TG_BOT_REPO, TG_BOT_REQ_FILE
|
||||||
from extensions.telegram_bot.moonraker_telegram_bot import (
|
from extensions.telegram_bot.moonraker_telegram_bot import (
|
||||||
@@ -105,6 +106,7 @@ class TelegramBotExtension(BaseExtension):
|
|||||||
cmd_sysctl_manage("daemon-reload")
|
cmd_sysctl_manage("daemon-reload")
|
||||||
|
|
||||||
# add to moonraker update manager
|
# add to moonraker update manager
|
||||||
|
BackupService().backup_moonraker_conf()
|
||||||
self._patch_bot_update_manager(mr_instances)
|
self._patch_bot_update_manager(mr_instances)
|
||||||
|
|
||||||
# restart moonraker
|
# restart moonraker
|
||||||
@@ -150,6 +152,7 @@ class TelegramBotExtension(BaseExtension):
|
|||||||
self._remove_bot_instances(tb_instances)
|
self._remove_bot_instances(tb_instances)
|
||||||
self._remove_bot_dir()
|
self._remove_bot_dir()
|
||||||
self._remove_bot_env()
|
self._remove_bot_env()
|
||||||
|
BackupService().backup_moonraker_conf()
|
||||||
remove_config_section("update_manager moonraker-telegram-bot", mr_instances)
|
remove_config_section("update_manager moonraker-telegram-bot", mr_instances)
|
||||||
self._delete_bot_logs(tb_instances)
|
self._delete_bot_logs(tb_instances)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ from pathlib import Path
|
|||||||
from typing import Literal
|
from typing import Literal
|
||||||
|
|
||||||
from components.klipper import (
|
from components.klipper import (
|
||||||
KLIPPER_BACKUP_DIR,
|
|
||||||
KLIPPER_DIR,
|
KLIPPER_DIR,
|
||||||
KLIPPER_ENV_DIR,
|
KLIPPER_ENV_DIR,
|
||||||
KLIPPER_REQ_FILE,
|
KLIPPER_REQ_FILE,
|
||||||
@@ -21,7 +20,6 @@ from components.klipper import (
|
|||||||
from components.klipper.klipper import Klipper
|
from components.klipper.klipper import Klipper
|
||||||
from components.klipper.klipper_utils import install_klipper_packages
|
from components.klipper.klipper_utils import install_klipper_packages
|
||||||
from components.moonraker import (
|
from components.moonraker import (
|
||||||
MOONRAKER_BACKUP_DIR,
|
|
||||||
MOONRAKER_DIR,
|
MOONRAKER_DIR,
|
||||||
MOONRAKER_ENV_DIR,
|
MOONRAKER_ENV_DIR,
|
||||||
MOONRAKER_REQ_FILE,
|
MOONRAKER_REQ_FILE,
|
||||||
@@ -30,10 +28,10 @@ from components.moonraker.moonraker import Moonraker
|
|||||||
from components.moonraker.services.moonraker_setup_service import (
|
from components.moonraker.services.moonraker_setup_service import (
|
||||||
install_moonraker_packages,
|
install_moonraker_packages,
|
||||||
)
|
)
|
||||||
from core.backup_manager.backup_manager import BackupManager, BackupManagerException
|
|
||||||
from core.instance_manager.instance_manager import InstanceManager
|
from core.instance_manager.instance_manager import InstanceManager
|
||||||
from core.logger import Logger
|
from core.logger import Logger
|
||||||
from utils.git_utils import GitException, get_repo_name, git_clone_wrapper
|
from core.services.backup_service import BackupService
|
||||||
|
from utils.git_utils import GitException, git_clone_wrapper
|
||||||
from utils.instance_utils import get_instances
|
from utils.instance_utils import get_instances
|
||||||
from utils.sys_utils import (
|
from utils.sys_utils import (
|
||||||
VenvCreationFailedException,
|
VenvCreationFailedException,
|
||||||
@@ -52,7 +50,6 @@ def run_switch_repo_routine(
|
|||||||
repo_dir: Path = KLIPPER_DIR if name == "klipper" else MOONRAKER_DIR
|
repo_dir: Path = KLIPPER_DIR if name == "klipper" else MOONRAKER_DIR
|
||||||
env_dir: Path = KLIPPER_ENV_DIR if name == "klipper" else MOONRAKER_ENV_DIR
|
env_dir: Path = KLIPPER_ENV_DIR if name == "klipper" else MOONRAKER_ENV_DIR
|
||||||
req_file = KLIPPER_REQ_FILE if name == "klipper" else MOONRAKER_REQ_FILE
|
req_file = KLIPPER_REQ_FILE if name == "klipper" else MOONRAKER_REQ_FILE
|
||||||
backup_dir: Path = KLIPPER_BACKUP_DIR if name == "klipper" else MOONRAKER_BACKUP_DIR
|
|
||||||
_type = Klipper if name == "klipper" else Moonraker
|
_type = Klipper if name == "klipper" else Moonraker
|
||||||
|
|
||||||
# step 1: stop all instances
|
# step 1: stop all instances
|
||||||
@@ -64,19 +61,17 @@ def run_switch_repo_routine(
|
|||||||
env_dir_backup_path: Path | None = None
|
env_dir_backup_path: Path | None = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# step 2: backup old repo and env
|
svc = BackupService()
|
||||||
org, _ = get_repo_name(repo_dir)
|
svc.backup_directory(
|
||||||
backup_dir = backup_dir.joinpath(org)
|
source_path=repo_dir,
|
||||||
bm = BackupManager()
|
backup_name=name,
|
||||||
repo_dir_backup_path = bm.backup_directory(
|
target_path=name,
|
||||||
repo_dir.name,
|
|
||||||
repo_dir,
|
|
||||||
backup_dir,
|
|
||||||
)
|
)
|
||||||
env_dir_backup_path = bm.backup_directory(
|
env_backup_name: str = f"{name if name == 'moonraker' else 'klippy'}-env"
|
||||||
env_dir.name,
|
svc.backup_directory(
|
||||||
env_dir,
|
source_path=env_dir,
|
||||||
backup_dir,
|
backup_name=env_backup_name,
|
||||||
|
target_path=name,
|
||||||
)
|
)
|
||||||
|
|
||||||
if not (repo_url or branch):
|
if not (repo_url or branch):
|
||||||
@@ -101,10 +96,6 @@ def run_switch_repo_routine(
|
|||||||
|
|
||||||
Logger.print_ok(f"Switched to {repo_url} at branch {branch}!")
|
Logger.print_ok(f"Switched to {repo_url} at branch {branch}!")
|
||||||
|
|
||||||
except BackupManagerException as e:
|
|
||||||
Logger.print_error(f"Error during backup of repository: {e}")
|
|
||||||
raise RepoSwitchFailedException(e)
|
|
||||||
|
|
||||||
except (GitException, VenvCreationFailedException) as e:
|
except (GitException, VenvCreationFailedException) as e:
|
||||||
# if something goes wrong during cloning or recreating the virtualenv,
|
# if something goes wrong during cloning or recreating the virtualenv,
|
||||||
# we restore the backup of the repo and env
|
# we restore the backup of the repo and env
|
||||||
@@ -122,6 +113,9 @@ def run_switch_repo_routine(
|
|||||||
Logger.print_error(f"Something went wrong: {e}")
|
Logger.print_error(f"Something went wrong: {e}")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
raise RepoSwitchFailedException(e)
|
||||||
|
|
||||||
Logger.print_status(f"Restarting all {_type.__name__} instances ...")
|
Logger.print_status(f"Restarting all {_type.__name__} instances ...")
|
||||||
InstanceManager.start_all(instances)
|
InstanceManager.start_all(instances)
|
||||||
|
|
||||||
|
|||||||
@@ -14,11 +14,9 @@ from datetime import datetime
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Dict, List, Literal, Set
|
from typing import Dict, List, Literal, Set
|
||||||
|
|
||||||
from components.klipper.klipper import Klipper
|
|
||||||
from components.moonraker.moonraker import Moonraker
|
from components.moonraker.moonraker import Moonraker
|
||||||
from core.constants import (
|
from core.constants import (
|
||||||
GLOBAL_DEPS,
|
GLOBAL_DEPS,
|
||||||
PRINTER_DATA_BACKUP_DIR,
|
|
||||||
)
|
)
|
||||||
from core.logger import DialogType, Logger
|
from core.logger import DialogType, Logger
|
||||||
from core.types.color import Color
|
from core.types.color import Color
|
||||||
@@ -42,10 +40,13 @@ from utils.sys_utils import (
|
|||||||
def get_kiauh_version() -> str:
|
def get_kiauh_version() -> str:
|
||||||
"""
|
"""
|
||||||
Helper method to get the current KIAUH version by reading the latest tag
|
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]
|
tags = get_local_tags(Path(__file__).parent.parent)
|
||||||
return lastest_tag
|
if tags:
|
||||||
|
return tags[-1]
|
||||||
|
else:
|
||||||
|
return "v?.?.?"
|
||||||
|
|
||||||
|
|
||||||
def convert_camelcase_to_kebabcase(name: str) -> str:
|
def convert_camelcase_to_kebabcase(name: str) -> str:
|
||||||
@@ -148,26 +149,6 @@ def get_install_status(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def backup_printer_config_dir() -> None:
|
|
||||||
# local import to prevent circular import
|
|
||||||
from core.backup_manager.backup_manager import BackupManager
|
|
||||||
|
|
||||||
instances: List[Klipper] = get_instances(Klipper)
|
|
||||||
bm = BackupManager()
|
|
||||||
|
|
||||||
if not instances:
|
|
||||||
Logger.print_info("Unable to find directory to backup!")
|
|
||||||
Logger.print_info("Are there no Klipper instances installed?")
|
|
||||||
return
|
|
||||||
|
|
||||||
for instance in instances:
|
|
||||||
bm.backup_directory(
|
|
||||||
instance.data_dir.name,
|
|
||||||
source=instance.base.cfg_dir,
|
|
||||||
target=PRINTER_DATA_BACKUP_DIR,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def moonraker_exists(name: str = "") -> List[Moonraker]:
|
def moonraker_exists(name: str = "") -> List[Moonraker]:
|
||||||
"""
|
"""
|
||||||
Helper method to check if a Moonraker instance exists
|
Helper method to check if a Moonraker instance exists
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ from __future__ import annotations
|
|||||||
import shutil
|
import shutil
|
||||||
import tempfile
|
import tempfile
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List, Tuple
|
from typing import List, Tuple, Union
|
||||||
|
|
||||||
from core.logger import Logger
|
from core.logger import Logger
|
||||||
from core.submodules.simple_config_parser.src.simple_config_parser.simple_config_parser import (
|
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
|
from utils.instance_type import InstanceType
|
||||||
|
|
||||||
ConfigOption = Tuple[str, str]
|
ConfigOption = Tuple[str, Union[str, List[str]]]
|
||||||
|
|
||||||
|
|
||||||
def add_config_section(
|
def add_config_section(
|
||||||
@@ -73,7 +73,7 @@ def add_config_section_at_top(section: str, instances: List[InstanceType]) -> No
|
|||||||
tmp.writelines(org_content)
|
tmp.writelines(org_content)
|
||||||
|
|
||||||
cfg_file.unlink()
|
cfg_file.unlink()
|
||||||
shutil.move(tmp_cfg_path, cfg_file)
|
shutil.move(tmp_cfg_path.as_posix(), cfg_file)
|
||||||
|
|
||||||
Logger.print_ok("OK!")
|
Logger.print_ok("OK!")
|
||||||
|
|
||||||
@@ -81,7 +81,7 @@ def add_config_section_at_top(section: str, instances: List[InstanceType]) -> No
|
|||||||
def remove_config_section(
|
def remove_config_section(
|
||||||
section: str, instances: List[InstanceType]
|
section: str, instances: List[InstanceType]
|
||||||
) -> List[InstanceType]:
|
) -> List[InstanceType]:
|
||||||
removed_from: List[instances] = []
|
removed_from: List[InstanceType] = []
|
||||||
for instance in instances:
|
for instance in instances:
|
||||||
cfg_file = instance.cfg_file
|
cfg_file = instance.cfg_file
|
||||||
Logger.print_status(f"Remove section '[{section}]' from '{cfg_file}' ...")
|
Logger.print_status(f"Remove section '[{section}]' from '{cfg_file}' ...")
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ from extensions.obico.moonraker_obico import MoonrakerObico
|
|||||||
from extensions.octoeverywhere.octoeverywhere import Octoeverywhere
|
from extensions.octoeverywhere.octoeverywhere import Octoeverywhere
|
||||||
from extensions.octoapp.octoapp import Octoapp
|
from extensions.octoapp.octoapp import Octoapp
|
||||||
from extensions.telegram_bot.moonraker_telegram_bot import MoonrakerTelegramBot
|
from extensions.telegram_bot.moonraker_telegram_bot import MoonrakerTelegramBot
|
||||||
|
from extensions.octoprint.octoprint import Octoprint
|
||||||
|
|
||||||
InstanceType = TypeVar(
|
InstanceType = TypeVar(
|
||||||
"InstanceType",
|
"InstanceType",
|
||||||
@@ -24,4 +25,5 @@ InstanceType = TypeVar(
|
|||||||
MoonrakerObico,
|
MoonrakerObico,
|
||||||
Octoeverywhere,
|
Octoeverywhere,
|
||||||
Octoapp,
|
Octoapp,
|
||||||
|
Octoprint,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -193,7 +193,7 @@ def install_python_requirements(target: Path, requirements: Path) -> None:
|
|||||||
]
|
]
|
||||||
result = run(command, stderr=PIPE, text=True)
|
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)
|
Logger.print_error(f"{result.stderr}", False)
|
||||||
raise VenvCreationFailedException("Installing Python requirements failed!")
|
raise VenvCreationFailedException("Installing Python requirements failed!")
|
||||||
|
|
||||||
@@ -222,7 +222,7 @@ def install_python_packages(target: Path, packages: List[str]) -> None:
|
|||||||
command.append(pkg)
|
command.append(pkg)
|
||||||
result = run(command, stderr=PIPE, text=True)
|
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)
|
Logger.print_error(f"{result.stderr}", False)
|
||||||
raise VenvCreationFailedException("Installing Python requirements failed!")
|
raise VenvCreationFailedException("Installing Python requirements failed!")
|
||||||
|
|
||||||
|
|||||||
18
klipper_repos.txt.example
Normal file
18
klipper_repos.txt.example
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# This file acts as an example file.
|
||||||
|
#
|
||||||
|
# 1) Make a copy of this file and rename it to 'klipper_repos.txt'
|
||||||
|
# 2) Add your custom Klipper repository to the bottom of that copy
|
||||||
|
# 3) Save the file
|
||||||
|
#
|
||||||
|
# Back in KIAUH you can now go into -> [Settings] and use action '2' to set a different Klipper repository
|
||||||
|
#
|
||||||
|
# Make sure to always separate the repository and the branch with a ','.
|
||||||
|
# <repository>,<branch> -> https://github.com/Klipper3d/klipper,master
|
||||||
|
# If you omit a branch, it will always default to 'master'
|
||||||
|
#
|
||||||
|
# You are allowed to omit the 'https://github.com/' part of the repository URL
|
||||||
|
# Down below are now a few examples of what is considered as valid:
|
||||||
|
https://github.com/Klipper3d/klipper,master
|
||||||
|
https://github.com/Klipper3d/klipper
|
||||||
|
Klipper3d/klipper,master
|
||||||
|
Klipper3d/klipper
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
requires-python = ">=3.8"
|
requires-python = ">=3.8"
|
||||||
|
|
||||||
[project.optional-dependencies]
|
[project.optional-dependencies]
|
||||||
dev=["ruff", "pyright"]
|
dev=["ruff", "mypy"]
|
||||||
|
|
||||||
[tool.ruff]
|
[tool.ruff]
|
||||||
required-version = ">=0.9.10"
|
required-version = ">=0.9.10"
|
||||||
@@ -20,3 +20,14 @@ quote-style = "double"
|
|||||||
|
|
||||||
[tool.ruff.lint]
|
[tool.ruff.lint]
|
||||||
extend-select = ["I"]
|
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
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ function update_klipperscreen() {
|
|||||||
git checkout -f master && ok_msg "Checkout successfull"
|
git checkout -f master && ok_msg "Checkout successfull"
|
||||||
|
|
||||||
if [[ $(md5sum "${KLIPPERSCREEN_DIR}/scripts/KlipperScreen-requirements.txt" | cut -d " " -f1) != "${old_md5}" ]]; then
|
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"
|
"${KLIPPERSCREEN_ENV}"/bin/pip install -r "${KLIPPERSCREEN_DIR}/scripts/KlipperScreen-requirements.txt"
|
||||||
ok_msg "Dependencies have been installed!"
|
ok_msg "Dependencies have been installed!"
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ function update_mobileraker() {
|
|||||||
git checkout -f main && ok_msg "Checkout successfull"
|
git checkout -f main && ok_msg "Checkout successfull"
|
||||||
|
|
||||||
if [[ $(md5sum "${MOBILERAKER_DIR}/scripts/mobileraker-requirements.txt" | cut -d " " -f1) != "${old_md5}" ]]; then
|
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"
|
"${MOBILERAKER_ENV}"/bin/pip install -r "${MOBILERAKER_DIR}/scripts/mobileraker-requirements.txt"
|
||||||
ok_msg "Dependencies have been installed!"
|
ok_msg "Dependencies have been installed!"
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ function moonraker_systemd() {
|
|||||||
###
|
###
|
||||||
# any moonraker client that uses "moonraker" in its own name must be blacklisted using
|
# 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
|
# this variable, otherwise they will be falsely recognized as moonraker instances
|
||||||
blacklist="obico"
|
blacklist="obico|hmi|telegram-bot"
|
||||||
|
|
||||||
ignore="${SYSTEMD}/moonraker-(${blacklist}).service"
|
ignore="${SYSTEMD}/moonraker-(${blacklist}).service"
|
||||||
match="${SYSTEMD}/moonraker(-[0-9a-zA-Z]+)?.service"
|
match="${SYSTEMD}/moonraker(-[0-9a-zA-Z]+)?.service"
|
||||||
@@ -153,11 +153,20 @@ import shlex
|
|||||||
import re
|
import re
|
||||||
import pathlib
|
import pathlib
|
||||||
import logging
|
import logging
|
||||||
import json
|
|
||||||
|
|
||||||
from typing import Tuple, Dict, List, Any
|
from typing import Tuple, Dict, List, Any
|
||||||
|
|
||||||
def _get_distro_info() -> Dict[str, Any]:
|
def _get_distro_info() -> Dict[str, Any]:
|
||||||
|
try:
|
||||||
|
import distro
|
||||||
|
except ModuleNotFoundError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
return dict(
|
||||||
|
distro_id=distro.id(),
|
||||||
|
distro_version=distro.version(),
|
||||||
|
aliases=distro.like().split()
|
||||||
|
)
|
||||||
release_file = pathlib.Path("/etc/os-release")
|
release_file = pathlib.Path("/etc/os-release")
|
||||||
release_info: Dict[str, str] = {}
|
release_info: Dict[str, str] = {}
|
||||||
with release_file.open("r") as f:
|
with release_file.open("r") as f:
|
||||||
@@ -193,6 +202,9 @@ class SysDepsParser:
|
|||||||
version = distro_info.get("distro_version")
|
version = distro_info.get("distro_version")
|
||||||
if version:
|
if version:
|
||||||
self.distro_version = _convert_version(version)
|
self.distro_version = _convert_version(version)
|
||||||
|
self.vendor: str = ""
|
||||||
|
if pathlib.Path("/etc/rpi-issue").is_file():
|
||||||
|
self.vendor = "raspberry-pi"
|
||||||
|
|
||||||
def _parse_spec(self, full_spec: str) -> str | None:
|
def _parse_spec(self, full_spec: str) -> str | None:
|
||||||
parts = full_spec.split(";", maxsplit=1)
|
parts = full_spec.split(";", maxsplit=1)
|
||||||
@@ -237,6 +249,9 @@ class SysDepsParser:
|
|||||||
elif req_var == "distro_id":
|
elif req_var == "distro_id":
|
||||||
left_op: str | Tuple[int | str, ...] = self.distro_id
|
left_op: str | Tuple[int | str, ...] = self.distro_id
|
||||||
right_op = dep_parts[2].strip().strip("\"'")
|
right_op = dep_parts[2].strip().strip("\"'")
|
||||||
|
elif req_var == "vendor":
|
||||||
|
left_op = self.vendor
|
||||||
|
right_op = dep_parts[2].strip().strip("\"'")
|
||||||
elif req_var == "distro_version":
|
elif req_var == "distro_version":
|
||||||
if not self.distro_version:
|
if not self.distro_version:
|
||||||
logging.info(
|
logging.info(
|
||||||
@@ -305,12 +320,12 @@ system_deps = {
|
|||||||
"python3-virtualenv", "python3-dev", "libopenjp2-7", "libsodium-dev",
|
"python3-virtualenv", "python3-dev", "libopenjp2-7", "libsodium-dev",
|
||||||
"zlib1g-dev", "libjpeg-dev", "packagekit",
|
"zlib1g-dev", "libjpeg-dev", "packagekit",
|
||||||
"wireless-tools; distro_id != 'ubuntu' or distro_version <= '24.04'",
|
"wireless-tools; distro_id != 'ubuntu' or distro_version <= '24.04'",
|
||||||
"iw; distro_id == 'ubuntu' and distro_version >= '24.10'", "curl",
|
"iw; distro_id == 'ubuntu' and distro_version >= '24.10'",
|
||||||
"build-essential"
|
"python3-libcamera; vendor == 'raspberry-pi' and distro_version >= '11'",
|
||||||
|
"curl", "build-essential"
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
system_deps_json = pathlib.Path("$package_json")
|
# *** SYSTEM DEPENDENCIES END ***
|
||||||
system_deps = json.loads(system_deps_json.read_bytes())
|
|
||||||
parser = SysDepsParser()
|
parser = SysDepsParser()
|
||||||
pkgs = parser.parse_dependencies(system_deps)
|
pkgs = parser.parse_dependencies(system_deps)
|
||||||
if pkgs:
|
if pkgs:
|
||||||
|
|||||||
Reference in New Issue
Block a user