mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-14 19:14:27 +05:00
Compare commits
28 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
372bab8847 | ||
|
|
d5062d41de | ||
|
|
e9459bd68e | ||
|
|
ee460663c9 | ||
|
|
6f0e0146ef | ||
|
|
229f317025 | ||
|
|
48c0ae7227 | ||
|
|
9c7b5fcb10 | ||
|
|
191bdd4874 | ||
|
|
ae0a6b697e | ||
|
|
b6521fd721 | ||
|
|
62b0f4f0f5 | ||
|
|
fa9a032aad | ||
|
|
5241d9c21f | ||
|
|
31150c98e2 | ||
|
|
3317114780 | ||
|
|
8851bd68f8 | ||
|
|
9168ad88a6 | ||
|
|
03c0d46a2e | ||
|
|
8a8afc60ee | ||
|
|
5b68710b23 | ||
|
|
6cee0252ee | ||
|
|
aff63665de | ||
|
|
1ed1e0fc4c | ||
|
|
81ac102644 | ||
|
|
89b48168f4 | ||
|
|
195b7fa926 | ||
|
|
12919c7140 |
@@ -11,5 +11,5 @@ end_of_line = lf
|
||||
[*.py]
|
||||
max_line_length = 88
|
||||
|
||||
[*.{sh,yml,yaml,json,md}]
|
||||
[*.{sh,yml,yaml,json}]
|
||||
indent_size = 2
|
||||
31
.github/workflows/deploy-docs.yml
vendored
31
.github/workflows/deploy-docs.yml
vendored
@@ -1,31 +0,0 @@
|
||||
name: Deploy Documentation
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches:
|
||||
- docs
|
||||
permissions:
|
||||
contents: write
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Configure Git Credentials
|
||||
run: |
|
||||
git config user.name github-actions[bot]
|
||||
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
|
||||
- uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: 3.x
|
||||
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
|
||||
- uses: actions/cache@v4
|
||||
with:
|
||||
key: mkdocs-material-${{ env.cache_id }}
|
||||
path: .cache
|
||||
restore-keys: |
|
||||
mkdocs-material-
|
||||
- name: Install dependencies
|
||||
run: pip install -r requirements.txt
|
||||
- name: Build and deploy documentation
|
||||
run: mkdocs gh-deploy --force
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -10,3 +10,4 @@ __pycache__
|
||||
*.code-workspace
|
||||
*.iml
|
||||
kiauh.cfg
|
||||
klipper_repos.txt
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
source=scripts
|
||||
|
||||
enable=avoid-nullary-conditions
|
||||
enable=deprecate-which
|
||||
enable=quote-safe-variables
|
||||
enable=require-variable-braces
|
||||
enable=require-double-brackets
|
||||
|
||||
# SC2162: `read` without `-r` will mangle backslashes.
|
||||
# https://github.com/koalaman/shellcheck/wiki/SC2162
|
||||
disable=SC2162
|
||||
|
||||
# SC2164: Use `cd ... || exit` in case `cd` fails
|
||||
# https://github.com/koalaman/shellcheck/wiki/SC2164
|
||||
disable=SC2164
|
||||
@@ -1,6 +0,0 @@
|
||||
FROM squidfunk/mkdocs-material:latest
|
||||
|
||||
# Install additional plugins required by our mkdocs configuration
|
||||
RUN pip install \
|
||||
mkdocs-git-revision-date-localized-plugin \
|
||||
mkdocstrings[python]
|
||||
93
README.md
93
README.md
@@ -1,8 +1,6 @@
|
||||
<p align="center">
|
||||
<a>
|
||||
<img src="https://raw.githubusercontent.com/dw-0/kiauh/master/resources/screenshots/kiauh.png" alt="KIAUH logo" height="181">
|
||||
<img src="docs/assets/logo-large.png" alt="KIAUH Logo" height="181">
|
||||
<h1 align="center">Klipper Installation And Update Helper</h1>
|
||||
</a>
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
@@ -27,75 +25,100 @@
|
||||
</h2>
|
||||
|
||||
### 📋 Prerequisites
|
||||
KIAUH is a script that assists you in installing Klipper on a Linux operating system that has
|
||||
already been flashed to your Raspberry Pi's (or other SBC's) SD card. As a result, you must ensure
|
||||
that you have a functional Linux system on hand. `Raspberry Pi OS Lite (either 32bit or 64bit)` is a recommended Linux image
|
||||
if you are using a Raspberry Pi. The [official Raspberry Pi Imager](https://www.raspberrypi.com/software/)
|
||||
|
||||
KIAUH is a script that assists you in installing Klipper on a Linux operating
|
||||
system that has
|
||||
already been flashed to your Raspberry Pi's (or other SBC's) SD card. As a
|
||||
result, you must ensure
|
||||
that you have a functional Linux system on hand.
|
||||
`Raspberry Pi OS Lite (either 32bit or 64bit)` is a recommended Linux image
|
||||
if you are using a Raspberry Pi.
|
||||
The [official Raspberry Pi Imager](https://www.raspberrypi.com/software/)
|
||||
is the simplest way to flash an image like this to an SD card.
|
||||
|
||||
* Once you have downloaded, installed and launched the Raspberry Pi Imager,
|
||||
select `Choose OS -> Raspberry Pi OS (other)`: \
|
||||
select `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">
|
||||
<img src="docs/assets/rpi_imager1.png" alt="KIAUH logo" height="350">
|
||||
</p>
|
||||
|
||||
* Then select `Raspberry Pi OS Lite (32bit)` (or 64bit if you want to use that instead):
|
||||
* Then select `Raspberry Pi OS Lite (32bit)` (or 64bit if you want to use that
|
||||
instead):
|
||||
|
||||
<p align="center">
|
||||
<img src="https://raw.githubusercontent.com/dw-0/kiauh/master/resources/screenshots/rpi_imager2.png" alt="KIAUH logo" height="350">
|
||||
<img src="docs/assets/rpi_imager2.png" alt="KIAUH logo" height="350">
|
||||
</p>
|
||||
|
||||
* Back in the Raspberry Pi Imager's main menu, select the corresponding SD card to which
|
||||
you want to flash the image.
|
||||
* Back in the Raspberry Pi Imager's main menu, select the corresponding SD card
|
||||
to which
|
||||
you want to flash the image.
|
||||
|
||||
* Make sure to go into the Advanced Option (the cog icon in the lower left corner of the main menu)
|
||||
and enable SSH and configure Wi-Fi.
|
||||
* Make sure to go into the Advanced Option (the cog icon in the lower left
|
||||
corner of the main menu)
|
||||
and enable SSH and configure Wi-Fi.
|
||||
|
||||
* If you need more help for using the Raspberry Pi Imager, please visit the [official documentation](https://www.raspberrypi.com/documentation/computers/getting-started.html).
|
||||
* If you need more help for using the Raspberry Pi Imager, please visit
|
||||
the [official documentation](https://www.raspberrypi.com/documentation/computers/getting-started.html).
|
||||
|
||||
These steps **only** apply if you are actually using a Raspberry Pi. In case you want
|
||||
to use a different SBC (like an Orange Pi or any other Pi derivates), please look up on how to get an appropriate Linux image flashed
|
||||
to the SD card before proceeding further (usually done with Balena Etcher in those cases). Also make sure that KIAUH will be able to run
|
||||
and operate on the Linux Distribution you are going to flash. You likely will have the most success with
|
||||
distributions based on Debian 11 Bullseye. Read the notes further down below in this document.
|
||||
These steps **only** apply if you are actually using a Raspberry Pi. In case you
|
||||
want
|
||||
to use a different SBC (like an Orange Pi or any other Pi derivates), please
|
||||
look up on how to get an appropriate Linux image flashed
|
||||
to the SD card before proceeding further (usually done with Balena Etcher in
|
||||
those cases). Also make sure that KIAUH will be able to run
|
||||
and operate on the Linux Distribution you are going to flash. You likely will
|
||||
have the most success with
|
||||
distributions based on Debian 11 Bullseye. Read the notes further down below in
|
||||
this document.
|
||||
|
||||
### 💾 Download and use KIAUH
|
||||
|
||||
**📢 Disclaimer: Usage of this script happens at your own risk!**
|
||||
|
||||
* **Step 1:** \
|
||||
To download this script, it is necessary to have git installed. If you don't have git already installed, or if you are unsure, run the following command:
|
||||
To download this script, it is necessary to have git installed. If you don't
|
||||
have git already installed, or if you are unsure, run the following command:
|
||||
|
||||
```shell
|
||||
sudo apt-get update && sudo apt-get install git -y
|
||||
```
|
||||
|
||||
* **Step 2:** \
|
||||
Once git is installed, use the following command to download KIAUH into your home-directory:
|
||||
Once git is installed, use the following command to download KIAUH into your
|
||||
home-directory:
|
||||
|
||||
```shell
|
||||
cd ~ && git clone https://github.com/dw-0/kiauh.git
|
||||
```
|
||||
|
||||
* **Step 3:** \
|
||||
Finally, start KIAUH by running the next command:
|
||||
Finally, start KIAUH by running the next command:
|
||||
|
||||
```shell
|
||||
./kiauh/kiauh.sh
|
||||
```
|
||||
|
||||
* **Step 4:** \
|
||||
You should now find yourself in the main menu of KIAUH. You will see several actions to choose from depending
|
||||
on what you want to do. To choose an action, simply type the corresponding number into the "Perform action"
|
||||
prompt and confirm by hitting ENTER.
|
||||
You should now find yourself in the main menu of KIAUH. You will see several
|
||||
actions to choose from depending
|
||||
on what you want to do. To choose an action, simply type the corresponding
|
||||
number into the "Perform action"
|
||||
prompt and confirm by hitting ENTER.
|
||||
|
||||
<hr>
|
||||
|
||||
<h2 align="center">❗ Notes ❗</h2>
|
||||
|
||||
### **📋 Please see the [Changelog](docs/changelog.md) for possible important changes!**
|
||||
### **📋 Please see the [Changelog](docs/changelog.md) for possible important
|
||||
|
||||
changes!**
|
||||
|
||||
- Mainly tested on Raspberry Pi OS Lite (Debian 10 Buster / Debian 11 Bullseye)
|
||||
- Other Debian based distributions (like Ubuntu 20 to 22) likely work too
|
||||
- Reported to work on Armbian as well but not tested in detail
|
||||
- During the use of this script you will be asked for your sudo password. There are several functions involved which need sudo privileges.
|
||||
- During the use of this script you will be asked for your sudo password. There
|
||||
are several functions involved which need sudo privileges.
|
||||
|
||||
<hr>
|
||||
|
||||
@@ -200,13 +223,17 @@ prompt and confirm by hitting ENTER.
|
||||
|
||||
<h2 align="center">✨ Credits ✨</h2>
|
||||
|
||||
* A big thank you to [lixxbox](https://github.com/lixxbox) for that awesome KIAUH-Logo!
|
||||
* Also, a big thank you to everyone who supported my work with a [Ko-fi](https://ko-fi.com/dw__0) !
|
||||
* Last but not least: Thank you to all contributors and members of the Klipper Community who like and share this project!
|
||||
* A big thank you to [lixxbox](https://github.com/lixxbox) for that awesome
|
||||
KIAUH-Logo!
|
||||
* Also, a big thank you to everyone who supported my work with
|
||||
a [Ko-fi](https://ko-fi.com/dw__0) !
|
||||
* Last but not least: Thank you to all contributors and members of the Klipper
|
||||
Community who like and share this project!
|
||||
|
||||
<hr>
|
||||
|
||||
<h4 align="center">A special thank you to JetBrains for sponsoring this project with their incredible software!</h4>
|
||||
<h4 align="center">A special thank you to JetBrains for sponsoring this project
|
||||
with their incredible software!</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">
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
services:
|
||||
mkdocs:
|
||||
build: .
|
||||
ports:
|
||||
- "8000:8000"
|
||||
volumes:
|
||||
- ./:/docs
|
||||
command: serve --dev-addr=0.0.0.0:8000
|
||||
549
docs/changelog.md
Normal file
549
docs/changelog.md
Normal file
@@ -0,0 +1,549 @@
|
||||
## Changelog
|
||||
|
||||
This document covers possible important changes to KIAUH.
|
||||
|
||||
### 2025-10-10 (v6.0.0)
|
||||
|
||||
KIAUH has now reached version 6! The majority of the changes mentioned in the
|
||||
previous changelog are now available in the final version.
|
||||
Most notible are the following changes:
|
||||
|
||||
- The dialog for selecting between v5 and v6 is gone and all v5 code was
|
||||
removed. V6 is the new default
|
||||
- You can add/remove alternative repositories for Klipper and Moonraker from
|
||||
within KIAUH, no need to manually edit any file
|
||||
- You can store and load firmware configurations for Klipper during the firmware
|
||||
compilation process
|
||||
- Spoolman is available as an extension, it does not use the bare-metal
|
||||
installation anymore, instead it uses the Docker Container approach
|
||||
- OctoApp is available as an extension
|
||||
- OctoPrint support was NOT killed. OctoPrint is available as an extension
|
||||
- I probably forgot to mention some other changes, but the idea is to create
|
||||
official docs for KIAUH where the new changelog will live in the future and
|
||||
available features and mechanics are explained in detail
|
||||
|
||||
If you really want to use v5, there is a v5 branch available in the repository.
|
||||
Keep in mind that v5 will not be updated anymore.
|
||||
|
||||
### 2024-08-31 (v6.0.0-alpha.1)
|
||||
|
||||
Long time no see, but here we are again!
|
||||
A lot has happened in the background, but now it is time to take it out into the
|
||||
wild.
|
||||
|
||||
#### KIAUH has now reached version 6! Well, at least in an alpha state...
|
||||
|
||||
The project has seen a complete rewrite of the script from scratch in Python.
|
||||
It requires Python 3.8 or newer to run. Because this update is still in an alpha
|
||||
state, bugs may or will occur.
|
||||
During startup, you will be asked if you want to start the new version 6 or the
|
||||
old version 5.
|
||||
As long as version 6 is in a pre-release state, version 5 will still be
|
||||
available. If there are any critical issues
|
||||
with the new version that were overlooked, you can always switch back to the old
|
||||
version.
|
||||
|
||||
In case you selected not to get asked about which version to start (option 3 or
|
||||
4 in the startup dialog) and you want to
|
||||
revert that decision, you will find a line called `version_to_launch=` within
|
||||
the `.kiauh.ini` file in your home directory.
|
||||
Just delete that line, save the file and restart KIAUH. KIAUH will then ask you
|
||||
again which version you want to start.
|
||||
|
||||
Here is a list of the most important changes to KIAUH in regard to version 6:
|
||||
|
||||
- The majority of features available in KIAUH v5 are still available; they just
|
||||
got migrated from Bash to Python.
|
||||
- It is now possible to add new/remove instances to/from existing multi-instance
|
||||
installations of Klipper and Moonraker
|
||||
- KIAUH now has an Extension-System. This allows contributors to add new
|
||||
installers to KIAUH without having to modify the main script.
|
||||
- You will now find some of the features that were previously available in
|
||||
the Installer-Menu in the Extensions-Menu.
|
||||
- The current extensions are:
|
||||
- G-Code Shell Command (previously found in the Advanced-Menu)
|
||||
- Mainsail Theme Installer (previously found in the Advanced-Menu)
|
||||
- Klipper-Backup (new in v6!)
|
||||
- Moonraker Telegram Bot (previously found in the Installer-Menu)
|
||||
- PrettyGCode for Klipper (previously found in the Installer-Menu)
|
||||
- Obico for Klipper (previously found in the Installer-Menu)
|
||||
- The following additional extensions are planned, but not yet available:
|
||||
- Spoolman (available in v5 in the Installer-Menu)
|
||||
- OctoApp (available in v5 in the Installer-Menu)
|
||||
- KIAUH has its own config file now
|
||||
- The file has some default values for the currently supported options
|
||||
- There might be more options in the future
|
||||
- It is located in KIAUH's root directory and is called `default.kiauh.cfg`
|
||||
- DO NOT EDIT the default file directly, instead make a copy of it and
|
||||
call it `kiauh.cfg`
|
||||
- Settings changed via the Advanced-Menu will be written to the
|
||||
`kiauh.cfg`
|
||||
- Support for OctoPrint was removed
|
||||
|
||||
Feel free to give version 6 a try and report any bugs or issues you encounter!
|
||||
Every feedback is appreciated.
|
||||
|
||||
### 2023-06-17
|
||||
|
||||
KIAUH has now added support for installing Mobileraker's companion!
|
||||
Mobileraker is a free and Open Source Android and iOS App for Klipper, utilizing
|
||||
the Moonraker API, allowing you
|
||||
to control your printer. Thank you to [Clon1998](https://github.com/Clon1998)
|
||||
for adding this feature!
|
||||
|
||||
### 2023-02-03
|
||||
|
||||
The installer for MJPG-Streamer got replaced by crowsnest. It is an improved
|
||||
webcam service, utilizing ustreamer.
|
||||
Please have a look here for additional info about crowsnest and how to configure
|
||||
it: https://github.com/mainsail-crew/crowsnest \
|
||||
It's unsure if the previous MJPG-Streamer installer will be updated and make its
|
||||
way back into KIAUH.
|
||||
A big thanks to [KwadFan](https://github.com/KwadFan) for writing the crowsnest
|
||||
implementation.
|
||||
|
||||
### 2022-10-31
|
||||
|
||||
Some functions got updated, though not all of them.
|
||||
|
||||
The following functions are still currently unavailable:
|
||||
|
||||
- Installation of: MJPG-Streamer
|
||||
- All backup functions and the Log-Upload
|
||||
|
||||
### 2022-10-20
|
||||
|
||||
KIAUH has now reached major version 5 !
|
||||
|
||||
Recently Moonraker introduced some changes which makes it necessary to change
|
||||
the folder structure of printer setups.
|
||||
If you are interested in the details, check out this
|
||||
PR: https://github.com/Arksine/moonraker/pull/491 \
|
||||
Although Moonraker has some mechanics available to migrate existing setups to
|
||||
the new file structure with the use of symlinks, fresh and clean installs
|
||||
should be considered.
|
||||
|
||||
The version jump of KIAUH to v5 is a breaking change due to those major changes!
|
||||
That means v4 and v5 are not compatible with each other!
|
||||
This is also the reason why you will currently be greeted by a yellow
|
||||
notification in the main menu of KIAUH leading to this changelog.
|
||||
I decided to disable a few functions of the script and focus on releasing the
|
||||
required changes to the core components of this script.
|
||||
I will work on updating the other parts of the script piece by piece during the
|
||||
next days/weeks.
|
||||
So I am already sorry in advance if one of your desired components you wanted to
|
||||
install or use temporarily cannot be installed or used right now.
|
||||
|
||||
The following functions are currently unavailable:
|
||||
|
||||
- Installation of: KlipperScreen, Obico, Octoprint, MJPG-Streamer, Telegram Bot
|
||||
and PrettyGCode
|
||||
- All backup functions and the Log-Upload
|
||||
|
||||
**So what is working?**\
|
||||
Installation of Klipper, Moonraker, Mainsail and Fluidd. Both, single and
|
||||
multi-instance setups work!\
|
||||
As already said, the rest will follow in the near future. Updating and removal
|
||||
of already installed components should continue to work.
|
||||
|
||||
**What was removed?**\
|
||||
The option to change Klippers configuration directory got removed. From now on
|
||||
it will not be possible anymore to change
|
||||
the configuration directory from within KIAUH and the new filestructure is
|
||||
enforced.
|
||||
|
||||
**What if I don't have an existing Klipper/Moonraker install right now?**\
|
||||
Nothing important to think about, install Klipper and Moonraker. KIAUH will
|
||||
install both of them with the new filestructure.
|
||||
|
||||
**What if I have an existing Klipper/Moonraker install?**\
|
||||
First of all: Backups! Please copy all of your config files and the Moonraker
|
||||
database (it is a hidden folder, usually `~/.moonraker_database`) to a safe
|
||||
location.
|
||||
After that, uninstall Klipper and Moonraker with KIAUH. You can then proceed and
|
||||
re-install both of them with KIAUH again. It is important that you are on KIAUH
|
||||
v5 for that!
|
||||
Once everything is installed again, you need to manually copy your configuration
|
||||
files from the old `~/klipper_config` folder to the new `~/printer_data/config`
|
||||
folder.
|
||||
Previous, by Moonraker created symlinks to folder of the old filestructure will
|
||||
not work anymore, you need to move the files to their new location now!
|
||||
Do the same with the two files inside of `~/.moonraker_database`. Move/copy them
|
||||
into `~/printer_data/database`. If `~/printer_data/database` is already
|
||||
populated with a `data.mdb` and `lock.mdb`
|
||||
delete them or simply overwrite them. Nothing should be lost as those should be
|
||||
empty database files. Anyway, you made backups, right?
|
||||
You can now proceed and restart Moonraker. Either from within Mainsail or
|
||||
Fluidd, or use SSH and execute `sudo systemctl restart moonraker`.
|
||||
If everything went smooth, you should be good to go again. If you see some
|
||||
Moonraker warnings about deprecated options in the `moonraker.conf`, go ahead
|
||||
and resolve them.
|
||||
I will not cover them in detail here. A good source is the Moonraker
|
||||
documentation: https://moonraker.readthedocs.io/en/latest/configuration/
|
||||
|
||||
**What if I have an existing Klipper/Moonraker multi-instance install?**\
|
||||
Pretty much the same steps that are required for single instance installs apply
|
||||
to multi-instance setups. So please go ahead and read the previous paragraph if
|
||||
you didn't already.
|
||||
Make backups of everything first. Then remove and install the desired amount of
|
||||
Klipper and Moonraker instances again.
|
||||
Now you need to move all config and database files to their new locations.\
|
||||
Example with an instance called `printer_1`:\
|
||||
The config files go from `~/klipper_config/printer_1` to
|
||||
`~/printer_1_data/config`.
|
||||
The database files go from `~/.moonraker_database_1` to
|
||||
`~/printer_1_data/database`.
|
||||
Now restart all Moonraker services. You can restart all of them at once if you
|
||||
launch KIAUH, and in the main menu type `restart moonraker` and hit Enter.
|
||||
|
||||
I hope I have covered the most important things. In case you need further
|
||||
support, the official Klipper Discord is a good place to ask for help.
|
||||
|
||||
### 2022-08-15
|
||||
|
||||
Support for "Obico for Klipper" was added! Huge thanks
|
||||
to [kennethjiang](https://github.com/kennethjiang) for helping me with the
|
||||
implementation!
|
||||
|
||||
### 2022-05-29
|
||||
|
||||
KIAUH has now reached major version 4 !
|
||||
|
||||
* feat: Klipper can be installed under Python3 (still considered as
|
||||
experimental)
|
||||
* feat: Klipper can be installed from custom repositories / inofficial forks
|
||||
* feat: Custom instance name for multi instance installations of Klipper
|
||||
* Any other multi instance will share the same name given to the
|
||||
corresponding Klipper instance
|
||||
* E.g. klipper-voron2 -> moonraker-voron2 -> moonraker-telegram-bot-voron2
|
||||
* feat: Option to allow installation of / updating to unstable Mainsail and
|
||||
Fluidd versions
|
||||
* by default only stable versions get installed/updated
|
||||
* feat: Multi-Instance OctoPrint installations now each have their own virtual
|
||||
python environment
|
||||
* allows independent installation of plugins for each instance
|
||||
* feat: Implementing the use of shellcheck during development
|
||||
* feat: Implementing a simple logging mechanic
|
||||
* feat: Log-upload function now also allows uploading other logfiles (kiauh.log,
|
||||
webcamd.log etc.)
|
||||
* feat: added several new help dialogs which try to explain various functions
|
||||
* fix: During Klipper installation, checks for group membership of `tty` and
|
||||
`dialout` are made
|
||||
* refactor: rework of the settings menu for better control the new KIAUH
|
||||
features
|
||||
* refactor: Support for DWC and DWC-for-Klipper has been removed
|
||||
* refactor: The backup before update settings were moved to the KIAUH settings
|
||||
menu
|
||||
* refactor: Switch branch function has been removed (was replaced by the custom
|
||||
Klipper repo feature)
|
||||
* refactor: The update manager sections for Mainsail, Fluidd and KlipperScreen
|
||||
were removed from the moonraker.conf template
|
||||
* They will now be individually added during installation of the
|
||||
corresponding interface
|
||||
* refactor: The rollback function was reworked and now also allows rollbacks of
|
||||
Moonraker
|
||||
* It now takes numerical inputs and reverts the corresponding repository by
|
||||
the given amount instead
|
||||
* KIAUH does not save previous states to its config anymore like it did with
|
||||
the previous approach
|
||||
|
||||
### 2022-01-29
|
||||
|
||||
* Starting from the 28th of January, Moonraker can make use of PackageKit and
|
||||
PolicyKit.\
|
||||
More details on that can be found [here](
|
||||
https://github.com/Arksine/moonraker/issues/349)
|
||||
and [here](https://github.com/Arksine/moonraker/pull/346)
|
||||
* KIAUH will install Moonrakers PolicyKit rules by default when __installing__
|
||||
Moonraker
|
||||
* KIAUH will also install Moonrakers PolicyKit rules when __updating__ Moonraker
|
||||
__via KIAUH__ as of now
|
||||
|
||||
### 2021-12-30
|
||||
|
||||
* Updated the doc for the usage of
|
||||
the [G-Code Shell Command Extension](docs/gcode_shell_command.md)
|
||||
* It became apparent, that some user groups are missing on some systems. A
|
||||
missing video group \
|
||||
membership for example caused issues when installing mjpg-streamer while not
|
||||
using the default pi user. \
|
||||
Other issues could occur when trying to flash an MCU on Debian or Ubuntu
|
||||
distributions where a user might not be part
|
||||
of the dialout group by default. A check for the tty group is also done. The
|
||||
tty group is needed for setting
|
||||
up a linux MCU (currently not yet supported by KIAUH).
|
||||
* There is an issue when trying to install Mainsail or Fluidd on Ubuntu 21.10.
|
||||
Permissions on that distro seem to have seen a rework
|
||||
in comparison to 20.04 and users will be greeted with an "Error 403 -
|
||||
Permission denied" message after installing one of Klippers webinterfaces.
|
||||
I still have to figure out a viable solution for that.
|
||||
|
||||
### 2021-09-28
|
||||
|
||||
* New Feature! Added an installer for the Telegram Bot for Moonraker
|
||||
by [nlef](https://github.com/nlef).
|
||||
Checkout his project! Remember to report all issues and/or bugs regarding that
|
||||
project in its corresponding repo and not here 😛.\
|
||||
You can find it here: https://github.com/nlef/moonraker-telegram-bot
|
||||
|
||||
### 2021-09-24
|
||||
|
||||
* The flashing function got adjusted a bit. It is now possible to also flash
|
||||
controllers which are connected over UART and thus accessible via
|
||||
`/dev/ttyAMA0`. You now have to select a connection methop prior flashing
|
||||
which is either USB or UART.
|
||||
* Due to several requests over time I have now created a Ko-fi account for those
|
||||
who want to support this project and my work with a small donation. Many
|
||||
thanks in advance to all future donors. You can support me on Ko-fi with this
|
||||
link: https://ko-fi.com/th33xitus
|
||||
* As usual, if you find any bugs or issues please report them. I tested the
|
||||
little rework i did with the hardware i have available and haven't encountered
|
||||
any malfunctions of flashing them yet.
|
||||
|
||||
### 2021-08-10
|
||||
|
||||
* KIAUH now supports the installation of the "PrettyGCode for Klipper"
|
||||
GCode-Viewer created by [Kragrathea](https://github.com/Kragrathea)!
|
||||
Installation, updating and removal are possible with KIAUH. For more details
|
||||
to this cool piece of software, please have a look
|
||||
here: https://github.com/Kragrathea/pgcode
|
||||
|
||||
### 2021-07-10
|
||||
|
||||
* The NGINX configuration files got updated to be in sync with MainsailOS and
|
||||
FluiddPi. Issues with the NGINX service not starting up due to wrong
|
||||
configuration should be resolved now. To get the updated configuration files,
|
||||
please remove Moonraker and Mainsail / Fluidd with KIAUH first and then
|
||||
re-install it. An automated file check for those configuration files might
|
||||
follow in the future which then automates updating those files if there were
|
||||
important changes.
|
||||
|
||||
* The default `moonraker.conf` was updated to reflect the recent changes to the
|
||||
update manager section. The update channel is set to `dev`.
|
||||
|
||||
### 2021-06-29
|
||||
|
||||
* KIAUH will now patch the new `log_path` to existing moonraker.conf files when
|
||||
updating Moonraker and the entry is missing. Before that, it was necessary
|
||||
that the user provided that path manually to make Fluidd display the logfiles
|
||||
in its interface. This issue should be resolved now.
|
||||
|
||||
### 2021-06-15
|
||||
|
||||
* Moonraker introduced an optional `log_path` which clients can make use of to
|
||||
show log files located in that folder to their users. More info
|
||||
here: https://github.com/Arksine/moonraker/commit/829b3a4ee80579af35dd64a37ccc092a1f67682a \
|
||||
Client developers agreed upon using `~/klipper_logs` as the new default log
|
||||
path.\
|
||||
That means, from now on, Klipper and Moonraker services installed with KIAUH
|
||||
will place their logfiles in that mentioned folder.
|
||||
* Additionally, KIAUH will now detect Klipper and Moonraker systemd services
|
||||
that still use the old default location of `/tmp/<service>.log` and will
|
||||
update them next time the user updates Klipper and/or Moonraker with the KIAUH
|
||||
update function.
|
||||
* Additional symlinks for the following logfiles will get created along those
|
||||
update procedures to make them accessible through the webinterface once its
|
||||
supported:
|
||||
- webcamd.log
|
||||
- mainsail-access.log
|
||||
- mainsail-error.log
|
||||
- fluidd-access.log
|
||||
- fluidd-error.log
|
||||
* For MainsailOS and FluiddPi users:\
|
||||
MainsailOS and FluiddPi will switch the shipped Klipper service from SysVinit
|
||||
to systemd probably with their next release. KIAUH can already help migrate
|
||||
older MainsailOS (0.4.0 and below) and FluiddPi (v1.13.0) releases to match
|
||||
their new service-, file- and folder-structure so you don't have to re-flash
|
||||
the SD-Card of your Raspberry Pi.\
|
||||
In detail here is what is going to happen when you use the new "CustomPiOS
|
||||
Migration Helper" from the Advanced Menu\
|
||||
`(Main Menu -> 4 -> Enter -> 10 -> Enter)` in a short summary:
|
||||
* The Klipper SysVinit service will get replaced by a Klipper systemd
|
||||
service
|
||||
* Klipper and Moonraker will use the new log-directory `~/klipper_logs`
|
||||
* The webcamd service gets updated
|
||||
* The webcamd script gets updated and moved from `/root/bin/webcamd` to
|
||||
`/usr/local/bin/webcamd`
|
||||
* The NGINX `upstreams.conf` gets updated to be able to configure up to 4
|
||||
webcams
|
||||
* The `mainsail.txt` / `fluiddpi.txt` gets moved from `/boot` to
|
||||
`~/klipper_config` and renamed to `webcam.txt`
|
||||
* Symlinks for the webcamd.log and various NGINX logs get created in
|
||||
`~/klipper_config`
|
||||
* Configuration files for Klipper, Moonraker and webcamd get added to
|
||||
`/etc/logrotate.d`
|
||||
* If they still exist, two lines will be removed from the mainsail.cfg or
|
||||
client_macros.cfg macro configurations:\
|
||||
`SAVE_GCODE_STATE NAME=PAUSE_state` and
|
||||
`RESTORE_GCODE_STATE NAME=PAUSE_state`
|
||||
* **Please note:**\
|
||||
The "CustomPiOS Migration Helper" is intended to only work on "vanilla"
|
||||
MainsailOS and FluiddPi systems. Do not try to migrate a modified MainsailOS
|
||||
or FluiddPi system (for example if you already used KIAUH to re-install
|
||||
services or to set up a multi-instance installation for Klipper / Moonraker).
|
||||
This won't work.
|
||||
|
||||
### 2021-01-31
|
||||
|
||||
* **This is a big one... KIAUH v3.0 is out.**\
|
||||
With this update you can now install multiple instances of Klipper, Moonraker,
|
||||
Duet Web Control or Octoprint on the same Pi. This was quite a big rework of
|
||||
the whole script. So bugs can appear but with the help of some testers, i
|
||||
think there shouldn't be any critical ones anymore. In this regards thanks to
|
||||
@lixxbox and @zellneralex for testing.
|
||||
|
||||
* Important changes to how installations are set up now: All components get
|
||||
installed as systemd services. Installation via init.d was dropped completely!
|
||||
This shouldn't affect you at all, since the common linux distributions like
|
||||
RaspberryPi OS or custom distributions like MainsailOS, FluiddPi or OctoPi
|
||||
support both ways of installing services. I just wanted to mention it here.
|
||||
|
||||
* Now with KIAUH v3.0 and multi-instance installation capabilities, there are
|
||||
some things to point out. You will now need to tell KIAUH where your printers
|
||||
configurations are located when installing Klipper for the first time. Even
|
||||
though it is not recommended, you can change this location with the help of
|
||||
KIAUH and rewrite Klipper and Moonraker to use the new location.
|
||||
|
||||
* When setting up a multi-instance system, the folder structure will only change
|
||||
slightly. The goal was to keep it as compatible as possible with the custom
|
||||
distributions like mainsailOS and FluiddPi. This should help converting a
|
||||
single-instance setup of mainsailOS/FluiddPi to a multi-instance setup in no
|
||||
time, but keeping single-instance backwards compatibility if needed at a later
|
||||
point in time.
|
||||
|
||||
* The folder structure is as follows when setting up multi-instances:\
|
||||
Each printer instance will get its own folder within your configuration
|
||||
location. The decision to this specific structure was made to make it as
|
||||
painless and easy as possible to convert to a multi-instance setup.
|
||||
Here is an example:
|
||||
```shell
|
||||
/home/<username>
|
||||
└── klipper_config
|
||||
├── printer_1
|
||||
│ ├── printer.cfg
|
||||
│ └── moonraker.conf
|
||||
├── printer_2
|
||||
│ ├── printer.cfg
|
||||
│ └── moonraker.conf
|
||||
└── printer_n
|
||||
├── printer.cfg
|
||||
└── moonraker.conf
|
||||
```
|
||||
* Also when setting up multi-instances of each service, the name of each service
|
||||
slightly changes.
|
||||
Each service gets its corresponding instance added to the service filename.
|
||||
|
||||
**This only applies to multi-instances! Single instance installations with
|
||||
KIAUH will keep their original names!**
|
||||
|
||||
Corresponding to the filetree example from above that would mean:
|
||||
```
|
||||
Klipper services:
|
||||
--> klipper-1.service
|
||||
--> klipper-2.service
|
||||
--> klipper-n.service
|
||||
|
||||
Moonraker services:
|
||||
--> moonraker-1.service
|
||||
--> moonraker-2.service
|
||||
--> moonraker-n.service
|
||||
```
|
||||
* The same service file rules from above apply to OctoPrint even though only
|
||||
Klipper and Moonraker are shown in this example.
|
||||
|
||||
* You can start, stop and restart all Klipper, Moonraker and OctoPrint instances
|
||||
from the KIAUH main menu. For doing this, just type "stop klipper", "start
|
||||
moonraker", "restart octoprint" and so on.
|
||||
|
||||
* KIAUH v3.0 relocated its ini-file. It is now a hidden file in the users
|
||||
home-directory calles `.kiauh.ini`. This has the benefit of keeping all values
|
||||
in that file between possible re-installations of KIAUH. Otherwise that file
|
||||
would be lost.
|
||||
|
||||
* The option of adding more trusted clients to the moonraker.conf file was
|
||||
dropped. Since you can edit this file right inside of Mainsail or Fluidd, only
|
||||
some basic entries are made which get you running.
|
||||
|
||||
* I bet i have missed mentioning other stuff as well because it took me quite
|
||||
some time to re-write many functions. So i just hope you like the new version
|
||||
😄
|
||||
|
||||
### 2020-11-28
|
||||
|
||||
* KIAUH now supports the installation, update and removal
|
||||
of [KlipperScreen](https://github.com/jordanruthe/KlipperScreen). This feature
|
||||
was was provided by [jordanruthe](https://github.com/jordanruthe)! Thank you!
|
||||
|
||||
### 2020-11-18
|
||||
|
||||
* Some changes to Fluidd caused a little rework on how KIAUH will install/update
|
||||
Fluidd from now on. Please see
|
||||
the [fluidd v1.0.0-rc0 release notes](https://github.com/cadriel/fluidd/releases/tag/v1.0.0-rc.0)
|
||||
for further information about what modifications to the moonraker.conf file
|
||||
exactly had to be done. In a nutshell, KIAUH will now always patch the
|
||||
required entries to the moonraker.conf if not already there.
|
||||
|
||||
### 2020-10-30:
|
||||
|
||||
* The user can now choose to install Klipper as a systemd service.
|
||||
|
||||
* The Shell Command extension and `shell_command.py` got renamed to G-Code Shell
|
||||
Command extension and `gcode_shell_command.py`. In case
|
||||
the [pending PR](https://github.com/KevinOConnor/klipper/pull/2173) will be
|
||||
merged in the future, this was an early attempt to dodge possible
|
||||
incompatibilities. The [G-Code Shell Command docs](gcode_shell_command.md) has
|
||||
been updated accordingly.
|
||||
|
||||
* The way how KIAUH interacts and writes to the users printer.cfg got changed.
|
||||
Usually KIAUH wrote everything directly into the printer.cfg. The way it will
|
||||
work from now on is, that a new file called `kiauh.cfg` will be created if
|
||||
there is something that needs to be written to the printer.cfg and everything
|
||||
gets written to `kiauh.cfg` instead. The only thing which then gets written to
|
||||
the users printer.cfg is `[include kiauh.cfg]`. This line will be located at
|
||||
the very top of the existing printer.cfg with a little comment as a note. The
|
||||
user can then decide to either keep the `kiauh.cfg` or take its content,
|
||||
places it into the printer.cfg directly and remove the `[include kiauh.cfg]`.
|
||||
|
||||
* The `mainsail_macros.cfg` got renamed to `webui_macros.cfg`. Since Mainsail
|
||||
and Fluidd both use the same kind of pause, cancel and resume macros, a more
|
||||
generic name was chosen for the file containing the example macros one can
|
||||
choose to install when installing those webinterfaces.
|
||||
|
||||
### 2020-10-10:
|
||||
|
||||
* Support for changing the Klipper branch to the moonraker-dev branch from
|
||||
@Arksine has been dropped. Support for Moonraker has been merged into Klipper
|
||||
mainline a long time ago.
|
||||
|
||||
* A new function is available from the main menu. You can now upload your log
|
||||
files to http://paste.c-net.org/ to share them for debugging purposes.
|
||||
|
||||
### 2020-10-06:
|
||||
|
||||
* Fluidd, a new Klipper interface got added to the list of available installers.
|
||||
At the same time some installation routines have changed or have seen some
|
||||
rework. Changes were made to the installation of NGINX configurations. A
|
||||
method was introduced to change the listen port of a webinterface
|
||||
configuration if there is already another webinterface listening on the
|
||||
default port (80).
|
||||
|
||||
* At the moment, the Moonraker installer no longer asks you whether you want to
|
||||
install a web interface too. For now you therefore have to install them with
|
||||
their respective installers. Please report any bugs or issues you encounter.
|
||||
|
||||
### 2020-09-17:
|
||||
|
||||
* The dev-2.0 branch will be abandoned as of today. If you did a checkout to
|
||||
that branch in the past, you have to checkout back to master to receive
|
||||
updates.
|
||||
|
||||
### 2020-09-12:
|
||||
|
||||
* The old [dwc2-for-klipper](https://github.com/Stephan3/dwc2-for-klipper) won't
|
||||
be supported anymore!\
|
||||
The is a new, fully rewritten project
|
||||
available: [dwc2-for-klipper-socket](https://github.com/Stephan3/dwc2-for-klipper-socket).\
|
||||
The installer of this script also got rewritten to make use of that new
|
||||
project. You will not be able to install or remove the
|
||||
old [dwc2-for-klipper](https://github.com/Stephan3/dwc2-for-klipper) with
|
||||
KIAUH anymore if you updated KIAUH to the newest version.
|
||||
@@ -1,305 +0,0 @@
|
||||
## Changelog
|
||||
|
||||
This document covers possible important changes to KIAUH.
|
||||
|
||||
### 2024-08-31 (v6.0.0-alpha.1)
|
||||
Long time no see, but here we are again!
|
||||
A lot has happened in the background, but now it is time to take it out into the wild.
|
||||
|
||||
#### KIAUH has now reached version 6! Well, at least in an alpha state...
|
||||
|
||||
The project has seen a complete rewrite of the script from scratch in Python.
|
||||
It requires Python 3.8 or newer to run. Because this update is still in an alpha state, bugs may or will occur.
|
||||
During startup, you will be asked if you want to start the new version 6 or the old version 5.
|
||||
As long as version 6 is in a pre-release state, version 5 will still be available. If there are any critical issues
|
||||
with the new version that were overlooked, you can always switch back to the old version.
|
||||
|
||||
In case you selected not to get asked about which version to start (option 3 or 4 in the startup dialog) and you want to
|
||||
revert that decision, you will find a line called `version_to_launch=` within the `.kiauh.ini` file in your home directory.
|
||||
Just delete that line, save the file and restart KIAUH. KIAUH will then ask you again which version you want to start.
|
||||
|
||||
Here is a list of the most important changes to KIAUH in regard to version 6:
|
||||
- The majority of features available in KIAUH v5 are still available; they just got migrated from Bash to Python.
|
||||
- It is now possible to add new/remove instances to/from existing multi-instance installations of Klipper and Moonraker
|
||||
- KIAUH now has an Extension-System. This allows contributors to add new installers to KIAUH without having to modify the main script.
|
||||
- You will now find some of the features that were previously available in the Installer-Menu in the Extensions-Menu.
|
||||
- The current extensions are:
|
||||
- G-Code Shell Command (previously found in the Advanced-Menu)
|
||||
- Mainsail Theme Installer (previously found in the Advanced-Menu)
|
||||
- Klipper-Backup (new in v6!)
|
||||
- Moonraker Telegram Bot (previously found in the Installer-Menu)
|
||||
- PrettyGCode for Klipper (previously found in the Installer-Menu)
|
||||
- Obico for Klipper (previously found in the Installer-Menu)
|
||||
- The following additional extensions are planned, but not yet available:
|
||||
- Spoolman (available in v5 in the Installer-Menu)
|
||||
- OctoApp (available in v5 in the Installer-Menu)
|
||||
- KIAUH has its own config file now
|
||||
- The file has some default values for the currently supported options
|
||||
- There might be more options in the future
|
||||
- It is located in KIAUH's root directory and is called `default.kiauh.cfg`
|
||||
- DO NOT EDIT the default file directly, instead make a copy of it and call it `kiauh.cfg`
|
||||
- Settings changed via the Advanced-Menu will be written to the `kiauh.cfg`
|
||||
- Support for OctoPrint was removed
|
||||
|
||||
Feel free to give version 6 a try and report any bugs or issues you encounter! Every feedback is appreciated.
|
||||
|
||||
### 2023-06-17
|
||||
KIAUH has now added support for installing Mobileraker's companion!
|
||||
Mobileraker is a free and Open Source Android and iOS App for Klipper, utilizing the Moonraker API, allowing you
|
||||
to control your printer. Thank you to [Clon1998](https://github.com/Clon1998) for adding this feature!
|
||||
|
||||
### 2023-02-03
|
||||
The installer for MJPG-Streamer got replaced by crowsnest. It is an improved webcam service, utilizing ustreamer.
|
||||
Please have a look here for additional info about crowsnest and how to configure it: https://github.com/mainsail-crew/crowsnest \
|
||||
It's unsure if the previous MJPG-Streamer installer will be updated and make its way back into KIAUH.
|
||||
A big thanks to [KwadFan](https://github.com/KwadFan) for writing the crowsnest implementation.
|
||||
|
||||
### 2022-10-31
|
||||
Some functions got updated, though not all of them.
|
||||
|
||||
The following functions are still currently unavailable:
|
||||
- Installation of: MJPG-Streamer
|
||||
- All backup functions and the Log-Upload
|
||||
|
||||
### 2022-10-20
|
||||
KIAUH has now reached major version 5 !
|
||||
|
||||
Recently Moonraker introduced some changes which makes it necessary to change the folder structure of printer setups.
|
||||
If you are interested in the details, check out this PR: https://github.com/Arksine/moonraker/pull/491 \
|
||||
Although Moonraker has some mechanics available to migrate existing setups to the new file structure with the use of symlinks, fresh and clean installs
|
||||
should be considered.
|
||||
|
||||
The version jump of KIAUH to v5 is a breaking change due to those major changes! That means v4 and v5 are not compatible with each other!
|
||||
This is also the reason why you will currently be greeted by a yellow notification in the main menu of KIAUH leading to this changelog.
|
||||
I decided to disable a few functions of the script and focus on releasing the required changes to the core components of this script.
|
||||
I will work on updating the other parts of the script piece by piece during the next days/weeks.
|
||||
So I am already sorry in advance if one of your desired components you wanted to install or use temporarily cannot be installed or used right now.
|
||||
|
||||
The following functions are currently unavailable:
|
||||
- Installation of: KlipperScreen, Obico, Octoprint, MJPG-Streamer, Telegram Bot and PrettyGCode
|
||||
- All backup functions and the Log-Upload
|
||||
|
||||
**So what is working?**\
|
||||
Installation of Klipper, Moonraker, Mainsail and Fluidd. Both, single and multi-instance setups work!\
|
||||
As already said, the rest will follow in the near future. Updating and removal of already installed components should continue to work.
|
||||
|
||||
**What was removed?**\
|
||||
The option to change Klippers configuration directory got removed. From now on it will not be possible anymore to change
|
||||
the configuration directory from within KIAUH and the new filestructure is enforced.
|
||||
|
||||
**What if I don't have an existing Klipper/Moonraker install right now?**\
|
||||
Nothing important to think about, install Klipper and Moonraker. KIAUH will install both of them with the new filestructure.
|
||||
|
||||
**What if I have an existing Klipper/Moonraker install?**\
|
||||
First of all: Backups! Please copy all of your config files and the Moonraker database (it is a hidden folder, usually `~/.moonraker_database`) to a safe location.
|
||||
After that, uninstall Klipper and Moonraker with KIAUH. You can then proceed and re-install both of them with KIAUH again. It is important that you are on KIAUH v5 for that!
|
||||
Once everything is installed again, you need to manually copy your configuration files from the old `~/klipper_config` folder to the new `~/printer_data/config` folder.
|
||||
Previous, by Moonraker created symlinks to folder of the old filestructure will not work anymore, you need to move the files to their new location now!
|
||||
Do the same with the two files inside of `~/.moonraker_database`. Move/copy them into `~/printer_data/database`. If `~/printer_data/database` is already populated with a `data.mdb` and `lock.mdb`
|
||||
delete them or simply overwrite them. Nothing should be lost as those should be empty database files. Anyway, you made backups, right?
|
||||
You can now proceed and restart Moonraker. Either from within Mainsail or Fluidd, or use SSH and execute `sudo systemctl restart moonraker`.
|
||||
If everything went smooth, you should be good to go again. If you see some Moonraker warnings about deprecated options in the `moonraker.conf`, go ahead and resolve them.
|
||||
I will not cover them in detail here. A good source is the Moonraker documentation: https://moonraker.readthedocs.io/en/latest/configuration/
|
||||
|
||||
**What if I have an existing Klipper/Moonraker multi-instance install?**\
|
||||
Pretty much the same steps that are required for single instance installs apply to multi-instance setups. So please go ahead and read the previous paragraph if you didn't already.
|
||||
Make backups of everything first. Then remove and install the desired amount of Klipper and Moonraker instances again.
|
||||
Now you need to move all config and database files to their new locations.\
|
||||
Example with an instance called `printer_1`:\
|
||||
The config files go from `~/klipper_config/printer_1` to `~/printer_1_data/config`.
|
||||
The database files go from `~/.moonraker_database_1` to `~/printer_1_data/database`.
|
||||
Now restart all Moonraker services. You can restart all of them at once if you launch KIAUH, and in the main menu type `restart moonraker` and hit Enter.
|
||||
|
||||
I hope I have covered the most important things. In case you need further support, the official Klipper Discord is a good place to ask for help.
|
||||
|
||||
### 2022-08-15
|
||||
Support for "Obico for Klipper" was added! Huge thanks to [kennethjiang](https://github.com/kennethjiang) for helping me with the implementation!
|
||||
|
||||
### 2022-05-29
|
||||
KIAUH has now reached major version 4 !
|
||||
* feat: Klipper can be installed under Python3 (still considered as experimental)
|
||||
* feat: Klipper can be installed from custom repositories / inofficial forks
|
||||
* feat: Custom instance name for multi instance installations of Klipper
|
||||
* Any other multi instance will share the same name given to the corresponding Klipper instance
|
||||
* E.g. klipper-voron2 -> moonraker-voron2 -> moonraker-telegram-bot-voron2
|
||||
* feat: Option to allow installation of / updating to unstable Mainsail and Fluidd versions
|
||||
* by default only stable versions get installed/updated
|
||||
* feat: Multi-Instance OctoPrint installations now each have their own virtual python environment
|
||||
* allows independent installation of plugins for each instance
|
||||
* feat: Implementing the use of shellcheck during development
|
||||
* feat: Implementing a simple logging mechanic
|
||||
* feat: Log-upload function now also allows uploading other logfiles (kiauh.log, webcamd.log etc.)
|
||||
* feat: added several new help dialogs which try to explain various functions
|
||||
* fix: During Klipper installation, checks for group membership of `tty` and `dialout` are made
|
||||
* refactor: rework of the settings menu for better control the new KIAUH features
|
||||
* refactor: Support for DWC and DWC-for-Klipper has been removed
|
||||
* refactor: The backup before update settings were moved to the KIAUH settings menu
|
||||
* refactor: Switch branch function has been removed (was replaced by the custom Klipper repo feature)
|
||||
* refactor: The update manager sections for Mainsail, Fluidd and KlipperScreen were removed from the moonraker.conf template
|
||||
* They will now be individually added during installation of the corresponding interface
|
||||
* refactor: The rollback function was reworked and now also allows rollbacks of Moonraker
|
||||
* It now takes numerical inputs and reverts the corresponding repository by the given amount instead
|
||||
* KIAUH does not save previous states to its config anymore like it did with the previous approach
|
||||
|
||||
|
||||
### 2022-01-29
|
||||
* Starting from the 28th of January, Moonraker can make use of PackageKit and PolicyKit.\
|
||||
More details on that can be found [here](
|
||||
https://github.com/Arksine/moonraker/issues/349) and [here](https://github.com/Arksine/moonraker/pull/346)
|
||||
* KIAUH will install Moonrakers PolicyKit rules by default when __installing__ Moonraker
|
||||
* KIAUH will also install Moonrakers PolicyKit rules when __updating__ Moonraker __via KIAUH__ as of now
|
||||
|
||||
### 2021-12-30
|
||||
* Updated the doc for the usage of the [G-Code Shell Command Extension](docs/gcode_shell_command.md)
|
||||
* It became apparent, that some user groups are missing on some systems. A missing video group \
|
||||
membership for example caused issues when installing mjpg-streamer while not using the default pi user. \
|
||||
Other issues could occur when trying to flash an MCU on Debian or Ubuntu distributions where a user might not be part
|
||||
of the dialout group by default. A check for the tty group is also done. The tty group is needed for setting
|
||||
up a linux MCU (currently not yet supported by KIAUH).
|
||||
* There is an issue when trying to install Mainsail or Fluidd on Ubuntu 21.10. Permissions on that distro seem to have seen a rework
|
||||
in comparison to 20.04 and users will be greeted with an "Error 403 - Permission denied" message after installing one of Klippers webinterfaces.
|
||||
I still have to figure out a viable solution for that.
|
||||
|
||||
### 2021-09-28
|
||||
* New Feature! Added an installer for the Telegram Bot for Moonraker by [nlef](https://github.com/nlef).
|
||||
Checkout his project! Remember to report all issues and/or bugs regarding that project in its corresponding repo and not here 😛.\
|
||||
You can find it here: https://github.com/nlef/moonraker-telegram-bot
|
||||
|
||||
### 2021-09-24
|
||||
* The flashing function got adjusted a bit. It is now possible to also flash controllers which are connected over UART and thus accessible via `/dev/ttyAMA0`. You now have to select a connection methop prior flashing which is either USB or UART.
|
||||
* Due to several requests over time I have now created a Ko-fi account for those who want to support this project and my work with a small donation. Many thanks in advance to all future donors. You can support me on Ko-fi with this link: https://ko-fi.com/th33xitus
|
||||
* As usual, if you find any bugs or issues please report them. I tested the little rework i did with the hardware i have available and haven't encountered any malfunctions of flashing them yet.
|
||||
|
||||
### 2021-08-10
|
||||
* KIAUH now supports the installation of the "PrettyGCode for Klipper" GCode-Viewer created by [Kragrathea](https://github.com/Kragrathea)! Installation, updating and removal are possible with KIAUH. For more details to this cool piece of software, please have a look here: https://github.com/Kragrathea/pgcode
|
||||
|
||||
### 2021-07-10
|
||||
* The NGINX configuration files got updated to be in sync with MainsailOS and FluiddPi. Issues with the NGINX service not starting up due to wrong configuration should be resolved now. To get the updated configuration files, please remove Moonraker and Mainsail / Fluidd with KIAUH first and then re-install it. An automated file check for those configuration files might follow in the future which then automates updating those files if there were important changes.
|
||||
|
||||
* The default `moonraker.conf` was updated to reflect the recent changes to the update manager section. The update channel is set to `dev`.
|
||||
|
||||
### 2021-06-29
|
||||
* KIAUH will now patch the new `log_path` to existing moonraker.conf files when updating Moonraker and the entry is missing. Before that, it was necessary that the user provided that path manually to make Fluidd display the logfiles in its interface. This issue should be resolved now.
|
||||
|
||||
### 2021-06-15
|
||||
|
||||
* Moonraker introduced an optional `log_path` which clients can make use of to show log files located in that folder to their users. More info here: https://github.com/Arksine/moonraker/commit/829b3a4ee80579af35dd64a37ccc092a1f67682a \
|
||||
Client developers agreed upon using `~/klipper_logs` as the new default log path.\
|
||||
That means, from now on, Klipper and Moonraker services installed with KIAUH will place their logfiles in that mentioned folder.
|
||||
* Additionally, KIAUH will now detect Klipper and Moonraker systemd services that still use the old default location of `/tmp/<service>.log` and will update them next time the user updates Klipper and/or Moonraker with the KIAUH update function.
|
||||
* Additional symlinks for the following logfiles will get created along those update procedures to make them accessible through the webinterface once its supported:
|
||||
- webcamd.log
|
||||
- mainsail-access.log
|
||||
- mainsail-error.log
|
||||
- fluidd-access.log
|
||||
- fluidd-error.log
|
||||
* For MainsailOS and FluiddPi users:\
|
||||
MainsailOS and FluiddPi will switch the shipped Klipper service from SysVinit to systemd probably with their next release. KIAUH can already help migrate older MainsailOS (0.4.0 and below) and FluiddPi (v1.13.0) releases to match their new service-, file- and folder-structure so you don't have to re-flash the SD-Card of your Raspberry Pi.\
|
||||
In detail here is what is going to happen when you use the new "CustomPiOS Migration Helper" from the Advanced Menu\
|
||||
`(Main Menu -> 4 -> Enter -> 10 -> Enter)` in a short summary:
|
||||
* The Klipper SysVinit service will get replaced by a Klipper systemd service
|
||||
* Klipper and Moonraker will use the new log-directory `~/klipper_logs`
|
||||
* The webcamd service gets updated
|
||||
* The webcamd script gets updated and moved from `/root/bin/webcamd` to `/usr/local/bin/webcamd`
|
||||
* The NGINX `upstreams.conf` gets updated to be able to configure up to 4 webcams
|
||||
* The `mainsail.txt` / `fluiddpi.txt` gets moved from `/boot` to `~/klipper_config` and renamed to `webcam.txt`
|
||||
* Symlinks for the webcamd.log and various NGINX logs get created in `~/klipper_config`
|
||||
* Configuration files for Klipper, Moonraker and webcamd get added to `/etc/logrotate.d`
|
||||
* If they still exist, two lines will be removed from the mainsail.cfg or client_macros.cfg macro configurations:\
|
||||
`SAVE_GCODE_STATE NAME=PAUSE_state` and `RESTORE_GCODE_STATE NAME=PAUSE_state`
|
||||
* **Please note:**\
|
||||
The "CustomPiOS Migration Helper" is intended to only work on "vanilla" MainsailOS and FluiddPi systems. Do not try to migrate a modified MainsailOS or FluiddPi system (for example if you already used KIAUH to re-install services or to set up a multi-instance installation for Klipper / Moonraker). This won't work.
|
||||
|
||||
### 2021-01-31
|
||||
|
||||
* **This is a big one... KIAUH v3.0 is out.**\
|
||||
With this update you can now install multiple instances of Klipper, Moonraker, Duet Web Control or Octoprint on the same Pi. This was quite a big rework of the whole script. So bugs can appear but with the help of some testers, i think there shouldn't be any critical ones anymore. In this regards thanks to @lixxbox and @zellneralex for testing.
|
||||
|
||||
* Important changes to how installations are set up now: All components get installed as systemd services. Installation via init.d was dropped completely! This shouldn't affect you at all, since the common linux distributions like RaspberryPi OS or custom distributions like MainsailOS, FluiddPi or OctoPi support both ways of installing services. I just wanted to mention it here.
|
||||
|
||||
* Now with KIAUH v3.0 and multi-instance installation capabilities, there are some things to point out. You will now need to tell KIAUH where your printers configurations are located when installing Klipper for the first time. Even though it is not recommended, you can change this location with the help of KIAUH and rewrite Klipper and Moonraker to use the new location.
|
||||
|
||||
* When setting up a multi-instance system, the folder structure will only change slightly. The goal was to keep it as compatible as possible with the custom distributions like mainsailOS and FluiddPi. This should help converting a single-instance setup of mainsailOS/FluiddPi to a multi-instance setup in no time, but keeping single-instance backwards compatibility if needed at a later point in time.
|
||||
|
||||
* The folder structure is as follows when setting up multi-instances:\
|
||||
Each printer instance will get its own folder within your configuration location. The decision to this specific structure was made to make it as painless and easy as possible to convert to a multi-instance setup.
|
||||
Here is an example:
|
||||
```shell
|
||||
/home/<username>
|
||||
└── klipper_config
|
||||
├── printer_1
|
||||
│ ├── printer.cfg
|
||||
│ └── moonraker.conf
|
||||
├── printer_2
|
||||
│ ├── printer.cfg
|
||||
│ └── moonraker.conf
|
||||
└── printer_n
|
||||
├── printer.cfg
|
||||
└── moonraker.conf
|
||||
```
|
||||
* Also when setting up multi-instances of each service, the name of each service slightly changes.
|
||||
Each service gets its corresponding instance added to the service filename.
|
||||
|
||||
**This only applies to multi-instances! Single instance installations with KIAUH will keep their original names!**
|
||||
|
||||
Corresponding to the filetree example from above that would mean:
|
||||
```
|
||||
Klipper services:
|
||||
--> klipper-1.service
|
||||
--> klipper-2.service
|
||||
--> klipper-n.service
|
||||
|
||||
Moonraker services:
|
||||
--> moonraker-1.service
|
||||
--> moonraker-2.service
|
||||
--> moonraker-n.service
|
||||
```
|
||||
* The same service file rules from above apply to OctoPrint even though only Klipper and Moonraker are shown in this example.
|
||||
|
||||
* You can start, stop and restart all Klipper, Moonraker and OctoPrint instances from the KIAUH main menu. For doing this, just type "stop klipper", "start moonraker", "restart octoprint" and so on.
|
||||
|
||||
* KIAUH v3.0 relocated its ini-file. It is now a hidden file in the users home-directory calles `.kiauh.ini`. This has the benefit of keeping all values in that file between possible re-installations of KIAUH. Otherwise that file would be lost.
|
||||
|
||||
* The option of adding more trusted clients to the moonraker.conf file was dropped. Since you can edit this file right inside of Mainsail or Fluidd, only some basic entries are made which get you running.
|
||||
|
||||
* I bet i have missed mentioning other stuff as well because it took me quite some time to re-write many functions. So i just hope you like the new version 😄
|
||||
|
||||
### 2020-11-28
|
||||
|
||||
* KIAUH now supports the installation, update and removal of [KlipperScreen](https://github.com/jordanruthe/KlipperScreen). This feature was was provided by [jordanruthe](https://github.com/jordanruthe)! Thank you!
|
||||
|
||||
### 2020-11-18
|
||||
|
||||
* Some changes to Fluidd caused a little rework on how KIAUH will install/update Fluidd from now on. Please see the [fluidd v1.0.0-rc0 release notes](https://github.com/cadriel/fluidd/releases/tag/v1.0.0-rc.0) for further information about what modifications to the moonraker.conf file exactly had to be done. In a nutshell, KIAUH will now always patch the required entries to the moonraker.conf if not already there.
|
||||
|
||||
### 2020-10-30:
|
||||
|
||||
* The user can now choose to install Klipper as a systemd service.
|
||||
|
||||
* The Shell Command extension and `shell_command.py` got renamed to G-Code Shell Command extension and `gcode_shell_command.py`. In case the [pending PR](https://github.com/KevinOConnor/klipper/pull/2173) will be merged in the future, this was an early attempt to dodge possible incompatibilities. The [G-Code Shell Command docs](extensions/gcode-shell-command) has been updated accordingly.
|
||||
|
||||
* The way how KIAUH interacts and writes to the users printer.cfg got changed. Usually KIAUH wrote everything directly into the printer.cfg. The way it will work from now on is, that a new file called `kiauh.cfg` will be created if there is something that needs to be written to the printer.cfg and everything gets written to `kiauh.cfg` instead. The only thing which then gets written to the users printer.cfg is `[include kiauh.cfg]`. This line will be located at the very top of the existing printer.cfg with a little comment as a note. The user can then decide to either keep the `kiauh.cfg` or take its content, places it into the printer.cfg directly and remove the `[include kiauh.cfg]`.
|
||||
|
||||
* The `mainsail_macros.cfg` got renamed to `webui_macros.cfg`. Since Mainsail and Fluidd both use the same kind of pause, cancel and resume macros, a more generic name was chosen for the file containing the example macros one can choose to install when installing those webinterfaces.
|
||||
|
||||
### 2020-10-10:
|
||||
|
||||
* Support for changing the Klipper branch to the moonraker-dev branch from @Arksine has been dropped. Support for Moonraker has been merged into Klipper mainline a long time ago.
|
||||
|
||||
* A new function is available from the main menu. You can now upload your log files to http://paste.c-net.org/ to share them for debugging purposes.
|
||||
|
||||
### 2020-10-06:
|
||||
|
||||
* Fluidd, a new Klipper interface got added to the list of available installers. At the same time some installation routines have changed or have seen some rework. Changes were made to the installation of NGINX configurations. A method was introduced to change the listen port of a webinterface configuration if there is already another webinterface listening on the default port (80).
|
||||
|
||||
* At the moment, the Moonraker installer no longer asks you whether you want to install a web interface too. For now you therefore have to install them with their respective installers. Please report any bugs or issues you encounter.
|
||||
|
||||
### 2020-09-17:
|
||||
|
||||
* The dev-2.0 branch will be abandoned as of today. If you did a checkout to that branch in the past, you have to checkout back to master to receive updates.
|
||||
|
||||
### 2020-09-12:
|
||||
|
||||
* The old [dwc2-for-klipper](https://github.com/Stephan3/dwc2-for-klipper) won't be supported anymore!\
|
||||
The is a new, fully rewritten project available: [dwc2-for-klipper-socket](https://github.com/Stephan3/dwc2-for-klipper-socket).\
|
||||
The installer of this script also got rewritten to make use of that new project. You will not be able to install or remove the old [dwc2-for-klipper](https://github.com/Stephan3/dwc2-for-klipper) with KIAUH anymore if you updated KIAUH to the newest version.
|
||||
@@ -1 +0,0 @@
|
||||
# Community Extensions
|
||||
@@ -1,23 +0,0 @@
|
||||
!!! tip "Important"
|
||||
This documentation is for KIAUH version 6 and still work in progress!
|
||||
|
||||
<h1 align="center">
|
||||
KIAUH - Klipper Installation And Update Helper
|
||||
</h1>
|
||||
|
||||
<p align="center">
|
||||
<img src="assets/logo-large.png" alt="KIAUH logo" width="400"/>
|
||||
</p>
|
||||
<p align="center" style="font-size: 1.2em; font-weight: bold;">
|
||||
A handy installation script that makes installing Klipper (and more) a breeze!
|
||||
</p>
|
||||
|
||||
|
||||
## Features
|
||||
|
||||
- Easy installation of Klipper and related components
|
||||
- Support for multiple instances
|
||||
- Extension system for additional functionality
|
||||
- Configuration management
|
||||
- And more!
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
# Installing KIAUH
|
||||
|
||||
In the following sections, you will be guided through the installation
|
||||
process step-by-step.
|
||||
|
||||
To use KIAUH, it is enough to download the script and run it on your
|
||||
Raspberry Pi or other compatible device. If you need to know how to
|
||||
set up a Raspberry Pi or if you are unsure whether your current setup
|
||||
is sufficient, please refer to the [Raspberry Pi Installation Guide](raspberry-pi-setup.md)
|
||||
and follow the steps therein. Afterwards, you can return to this guide to install KIAUH.
|
||||
|
||||
### Prerequisites
|
||||
Before you can download and run KIAUH, you need to ensure that ``git`` is
|
||||
installed on your system. Open a terminal and run the following command:
|
||||
|
||||
```bash
|
||||
sudo apt-get update && sudo apt-get install git -y
|
||||
```
|
||||
|
||||
### Downloading KIAUH
|
||||
After `git` was successfully installed, you can download KIAUH by
|
||||
cloning the repository from GitHub. It is recommended to clone it into
|
||||
your home directory. Run the following command in your terminal:
|
||||
```bash
|
||||
cd ~ && git clone https://github.com/dw-0/kiauh.git
|
||||
```
|
||||
|
||||
### Running KIAUH
|
||||
Once the repository is cloned, you can start KIAUH. Make sure you are in
|
||||
your home directory and execute the script by running the following
|
||||
command:
|
||||
```bash
|
||||
./kiauh/kiauh.sh
|
||||
```
|
||||
|
||||
After executing the command, you will be presented with the KIAUH menu,
|
||||
which allows you to install and manage various 3D printing software.
|
||||
For more information on how to use KIAUH, please refer to the
|
||||
[Usage Guide](usage.md).
|
||||
@@ -1,49 +0,0 @@
|
||||
# Raspberry Pi Setup
|
||||
|
||||
This guide will help you set up a Raspberry Pi for running Klipper and other,
|
||||
Klipper related 3D printing software. In case you are using a different single-board
|
||||
computer (SBC), please refer to the manufacturer's instructions for installing
|
||||
a compatible version of Linux on your device.
|
||||
|
||||
It is assumed that you have at least a Raspberry Pi 3 or newer, along with a
|
||||
microSD card (at least 8GB, preferably 16GB or more) and a power supply.
|
||||
Additionally, you will need a computer with an SD card reader to prepare
|
||||
the microSD card.
|
||||
|
||||
KIAUH requires a Linux operating system that has already been flashed to your
|
||||
Raspberry Pi's (or other SBC's) microSD card. As a result, you must ensure that you
|
||||
already have a functional Linux system on hand before you can proceed with
|
||||
installing KIAUH. `Raspberry Pi OS Lite` (either 32bit or 64bit) is a recommended Linux image
|
||||
if you are using a Raspberry Pi.
|
||||
|
||||
---
|
||||
|
||||
To flash `Raspberry Pi OS Lite` to your microSD card using the official [Raspberry Pi Imager](https://www.raspberrypi.com/software/),
|
||||
follow the steps below. If you encounter any issues or need further assistance, please refer to the [official Raspberry Pi documentation](https://www.raspberrypi.com/documentation/computers/getting-started.html).
|
||||
|
||||
1. Open the Raspberry Pi Imager application on your computer.
|
||||
2. Click on `Choose OS` and select `Raspberry Pi OS (other)`.
|
||||

|
||||
3. Choose `Raspberry Pi OS Lite (32bit)` (or 64bit if desired).
|
||||

|
||||
4. Insert the microSD card into your computer's SD card reader.
|
||||
5. In the main menu of the Imager, select the correct microSD card.
|
||||
6. Click the gear icon at the bottom left of the main menu to open advanced options.
|
||||
7. Enable SSH and enter your Wi-Fi credentials.
|
||||
|
||||
!!! info
|
||||
Wi-Fi is only necessary if you want to connect to your Raspberry Pi over a wireless network. If you plan to use a wired Ethernet connection, you can skip this step. SSH is required for remote access to your Raspberry Pi, so make sure to enable it.
|
||||
|
||||
8. Click `Save` to close the advanced options menu.
|
||||
9. Click `Write` to start flashing the image to the microSD card.
|
||||
|
||||
!!! warning
|
||||
All data on the microSD card will be overwritten!
|
||||
|
||||
10. Once the flashing process is complete, safely eject the microSD card from your computer.
|
||||
11. Insert the microSD card into your Raspberry Pi.
|
||||
12. Connect your Raspberry Pi to a power source to boot it up.
|
||||
13. Wait for a few minutes to allow the Raspberry Pi to complete its initial setup.
|
||||
14. You can now connect to your Raspberry Pi via SSH using the IP address assigned by your router. The default username is `pi` and the default password is `raspberry`.
|
||||
|
||||
If you successfully connected to your Raspberry Pi via SSH, you can proceed to install KIAUH by following the instructions in the [Installation Guide](installation.md).
|
||||
15
kiauh.py
15
kiauh.py
@@ -1,15 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# ======================================================================= #
|
||||
# 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 kiauh.main import main
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
113
kiauh.sh
113
kiauh.sh
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
|
||||
# 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 #
|
||||
@@ -15,11 +15,6 @@ clear -x
|
||||
# make sure we have the correct permissions while running the script
|
||||
umask 022
|
||||
|
||||
### sourcing all additional scripts
|
||||
KIAUH_SRCDIR="$(dirname -- "$(readlink -f "${BASH_SOURCE[0]}")")"
|
||||
for script in "${KIAUH_SRCDIR}/scripts/"*.sh; do . "${script}"; done
|
||||
for script in "${KIAUH_SRCDIR}/scripts/ui/"*.sh; do . "${script}"; done
|
||||
|
||||
#===================================================#
|
||||
#=================== UPDATE KIAUH ==================#
|
||||
#===================================================#
|
||||
@@ -57,26 +52,17 @@ function kiauh_update_avail() {
|
||||
fi
|
||||
}
|
||||
|
||||
function save_startup_version() {
|
||||
local launch_version
|
||||
|
||||
echo "${1}"
|
||||
|
||||
sed -i "/^version_to_launch=/d" "${INI_FILE}"
|
||||
sed -i '$a'"version_to_launch=${1}" "${INI_FILE}"
|
||||
}
|
||||
|
||||
function kiauh_update_dialog() {
|
||||
[[ ! $(kiauh_update_avail) == "true" ]] && return
|
||||
top_border
|
||||
echo -e "/-------------------------------------------------------\\"
|
||||
echo -e "|${green} New KIAUH update available! ${white}|"
|
||||
hr
|
||||
echo -e "|-------------------------------------------------------|"
|
||||
echo -e "|${green} View Changelog: https://git.io/JnmlX ${white}|"
|
||||
blank_line
|
||||
echo -e "| |"
|
||||
echo -e "|${yellow} It is recommended to keep KIAUH up to date. Updates ${white}|"
|
||||
echo -e "|${yellow} usually contain bugfixes, important changes or new ${white}|"
|
||||
echo -e "|${yellow} features. Please consider updating! ${white}|"
|
||||
bottom_border
|
||||
echo -e "\-------------------------------------------------------/"
|
||||
|
||||
local yn
|
||||
read -p "${cyan}###### Do you want to update now? (Y/n):${white} " yn
|
||||
@@ -93,11 +79,35 @@ function kiauh_update_dialog() {
|
||||
done
|
||||
}
|
||||
|
||||
function launch_kiauh_v5() {
|
||||
main_menu
|
||||
function check_euid() {
|
||||
if [[ ${EUID} -eq 0 ]]; then
|
||||
echo -e "${red}"
|
||||
echo -e "/-------------------------------------------------------\\"
|
||||
echo -e "| !!! THIS SCRIPT MUST NOT RUN AS ROOT !!! |"
|
||||
echo -e "| |"
|
||||
echo -e "| It will ask for credentials as needed. |"
|
||||
echo -e "\-------------------------------------------------------/"
|
||||
echo -e "${white}"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function launch_kiauh_v6() {
|
||||
function check_if_ratos() {
|
||||
if [[ -n $(which ratos) ]]; then
|
||||
echo -e "${red}"
|
||||
echo -e "/-------------------------------------------------------\\"
|
||||
echo -e "| !!! RatOS 2.1 or greater detected !!! |"
|
||||
echo -e "| |"
|
||||
echo -e "| KIAUH does currently not support RatOS. |"
|
||||
echo -e "| If you have any questions, please ask for help on the |"
|
||||
echo -e "| RatRig Community Discord: https://discord.gg/ratrig |"
|
||||
echo -e "\-------------------------------------------------------/"
|
||||
echo -e "${white}"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function main() {
|
||||
local entrypoint
|
||||
|
||||
if ! command -v python3 &>/dev/null || [[ $(python3 -V | cut -d " " -f2 | cut -d "." -f2) -lt 8 ]]; then
|
||||
@@ -111,67 +121,10 @@ function launch_kiauh_v6() {
|
||||
export PYTHONPATH="${entrypoint}"
|
||||
|
||||
clear -x
|
||||
python3 "${entrypoint}/kiauh.py"
|
||||
}
|
||||
|
||||
function main() {
|
||||
read_kiauh_ini "${FUNCNAME[0]}"
|
||||
|
||||
if [[ ${version_to_launch} -eq 5 ]]; then
|
||||
launch_kiauh_v5
|
||||
elif [[ ${version_to_launch} -eq 6 ]]; then
|
||||
launch_kiauh_v6
|
||||
else
|
||||
top_border
|
||||
echo -e "| ${green}KIAUH v6.0.0-alpha1 is available now!${white} |"
|
||||
hr
|
||||
echo -e "| View Changelog: ${magenta}https://git.io/JnmlX${white} |"
|
||||
blank_line
|
||||
echo -e "| KIAUH v6 was completely rewritten from the ground up. |"
|
||||
echo -e "| It's based on Python 3.8 and has many improvements. |"
|
||||
blank_line
|
||||
echo -e "| ${yellow}NOTE: Version 6 is still in alpha, so bugs may occur!${white} |"
|
||||
echo -e "| ${yellow}Yet, your feedback and bug reports are very much${white} |"
|
||||
echo -e "| ${yellow}appreciated and will help finalize the release.${white} |"
|
||||
hr
|
||||
echo -e "| Would you like to try out KIAUH v6? |"
|
||||
echo -e "| 1) Yes |"
|
||||
echo -e "| 2) No |"
|
||||
echo -e "| 3) Yes, remember my choice for next time |"
|
||||
echo -e "| 4) No, remember my choice for next time |"
|
||||
quit_footer
|
||||
while true; do
|
||||
read -p "${cyan}###### Select action:${white} " -e input
|
||||
case "${input}" in
|
||||
1)
|
||||
launch_kiauh_v6
|
||||
break;;
|
||||
2)
|
||||
launch_kiauh_v5
|
||||
break;;
|
||||
3)
|
||||
save_startup_version 6
|
||||
launch_kiauh_v6
|
||||
break;;
|
||||
4)
|
||||
save_startup_version 5
|
||||
launch_kiauh_v5
|
||||
break;;
|
||||
Q|q)
|
||||
echo -e "${green}###### Happy printing! ######${white}"; echo
|
||||
exit 0;;
|
||||
*)
|
||||
error_msg "Invalid Input!\n";;
|
||||
esac
|
||||
done && input=""
|
||||
fi
|
||||
python3 "${entrypoint}/kiauh/main.py"
|
||||
}
|
||||
|
||||
check_if_ratos
|
||||
check_euid
|
||||
init_logfile
|
||||
set_globals
|
||||
kiauh_update_dialog
|
||||
read_kiauh_ini
|
||||
init_ini
|
||||
main
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from core.backup_manager import BACKUP_ROOT_DIR
|
||||
from core.constants import SYSTEMD
|
||||
|
||||
# repo
|
||||
@@ -20,7 +19,6 @@ CROWSNEST_SERVICE_NAME = "crowsnest.service"
|
||||
|
||||
# directories
|
||||
CROWSNEST_DIR = Path.home().joinpath("crowsnest")
|
||||
CROWSNEST_BACKUP_DIR = BACKUP_ROOT_DIR.joinpath("crowsnest-backups")
|
||||
|
||||
# files
|
||||
CROWSNEST_MULTI_CONFIG = CROWSNEST_DIR.joinpath("tools/.config")
|
||||
|
||||
@@ -15,7 +15,6 @@ from subprocess import CalledProcessError, run
|
||||
from typing import List
|
||||
|
||||
from components.crowsnest import (
|
||||
CROWSNEST_BACKUP_DIR,
|
||||
CROWSNEST_BIN_FILE,
|
||||
CROWSNEST_DIR,
|
||||
CROWSNEST_INSTALL_SCRIPT,
|
||||
@@ -26,8 +25,8 @@ from components.crowsnest import (
|
||||
CROWSNEST_SERVICE_NAME,
|
||||
)
|
||||
from components.klipper.klipper import Klipper
|
||||
from core.backup_manager.backup_manager import BackupManager
|
||||
from core.logger import DialogType, Logger
|
||||
from core.services.backup_service import BackupService
|
||||
from core.settings.kiauh_settings import KiauhSettings
|
||||
from core.types.component_status import ComponentStatus
|
||||
from utils.common import (
|
||||
@@ -127,11 +126,11 @@ def update_crowsnest() -> None:
|
||||
|
||||
settings = KiauhSettings()
|
||||
if settings.kiauh.backup_before_update:
|
||||
bm = BackupManager()
|
||||
bm.backup_directory(
|
||||
CROWSNEST_DIR.name,
|
||||
source=CROWSNEST_DIR,
|
||||
target=CROWSNEST_BACKUP_DIR,
|
||||
svc = BackupService()
|
||||
svc.backup_directory(
|
||||
source_path=CROWSNEST_DIR,
|
||||
target_path="crowsnest",
|
||||
backup_name="crowsnest",
|
||||
)
|
||||
|
||||
git_pull_wrapper(CROWSNEST_DIR)
|
||||
|
||||
@@ -9,8 +9,6 @@
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from core.backup_manager import BACKUP_ROOT_DIR
|
||||
|
||||
MODULE_PATH = Path(__file__).resolve().parent
|
||||
|
||||
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_KCONFIGS_DIR = Path.home().joinpath("klipper-kconfigs")
|
||||
KLIPPER_ENV_DIR = Path.home().joinpath("klippy-env")
|
||||
KLIPPER_BACKUP_DIR = BACKUP_ROOT_DIR.joinpath("klipper-backups")
|
||||
|
||||
# files
|
||||
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 components.klipper import (
|
||||
KLIPPER_BACKUP_DIR,
|
||||
KLIPPER_DIR,
|
||||
KLIPPER_ENV_DIR,
|
||||
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 (
|
||||
create_client_config_symlink,
|
||||
)
|
||||
from core.backup_manager.backup_manager import BackupManager
|
||||
from core.constants import CURRENT_USER
|
||||
from core.instance_manager.base_instance import SUFFIX_BLACKLIST
|
||||
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 (
|
||||
SimpleConfigParser,
|
||||
)
|
||||
@@ -198,9 +197,17 @@ def create_example_printer_cfg(
|
||||
|
||||
|
||||
def backup_klipper_dir() -> None:
|
||||
bm = BackupManager()
|
||||
bm.backup_directory("klipper", source=KLIPPER_DIR, target=KLIPPER_BACKUP_DIR)
|
||||
bm.backup_directory("klippy-env", source=KLIPPER_ENV_DIR, target=KLIPPER_BACKUP_DIR)
|
||||
svc = BackupService()
|
||||
svc.backup_directory(
|
||||
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:
|
||||
@@ -230,7 +237,6 @@ def install_input_shaper_deps() -> None:
|
||||
"If you agree, the following additional system packages will be installed:",
|
||||
"● python3-numpy",
|
||||
"● python3-matplotlib",
|
||||
"● libatlas-base-dev",
|
||||
"● libopenblas-dev",
|
||||
"\n\n",
|
||||
"Also, the following Python package will be installed:",
|
||||
@@ -246,7 +252,6 @@ def install_input_shaper_deps() -> None:
|
||||
apt_deps = (
|
||||
"python3-numpy",
|
||||
"python3-matplotlib",
|
||||
"libatlas-base-dev",
|
||||
"libopenblas-dev",
|
||||
)
|
||||
check_install_dependencies({*apt_deps})
|
||||
|
||||
0
kiauh/components/klipper/services/__init__.py
Normal file
0
kiauh/components/klipper/services/__init__.py
Normal file
@@ -8,7 +8,6 @@
|
||||
# ======================================================================= #
|
||||
from pathlib import Path
|
||||
|
||||
from core.backup_manager import BACKUP_ROOT_DIR
|
||||
from core.constants import SYSTEMD
|
||||
|
||||
# repo
|
||||
@@ -22,7 +21,6 @@ KLIPPERSCREEN_LOG_NAME = "KlipperScreen.log"
|
||||
# directories
|
||||
KLIPPERSCREEN_DIR = Path.home().joinpath("KlipperScreen")
|
||||
KLIPPERSCREEN_ENV_DIR = Path.home().joinpath(".KlipperScreen-env")
|
||||
KLIPPERSCREEN_BACKUP_DIR = BACKUP_ROOT_DIR.joinpath("klipperscreen-backups")
|
||||
|
||||
# files
|
||||
KLIPPERSCREEN_REQ_FILE = KLIPPERSCREEN_DIR.joinpath(
|
||||
|
||||
@@ -13,7 +13,6 @@ from typing import List
|
||||
|
||||
from components.klipper.klipper import Klipper
|
||||
from components.klipperscreen import (
|
||||
KLIPPERSCREEN_BACKUP_DIR,
|
||||
KLIPPERSCREEN_DIR,
|
||||
KLIPPERSCREEN_ENV_DIR,
|
||||
KLIPPERSCREEN_INSTALL_SCRIPT,
|
||||
@@ -25,10 +24,10 @@ from components.klipperscreen import (
|
||||
KLIPPERSCREEN_UPDATER_SECTION_NAME,
|
||||
)
|
||||
from components.moonraker.moonraker import Moonraker
|
||||
from core.backup_manager.backup_manager import BackupManager
|
||||
from core.constants import SYSTEMD
|
||||
from core.instance_manager.instance_manager import InstanceManager
|
||||
from core.logger import DialogType, Logger
|
||||
from core.services.backup_service import BackupService
|
||||
from core.settings.kiauh_settings import KiauhSettings
|
||||
from core.types.component_status import ComponentStatus
|
||||
from utils.common import (
|
||||
@@ -97,6 +96,7 @@ def install_klipperscreen() -> None:
|
||||
|
||||
|
||||
def patch_klipperscreen_update_manager(instances: List[Moonraker]) -> None:
|
||||
BackupService().backup_moonraker_conf()
|
||||
add_config_section(
|
||||
section=KLIPPERSCREEN_UPDATER_SECTION_NAME,
|
||||
instances=instances,
|
||||
@@ -183,6 +183,7 @@ def remove_klipperscreen() -> None:
|
||||
mr_instances: List[Moonraker] = get_instances(Moonraker)
|
||||
if mr_instances:
|
||||
Logger.print_status("Removing KlipperScreen from update manager ...")
|
||||
BackupService().backup_moonraker_conf()
|
||||
remove_config_section("update_manager KlipperScreen", mr_instances)
|
||||
Logger.print_ok("KlipperScreen successfully removed from update manager!")
|
||||
|
||||
@@ -193,14 +194,14 @@ def remove_klipperscreen() -> None:
|
||||
|
||||
|
||||
def backup_klipperscreen_dir() -> None:
|
||||
bm = BackupManager()
|
||||
bm.backup_directory(
|
||||
KLIPPERSCREEN_DIR.name,
|
||||
source=KLIPPERSCREEN_DIR,
|
||||
target=KLIPPERSCREEN_BACKUP_DIR,
|
||||
svc = BackupService()
|
||||
svc.backup_directory(
|
||||
source_path=KLIPPERSCREEN_DIR,
|
||||
backup_name="KlipperScreen",
|
||||
target_path="KlipperScreen",
|
||||
)
|
||||
bm.backup_directory(
|
||||
KLIPPERSCREEN_ENV_DIR.name,
|
||||
source=KLIPPERSCREEN_ENV_DIR,
|
||||
target=KLIPPERSCREEN_BACKUP_DIR,
|
||||
svc.backup_directory(
|
||||
source_path=KLIPPERSCREEN_ENV_DIR,
|
||||
backup_name="KlipperScreen-env",
|
||||
target_path="KlipperScreen",
|
||||
)
|
||||
|
||||
@@ -9,8 +9,6 @@
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from core.backup_manager import BACKUP_ROOT_DIR
|
||||
|
||||
MODULE_PATH = Path(__file__).resolve().parent
|
||||
|
||||
MOONRAKER_REPO_URL = "https://github.com/Arksine/moonraker.git"
|
||||
@@ -25,8 +23,6 @@ MOONRAKER_ENV_FILE_NAME = "moonraker.env"
|
||||
# directories
|
||||
MOONRAKER_DIR = Path.home().joinpath("moonraker")
|
||||
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
|
||||
MOONRAKER_INSTALL_SCRIPT = MOONRAKER_DIR.joinpath("scripts/install-moonraker.sh")
|
||||
|
||||
0
kiauh/components/moonraker/menus/__init__.py
Normal file
0
kiauh/components/moonraker/menus/__init__.py
Normal file
@@ -61,6 +61,9 @@ class SysDepsParser:
|
||||
version = distro_info.get("distro_version")
|
||||
if 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:
|
||||
parts = full_spec.split(";", maxsplit=1)
|
||||
@@ -109,6 +112,9 @@ class SysDepsParser:
|
||||
elif req_var == "distro_id":
|
||||
left_op: str | Tuple[int | str, ...] = self.distro_id
|
||||
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":
|
||||
if not self.distro_version:
|
||||
logging.info(
|
||||
|
||||
@@ -14,8 +14,6 @@ from typing import Dict, List, Optional
|
||||
|
||||
from components.moonraker import (
|
||||
MODULE_PATH,
|
||||
MOONRAKER_BACKUP_DIR,
|
||||
MOONRAKER_DB_BACKUP_DIR,
|
||||
MOONRAKER_DEFAULT_PORT,
|
||||
MOONRAKER_DEPS_JSON_FILE,
|
||||
MOONRAKER_DIR,
|
||||
@@ -25,8 +23,8 @@ from components.moonraker import (
|
||||
from components.moonraker.moonraker import Moonraker
|
||||
from components.moonraker.utils.sysdeps_parser import SysDepsParser
|
||||
from components.webui_client.base_data import BaseWebClient
|
||||
from core.backup_manager.backup_manager import BackupManager
|
||||
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 (
|
||||
SimpleConfigParser,
|
||||
)
|
||||
@@ -125,7 +123,7 @@ def create_example_moonraker_conf(
|
||||
scp = SimpleConfigParser()
|
||||
scp.read_file(target)
|
||||
trusted_clients: List[str] = [
|
||||
f" {'.'.join(ip)}\n",
|
||||
f"{'.'.join(ip)}",
|
||||
*scp.getvals("authorization", "trusted_clients"),
|
||||
]
|
||||
|
||||
@@ -168,21 +166,55 @@ def create_example_moonraker_conf(
|
||||
|
||||
|
||||
def backup_moonraker_dir() -> None:
|
||||
bm = BackupManager()
|
||||
bm.backup_directory("moonraker", source=MOONRAKER_DIR, target=MOONRAKER_BACKUP_DIR)
|
||||
bm.backup_directory(
|
||||
"moonraker-env", source=MOONRAKER_ENV_DIR, target=MOONRAKER_BACKUP_DIR
|
||||
svc = BackupService()
|
||||
svc.backup_directory(
|
||||
source_path=MOONRAKER_DIR, backup_name="moonraker", target_path="moonraker"
|
||||
)
|
||||
svc.backup_directory(
|
||||
source_path=MOONRAKER_ENV_DIR,
|
||||
backup_name="moonraker-env",
|
||||
target_path="moonraker",
|
||||
)
|
||||
|
||||
|
||||
def backup_moonraker_db_dir() -> None:
|
||||
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:
|
||||
name = f"database-{instance.data_dir.name}"
|
||||
bm.backup_directory(
|
||||
name, source=instance.db_dir, target=MOONRAKER_DB_BACKUP_DIR
|
||||
svc.backup_directory(
|
||||
source_path=instance.db_dir,
|
||||
target_path=f"{instance.data_dir.name}",
|
||||
backup_name="database",
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -34,7 +34,6 @@ class BaseWebClient(ABC):
|
||||
display_name: str
|
||||
client_dir: Path
|
||||
config_file: Path
|
||||
backup_dir: Path
|
||||
repo_path: str
|
||||
download_url: str
|
||||
nginx_config: Path
|
||||
@@ -52,6 +51,5 @@ class BaseWebClientConfig(ABC):
|
||||
display_name: str
|
||||
config_filename: str
|
||||
config_dir: Path
|
||||
backup_dir: Path
|
||||
repo_url: str
|
||||
config_section: str
|
||||
|
||||
@@ -14,6 +14,7 @@ from components.klipper.klipper import Klipper
|
||||
from components.moonraker.moonraker import Moonraker
|
||||
from components.webui_client.base_data import BaseWebClientConfig
|
||||
from core.logger import Logger
|
||||
from core.services.backup_service import BackupService
|
||||
from core.services.message_service import Message
|
||||
from core.types.color import Color
|
||||
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):
|
||||
completion_msg.text.append(f"● {client_config.display_name} removed")
|
||||
|
||||
BackupService().backup_printer_config_dir()
|
||||
|
||||
completion_msg = remove_moonraker_config_section(
|
||||
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.logger import Logger
|
||||
from core.services.backup_service import BackupService
|
||||
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.fs_utils import create_symlink
|
||||
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)
|
||||
|
||||
if cfg_backup:
|
||||
backup_printer_config_dir()
|
||||
BackupService().backup_printer_config_dir()
|
||||
|
||||
add_config_section(
|
||||
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 (
|
||||
run_client_config_removal,
|
||||
)
|
||||
from core.backup_manager.backup_manager import BackupManager
|
||||
from core.constants import NGINX_SITES_AVAILABLE, NGINX_SITES_ENABLED
|
||||
from core.logger import Logger
|
||||
from core.services.backup_service import BackupService
|
||||
from core.services.message_service import Message
|
||||
from core.types.color import Color
|
||||
from utils.config_utils import remove_config_section
|
||||
@@ -43,8 +43,19 @@ def run_client_removal(
|
||||
kl_instances: List[Klipper] = get_instances(Klipper)
|
||||
|
||||
if backup_config:
|
||||
bm = BackupManager()
|
||||
if bm.backup_file(client.config_file):
|
||||
version = ""
|
||||
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")
|
||||
|
||||
if remove_client:
|
||||
@@ -56,6 +67,7 @@ def run_client_removal(
|
||||
if remove_client_nginx_logs(client, kl_instances):
|
||||
completion_msg.text.append("● NGINX logs removed")
|
||||
|
||||
BackupService().backup_moonraker_conf()
|
||||
section = f"update_manager {client_name}"
|
||||
handled_instances: List[Moonraker] = remove_config_section(
|
||||
section, mr_instances
|
||||
|
||||
@@ -37,9 +37,10 @@ from components.webui_client.client_utils import (
|
||||
)
|
||||
from core.instance_manager.instance_manager import InstanceManager
|
||||
from core.logger import DialogType, Logger
|
||||
from core.services.backup_service import BackupService
|
||||
from core.settings.kiauh_settings import KiauhSettings
|
||||
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.fs_utils import unzip
|
||||
from utils.input_utils import get_confirm
|
||||
@@ -97,7 +98,7 @@ def install_client(
|
||||
if enable_remotemode and client.client == WebClientType.MAINSAIL:
|
||||
enable_mainsail_remotemode()
|
||||
|
||||
backup_printer_config_dir()
|
||||
BackupService().backup_printer_config_dir()
|
||||
add_config_section(
|
||||
section=f"update_manager {client.name}",
|
||||
instances=mr_instances,
|
||||
|
||||
@@ -11,6 +11,7 @@ from __future__ import annotations
|
||||
import json
|
||||
import re
|
||||
import shutil
|
||||
from json import JSONDecodeError
|
||||
from pathlib import Path
|
||||
from subprocess import PIPE, CalledProcessError, run
|
||||
from typing import List, get_args
|
||||
@@ -24,13 +25,13 @@ from components.webui_client.base_data import (
|
||||
from components.webui_client.client_dialogs import print_client_port_select_dialog
|
||||
from components.webui_client.fluidd_data import FluiddData
|
||||
from components.webui_client.mainsail_data import MainsailData
|
||||
from core.backup_manager.backup_manager import BackupManager
|
||||
from core.constants import (
|
||||
NGINX_CONFD,
|
||||
NGINX_SITES_AVAILABLE,
|
||||
NGINX_SITES_ENABLED,
|
||||
)
|
||||
from core.logger import Logger
|
||||
from core.services.backup_service import BackupService
|
||||
from core.settings.kiauh_settings import KiauhSettings, WebUiSettings
|
||||
from core.submodules.simple_config_parser.src.simple_config_parser.simple_config_parser import (
|
||||
SimpleConfigParser,
|
||||
@@ -151,18 +152,36 @@ def symlink_webui_nginx_log(
|
||||
def get_local_client_version(client: BaseWebClient) -> str | None:
|
||||
relinfo_file = client.client_dir.joinpath("release_info.json")
|
||||
version_file = client.client_dir.joinpath(".version")
|
||||
default = "n/a"
|
||||
|
||||
if not client.client_dir.exists():
|
||||
return None
|
||||
if not relinfo_file.is_file() and not version_file.is_file():
|
||||
return "n/a"
|
||||
return default
|
||||
|
||||
# try to get version from release_info.json first
|
||||
if relinfo_file.is_file():
|
||||
with open(relinfo_file, "r") as f:
|
||||
return str(json.load(f)["version"])
|
||||
else:
|
||||
try:
|
||||
if relinfo_file.stat().st_size == 0:
|
||||
raise JSONDecodeError("Empty file", "", 0)
|
||||
with open(relinfo_file, "r", encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
raw_version = data.get("version")
|
||||
if raw_version is not None:
|
||||
parsed = str(raw_version).strip()
|
||||
if parsed:
|
||||
return parsed
|
||||
except (JSONDecodeError, OSError):
|
||||
Logger.print_error("Invalid 'release_info.json'")
|
||||
|
||||
# fallback to .version file
|
||||
if version_file.is_file():
|
||||
try:
|
||||
with open(version_file, "r") as f:
|
||||
return f.readlines()[0]
|
||||
line = f.readline().strip()
|
||||
return line or default
|
||||
except OSError:
|
||||
Logger.print_error("Unable to read '.version'")
|
||||
|
||||
return default
|
||||
|
||||
|
||||
def get_remote_client_version(client: BaseWebClient) -> str | None:
|
||||
@@ -175,26 +194,39 @@ def get_remote_client_version(client: BaseWebClient) -> str | None:
|
||||
|
||||
|
||||
def backup_client_data(client: BaseWebClient) -> None:
|
||||
name = client.name
|
||||
version = ""
|
||||
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]
|
||||
|
||||
bm = BackupManager()
|
||||
bm.backup_directory(f"{name}-{version}", src, dest)
|
||||
bm.backup_file(client.config_file, dest)
|
||||
bm.backup_file(NGINX_SITES_AVAILABLE.joinpath(name), dest)
|
||||
svc = BackupService()
|
||||
target_path = svc.backup_root.joinpath(f"{client.client_dir.name}_{version}")
|
||||
svc.backup_directory(
|
||||
source_path=client.client_dir,
|
||||
target_path=target_path,
|
||||
backup_name=client.name,
|
||||
)
|
||||
svc.backup_file(
|
||||
source_path=client.config_file,
|
||||
target_path=target_path,
|
||||
)
|
||||
|
||||
|
||||
def backup_client_config_data(client: BaseWebClient) -> None:
|
||||
client_config = client.client_config
|
||||
name = client_config.name
|
||||
source = client_config.config_dir
|
||||
target = client_config.backup_dir
|
||||
bm = BackupManager()
|
||||
bm.backup_directory(name, source, target)
|
||||
version = ""
|
||||
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}")
|
||||
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]:
|
||||
|
||||
@@ -18,7 +18,6 @@ from components.webui_client.base_data import (
|
||||
WebClientConfigType,
|
||||
WebClientType,
|
||||
)
|
||||
from core.backup_manager import BACKUP_ROOT_DIR
|
||||
from core.constants import NGINX_SITES_AVAILABLE
|
||||
|
||||
|
||||
@@ -30,7 +29,6 @@ class FluiddConfigWeb(BaseWebClientConfig):
|
||||
config_dir: Path = Path.home().joinpath("fluidd-config")
|
||||
config_filename: str = "fluidd.cfg"
|
||||
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"
|
||||
|
||||
|
||||
@@ -43,7 +41,6 @@ class FluiddData(BaseWebClient):
|
||||
display_name: str = name.capitalize()
|
||||
client_dir: Path = Path.home().joinpath("fluidd")
|
||||
config_file: Path = client_dir.joinpath("config.json")
|
||||
backup_dir: Path = BACKUP_ROOT_DIR.joinpath("fluidd-backups")
|
||||
repo_path: str = "fluidd-core/fluidd"
|
||||
nginx_config: Path = NGINX_SITES_AVAILABLE.joinpath("fluidd")
|
||||
nginx_access_log: Path = Path("/var/log/nginx/fluidd-access.log")
|
||||
|
||||
@@ -18,7 +18,6 @@ from components.webui_client.base_data import (
|
||||
WebClientConfigType,
|
||||
WebClientType,
|
||||
)
|
||||
from core.backup_manager import BACKUP_ROOT_DIR
|
||||
from core.constants import NGINX_SITES_AVAILABLE
|
||||
|
||||
|
||||
@@ -30,7 +29,6 @@ class MainsailConfigWeb(BaseWebClientConfig):
|
||||
config_dir: Path = Path.home().joinpath("mainsail-config")
|
||||
config_filename: str = "mainsail.cfg"
|
||||
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"
|
||||
|
||||
|
||||
@@ -43,7 +41,6 @@ class MainsailData(BaseWebClient):
|
||||
display_name: str = name.capitalize()
|
||||
client_dir: Path = Path.home().joinpath("mainsail")
|
||||
config_file: Path = client_dir.joinpath("config.json")
|
||||
backup_dir: Path = BACKUP_ROOT_DIR.joinpath("mainsail-backups")
|
||||
repo_path: str = "mainsail-crew/mainsail"
|
||||
nginx_config: Path = NGINX_SITES_AVAILABLE.joinpath("mainsail")
|
||||
nginx_access_log: Path = Path("/var/log/nginx/mainsail-access.log")
|
||||
|
||||
@@ -1,12 +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 pathlib import Path
|
||||
|
||||
BACKUP_ROOT_DIR = Path.home().joinpath("kiauh-backups")
|
||||
@@ -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
|
||||
from pathlib import Path
|
||||
|
||||
from core.backup_manager import BACKUP_ROOT_DIR
|
||||
|
||||
# global dependencies
|
||||
GLOBAL_DEPS = ["git", "wget", "curl", "unzip", "dfu-util", "python3-virtualenv"]
|
||||
|
||||
@@ -24,7 +22,6 @@ CURRENT_USER = pwd.getpwuid(os.getuid())[0]
|
||||
|
||||
# dirs
|
||||
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_ENABLED = Path("/etc/nginx/sites-enabled")
|
||||
NGINX_CONFD = Path("/etc/nginx/conf.d")
|
||||
|
||||
@@ -16,8 +16,9 @@ from typing import List
|
||||
|
||||
from utils.fs_utils import get_data_dir
|
||||
|
||||
SUFFIX_BLACKLIST: List[str] = ["None", "mcu", "obico", "bambu", "companion"]
|
||||
|
||||
# suffixes that are not allowed to be used for instances
|
||||
# because they would cause conflicts with other components or are reserved
|
||||
SUFFIX_BLACKLIST: List[str] = ["None", "mcu", "obico", "bambu", "companion", "hmi"]
|
||||
|
||||
@dataclass(repr=True)
|
||||
class BaseInstance:
|
||||
|
||||
@@ -25,8 +25,8 @@ from components.webui_client.fluidd_data import FluiddData
|
||||
from components.webui_client.mainsail_data import MainsailData
|
||||
from core.menus import Option
|
||||
from core.menus.base_menu import BaseMenu
|
||||
from core.services.backup_service import BackupService
|
||||
from core.types.color import Color
|
||||
from utils.common import backup_printer_config_dir
|
||||
|
||||
|
||||
# noinspection PyUnusedLocal
|
||||
@@ -58,7 +58,7 @@ class BackupMenu(BaseMenu):
|
||||
|
||||
def print_menu(self) -> None:
|
||||
line1 = Color.apply(
|
||||
"INFO: Backups are located in '~/kiauh-backups'", Color.YELLOW
|
||||
"INFO: Backups are located in '~/kiauh_backups'", Color.YELLOW
|
||||
)
|
||||
menu = textwrap.dedent(
|
||||
f"""
|
||||
@@ -86,7 +86,7 @@ class BackupMenu(BaseMenu):
|
||||
backup_moonraker_dir()
|
||||
|
||||
def backup_printer_config(self, **kwargs) -> None:
|
||||
backup_printer_config_dir()
|
||||
BackupService().backup_printer_config_dir()
|
||||
|
||||
def backup_moonraker_db(self, **kwargs) -> None:
|
||||
backup_moonraker_db_dir()
|
||||
|
||||
198
kiauh/core/services/backup_service.py
Normal file
198
kiauh/core/services/backup_service.py
Normal file
@@ -0,0 +1,198 @@
|
||||
# ======================================================================= #
|
||||
# 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}"
|
||||
)
|
||||
|
||||
backup_dir = self._backup_root
|
||||
if target_path is not None:
|
||||
backup_dir = self._backup_root.joinpath(target_path)
|
||||
|
||||
backup_dir.mkdir(parents=True, exist_ok=True)
|
||||
shutil.copy2(source_path, backup_dir.joinpath(filename))
|
||||
|
||||
Logger.print_ok(
|
||||
f"Successfully backed up '{source_path}' to '{backup_dir}'"
|
||||
)
|
||||
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)
|
||||
|
||||
if backup_path.exists():
|
||||
Logger.print_info(f"Reusing existing backup directory '{backup_path}'")
|
||||
|
||||
shutil.copytree(
|
||||
source_path,
|
||||
backup_path,
|
||||
dirs_exist_ok=True,
|
||||
symlinks=True,
|
||||
ignore_dangling_symlinks=True,
|
||||
)
|
||||
|
||||
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.moonraker import MOONRAKER_REPO_URL
|
||||
from core.backup_manager.backup_manager import BackupManager
|
||||
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 (
|
||||
SimpleConfigParser,
|
||||
)
|
||||
@@ -254,32 +254,34 @@ class KiauhSettings:
|
||||
section: str,
|
||||
option: str,
|
||||
getter: Callable[[str, str, T | None], T],
|
||||
fallback: T = None,
|
||||
fallback: T | None = None,
|
||||
silent: bool = False,
|
||||
) -> T:
|
||||
) -> T | None:
|
||||
if not self.__check_option_exists(section, option, fallback, silent):
|
||||
return fallback
|
||||
return getter(section, option, fallback)
|
||||
|
||||
def __set_repo_state(self, section: str, repos: List[str]) -> List[Repository]:
|
||||
_repos: List[Repository] = []
|
||||
for repo in repos:
|
||||
try:
|
||||
if repo.strip().startswith("#") or repo.strip().startswith(";"):
|
||||
continue
|
||||
if "," in repo:
|
||||
url, branch = repo.strip().split(",")
|
||||
for raw in repos:
|
||||
line = raw.strip()
|
||||
|
||||
if not branch:
|
||||
branch = "master"
|
||||
if not line or line.startswith("#") or line.startswith(";"):
|
||||
continue
|
||||
|
||||
try:
|
||||
if "," in line:
|
||||
url_part, branch_part = line.split(",")
|
||||
url = url_part.strip()
|
||||
branch = branch_part.strip() or "master"
|
||||
else:
|
||||
url = repo.strip()
|
||||
url = line
|
||||
branch = "master"
|
||||
|
||||
# url must not be empty otherwise it's considered
|
||||
# as an unrecoverable, invalid configuration
|
||||
if not url:
|
||||
raise InvalidValueError(section, "repositories", repo)
|
||||
raise InvalidValueError(section, "repositories", line)
|
||||
|
||||
_repos.append(Repository(url.strip(), branch.strip()))
|
||||
|
||||
@@ -374,8 +376,8 @@ class KiauhSettings:
|
||||
kill()
|
||||
|
||||
def _migrate_repo_config(self) -> None:
|
||||
bm = BackupManager()
|
||||
if not bm.backup_file(CUSTOM_CFG):
|
||||
svc = BackupService()
|
||||
if not svc.backup_file(CUSTOM_CFG):
|
||||
Logger.print_dialog(
|
||||
DialogType.ERROR,
|
||||
[
|
||||
|
||||
@@ -10,41 +10,10 @@ Specialized for handling Klipper style config files.
|
||||
- Section: A section is defined by a line starting with a `[` and ending with a `]`
|
||||
- Option: A line starting with a word, followed by a `:` or `=` and a value
|
||||
- Option Block: A line starting with a word, followed by a `:` or `=` and a newline
|
||||
- The word `gcode` is excluded from being treated as an option block
|
||||
- Gcode Block: A line starting with the word `gcode`, followed by a `:` or `=` and a newline
|
||||
- All indented lines following the gcode line are considered part of the gcode block
|
||||
- Comment: A line starting with a `#` or `;`
|
||||
- Blank: A line containing only whitespace characters
|
||||
- SaveConfig Block: Klippers auto-generated SAVE_CONFIG section that can be found at the very end of the config file
|
||||
|
||||
---
|
||||
|
||||
### Internally, the config is stored as a dictionary of sections, each containing a header and a list of elements:
|
||||
```python
|
||||
config = {
|
||||
"section_name": {
|
||||
"header": "[section_name]\n",
|
||||
"elements": [
|
||||
{
|
||||
"type": "comment",
|
||||
"content": "# This is a comment\n"
|
||||
},
|
||||
{
|
||||
"type": "option",
|
||||
"name": "option1",
|
||||
"value": "value1",
|
||||
"raw": "option1: value1\n"
|
||||
},
|
||||
{
|
||||
"type": "blank",
|
||||
"content": "\n"
|
||||
},
|
||||
{
|
||||
"type": "option_block",
|
||||
"name": "option2",
|
||||
"value": [
|
||||
"value2",
|
||||
"value3"
|
||||
],
|
||||
"raw": "option2:"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
# ======================================================================= #
|
||||
# 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 #
|
||||
# ======================================================================= #
|
||||
import re
|
||||
from enum import Enum
|
||||
|
||||
# definition of section line:
|
||||
# - then line MUST start with an opening square bracket - it is the first section marker
|
||||
# - the section marker MUST be followed by at least one character - it is the section name
|
||||
# - the section name MUST be followed by a closing square bracket - it is the second section marker
|
||||
# - the second section marker MAY be followed by any amount of whitespace characters
|
||||
# - the second section marker MAY be followed by a # or ; - it is the comment marker
|
||||
# - the inline comment MAY be of any length and character
|
||||
SECTION_RE = re.compile(r"^\[(\S.*\S|\S)]\s*([#;].*)?$")
|
||||
|
||||
# definition of option line:
|
||||
# - the line MUST start with a word - it is the option name
|
||||
# - the option name MUST be followed by a colon or an equal sign - it is the separator
|
||||
# - the separator MUST be followed by a value
|
||||
# - the separator MAY have any amount of leading or trailing whitespaces
|
||||
# - the separator MUST NOT be directly followed by a colon or equal sign
|
||||
# - the value MAY be of any length and character
|
||||
# - the value MAY contain any amount of trailing whitespaces
|
||||
# - the value MAY be followed by a # or ; - it is the comment marker
|
||||
# - the inline comment MAY be of any length and character
|
||||
OPTION_RE = re.compile(r"^([^;#:=\s]+)\s?[:=]\s*([^;#:=\s][^;#]*?)\s*([#;].*)?$")
|
||||
# definition of options block start line:
|
||||
# - the line MUST start with a word - it is the option name
|
||||
# - the option name MUST be followed by a colon or an equal sign - it is the separator
|
||||
# - the separator MUST NOT be followed by a value
|
||||
# - the separator MAY have any amount of leading or trailing whitespaces
|
||||
# - the separator MUST NOT be directly followed by a colon or equal sign
|
||||
# - the separator MAY be followed by a # or ; - it is the comment marker
|
||||
# - the inline comment MAY be of any length and character
|
||||
OPTIONS_BLOCK_START_RE = re.compile(r"^([^;#:=\s]+)\s*[:=]\s*([#;].*)?$")
|
||||
|
||||
# definition of comment line:
|
||||
# - the line MAY start with any amount of whitespace characters
|
||||
# - the line MUST contain a # or ; - it is the comment marker
|
||||
# - the comment marker MAY be followed by any amount of whitespace characters
|
||||
# - the comment MAY be of any length and character
|
||||
LINE_COMMENT_RE = re.compile(r"^\s*[#;].*")
|
||||
|
||||
# definition of empty line:
|
||||
# - the line MUST contain only whitespace characters
|
||||
EMPTY_LINE_RE = re.compile(r"^\s*$")
|
||||
|
||||
BOOLEAN_STATES = {
|
||||
"1": True,
|
||||
"yes": True,
|
||||
"true": True,
|
||||
"on": True,
|
||||
"0": False,
|
||||
"no": False,
|
||||
"false": False,
|
||||
"off": False,
|
||||
}
|
||||
|
||||
HEADER_IDENT = "#_header"
|
||||
|
||||
INDENT = " " * 4
|
||||
|
||||
class LineType(Enum):
|
||||
OPTION = "option"
|
||||
OPTION_BLOCK = "option_block"
|
||||
COMMENT = "comment"
|
||||
BLANK = "blank"
|
||||
@@ -1,5 +1,5 @@
|
||||
# ======================================================================= #
|
||||
# Copyright (C) 2024 Dominik Willner <th33xitus@gmail.com> #
|
||||
# Copyright (C) 2025 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# https://github.com/dw-0/simple-config-parser #
|
||||
# #
|
||||
@@ -8,19 +8,89 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from dataclasses import dataclass, field
|
||||
from enum import Enum
|
||||
from pathlib import Path
|
||||
from typing import Callable, Dict, List
|
||||
from typing import Any, Callable, Dict, List, Set, Union
|
||||
|
||||
from ..simple_config_parser.constants import (
|
||||
BOOLEAN_STATES,
|
||||
EMPTY_LINE_RE,
|
||||
HEADER_IDENT,
|
||||
LINE_COMMENT_RE,
|
||||
OPTION_RE,
|
||||
OPTIONS_BLOCK_START_RE,
|
||||
SECTION_RE, LineType, INDENT,
|
||||
# definition of section line:
|
||||
# - the line MUST start with an opening square bracket - it is the first section marker
|
||||
# - the section marker MUST be followed by at least one character - it is the section name
|
||||
# - the section name MUST be followed by a closing square bracket - it is the second section marker
|
||||
# - the second section marker MAY be followed by any amount of whitespace characters
|
||||
# - the second section marker MAY be followed by a # or ; - it is the comment marker
|
||||
# - the inline comment MAY be of any length and character
|
||||
SECTION_RE = re.compile(r"^\[(\S.*\S|\S)]\s*([#;].*)?$")
|
||||
|
||||
# definition of option line:
|
||||
# - the line MUST start with a word - it is the option name
|
||||
# - the option name MUST be followed by a colon or an equal sign - it is the separator
|
||||
# - the separator MUST be followed by a value
|
||||
# - the separator MAY have any amount of leading or trailing whitespaces
|
||||
# - the separator MUST NOT be directly followed by a colon or equal sign
|
||||
# - the value MAY be of any length and character
|
||||
# - the value MAY contain any amount of trailing whitespaces
|
||||
# - the value MAY be followed by a # or ; - it is the comment marker
|
||||
# - the inline comment MAY be of any length and character
|
||||
OPTION_RE = re.compile(r"^([^;#:=\s]+)\s?[:=]\s*([^;#:=\s][^;#]*?)\s*([#;].*)?$")
|
||||
|
||||
# definition of options block start line:
|
||||
# - the line MUST start with a word - it is the option name
|
||||
# - the option name MUST NOT be "gcode"
|
||||
# - the option name MUST be followed by a colon or an equal sign - it is the separator
|
||||
# - the separator MUST NOT be followed by a value
|
||||
# - the separator MAY have any amount of leading or trailing whitespaces
|
||||
# - the separator MUST NOT be directly followed by a colon or equal sign
|
||||
# - the separator MAY be followed by a # or ; - it is the comment marker
|
||||
# - the inline comment MAY be of any length and character
|
||||
OPTIONS_BLOCK_START_RE = re.compile(
|
||||
r"^(?!\s*gcode\s*[:=])([^;#:=\s]+)\s*[:=]\s*([#;].*)?$"
|
||||
)
|
||||
|
||||
# definition of gcode block start line:
|
||||
# - the line MUST start with the word "gcode"
|
||||
# - the word "gcode" MUST be followed by a colon or an equal sign - it is the separator
|
||||
# - the separator MUST NOT be followed by a value
|
||||
# - the separator MAY have any amount of leading or trailing whitespaces
|
||||
# - the separator MUST NOT be directly followed by a colon or equal sign
|
||||
# - the separator MAY be followed by a # or ; - it is the comment marker
|
||||
# - the inline comment MAY be of any length and character
|
||||
GCODE_BLOCK_START_RE = re.compile(r"^\s*gcode\s*[:=]\s*(?:[#;].*)?$")
|
||||
|
||||
# definition of comment line:
|
||||
# - the line MAY start with any amount of whitespace characters
|
||||
# - the line MUST contain a # or ; - it is the comment marker
|
||||
# - the comment marker MAY be followed by any amount of whitespace characters
|
||||
# - the comment MAY be of any length and character
|
||||
LINE_COMMENT_RE = re.compile(r"^\s*[#;].*")
|
||||
|
||||
# definition of empty line:
|
||||
# - the line MUST contain only whitespace characters
|
||||
EMPTY_LINE_RE = re.compile(r"^\s*$")
|
||||
|
||||
SAVE_CONFIG_START_RE = re.compile(r"^#\*# <-+ SAVE_CONFIG -+>$")
|
||||
SAVE_CONFIG_CONTENT_RE = re.compile(r"^#\*#.*$")
|
||||
|
||||
BOOLEAN_STATES = {
|
||||
"1": True,
|
||||
"yes": True,
|
||||
"true": True,
|
||||
"on": True,
|
||||
"0": False,
|
||||
"no": False,
|
||||
"false": False,
|
||||
"off": False,
|
||||
}
|
||||
|
||||
|
||||
class LineType(Enum):
|
||||
OPTION = "option"
|
||||
OPTION_BLOCK = "option_block"
|
||||
COMMENT = "comment"
|
||||
BLANK = "blank"
|
||||
|
||||
|
||||
_UNSET = object()
|
||||
|
||||
|
||||
@@ -47,6 +117,7 @@ class NoOptionError(Exception):
|
||||
msg = f"Option '{option}' in section '{section}' is not defined"
|
||||
super().__init__(msg)
|
||||
|
||||
|
||||
class UnknownLineError(Exception):
|
||||
"""Raised when a line is not recognized as any known type"""
|
||||
|
||||
@@ -55,31 +126,108 @@ class UnknownLineError(Exception):
|
||||
super().__init__(msg)
|
||||
|
||||
|
||||
@dataclass
|
||||
class Option:
|
||||
"""Dataclass representing a (pseudo) config option"""
|
||||
|
||||
name: str
|
||||
raw: str
|
||||
value: str
|
||||
|
||||
|
||||
@dataclass
|
||||
class MultiLineOption:
|
||||
"""Dataclass representing a multi-line config option"""
|
||||
|
||||
name: str
|
||||
raw: str
|
||||
values: List[MLOptionValue] = field(default_factory=list)
|
||||
|
||||
|
||||
@dataclass
|
||||
class MLOptionValue:
|
||||
"""Dataclass representing a value in a multi-line option"""
|
||||
|
||||
raw: str
|
||||
indent: int
|
||||
value: str
|
||||
|
||||
|
||||
@dataclass
|
||||
class Gcode:
|
||||
"""Dataclass representing a gcode block"""
|
||||
|
||||
name: str
|
||||
raw: str
|
||||
gcode: List[str] = field(default_factory=list)
|
||||
|
||||
|
||||
@dataclass
|
||||
class BlankLine:
|
||||
"""Dataclass representing a blank line"""
|
||||
|
||||
raw: str = "\n"
|
||||
|
||||
|
||||
@dataclass
|
||||
class CommentLine:
|
||||
"""Dataclass representing a comment line"""
|
||||
|
||||
raw: str
|
||||
|
||||
|
||||
SectionItem = Union[Option, MultiLineOption, Gcode, BlankLine, CommentLine]
|
||||
|
||||
|
||||
@dataclass
|
||||
class Section:
|
||||
"""Dataclass representing a config section"""
|
||||
|
||||
name: str
|
||||
raw: str
|
||||
items: List[SectionItem] = field(default_factory=list)
|
||||
|
||||
|
||||
# noinspection PyMethodMayBeStatic
|
||||
class SimpleConfigParser:
|
||||
"""A customized config parser targeted at handling Klipper style config files"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.header: List[str] = []
|
||||
self.config: Dict = {}
|
||||
self.current_section: str | None = None
|
||||
self.current_opt_block: str | None = None
|
||||
self.in_option_block: bool = False
|
||||
|
||||
self._header: List[str] = []
|
||||
self._save_config_block: List[str] = []
|
||||
self._config: List[Section] = []
|
||||
self._curr_sect: Union[Section, None] = None
|
||||
self._curr_ml_opt: Union[MultiLineOption, None] = None
|
||||
self._curr_gcode: Union[Gcode, None] = None
|
||||
|
||||
def _match_section(self, line: str) -> bool:
|
||||
"""Wheter or not the given line matches the definition of a section"""
|
||||
"""Whether the given line matches the definition of a section"""
|
||||
return SECTION_RE.match(line) is not None
|
||||
|
||||
def _match_option(self, line: str) -> bool:
|
||||
"""Wheter or not the given line matches the definition of an option"""
|
||||
"""Whether the given line matches the definition of an option"""
|
||||
return OPTION_RE.match(line) is not None
|
||||
|
||||
def _match_options_block_start(self, line: str) -> bool:
|
||||
"""Wheter or not the given line matches the definition of a multiline option"""
|
||||
"""Whether the given line matches the definition of a multiline option"""
|
||||
return OPTIONS_BLOCK_START_RE.match(line) is not None
|
||||
|
||||
def _match_gcode_block_start(self, line: str) -> bool:
|
||||
"""Whether the given line matches the definition of a gcode block start"""
|
||||
return GCODE_BLOCK_START_RE.match(line) is not None
|
||||
|
||||
def _match_save_config_start(self, line: str) -> bool:
|
||||
"""Whether the given line matches the definition of a save config start"""
|
||||
return SAVE_CONFIG_START_RE.match(line) is not None
|
||||
|
||||
def _match_save_config_content(self, line: str) -> bool:
|
||||
"""Whether the given line matches the definition of a save config content"""
|
||||
return SAVE_CONFIG_CONTENT_RE.match(line) is not None
|
||||
|
||||
def _match_line_comment(self, line: str) -> bool:
|
||||
"""Wheter or not the given line matches the definition of a comment"""
|
||||
"""Whether the given line matches the definition of a comment"""
|
||||
return LINE_COMMENT_RE.match(line) is not None
|
||||
|
||||
def _match_empty_line(self, line: str) -> bool:
|
||||
@@ -88,59 +236,112 @@ class SimpleConfigParser:
|
||||
|
||||
def _parse_line(self, line: str) -> None:
|
||||
"""Parses a line and determines its type"""
|
||||
if self._curr_sect is None and not self._match_section(line):
|
||||
# we are at the beginning of the file, so we consider the part
|
||||
# up to the first section as the file header and store it separately
|
||||
self._header.append(line)
|
||||
return
|
||||
|
||||
if self._match_section(line):
|
||||
self.current_opt_block = None
|
||||
self.current_section = SECTION_RE.match(line).group(1)
|
||||
self.config[self.current_section] = {
|
||||
"header": line,
|
||||
"elements": []
|
||||
}
|
||||
self._reset_special_items()
|
||||
|
||||
elif self._match_option(line):
|
||||
self.current_opt_block = None
|
||||
option = OPTION_RE.match(line).group(1)
|
||||
value = OPTION_RE.match(line).group(2)
|
||||
self.config[self.current_section]["elements"].append({
|
||||
"type": LineType.OPTION.value,
|
||||
"name": option,
|
||||
"value": value,
|
||||
"raw": line
|
||||
})
|
||||
sect_name: str = SECTION_RE.match(line).group(1)
|
||||
sect = Section(name=sect_name, raw=line)
|
||||
self._curr_sect = sect
|
||||
self._config.append(sect)
|
||||
return
|
||||
|
||||
elif self._match_options_block_start(line):
|
||||
option = OPTIONS_BLOCK_START_RE.match(line).group(1)
|
||||
self.current_opt_block = option
|
||||
self.config[self.current_section]["elements"].append({
|
||||
"type": LineType.OPTION_BLOCK.value,
|
||||
"name": option,
|
||||
"value": [],
|
||||
"raw": line
|
||||
})
|
||||
if self._match_option(line):
|
||||
self._reset_special_items()
|
||||
|
||||
elif self.current_opt_block is not None:
|
||||
# we are in an option block, so we add the line to the option's value
|
||||
for element in reversed(self.config[self.current_section]["elements"]):
|
||||
if element["type"] == LineType.OPTION_BLOCK.value and element["name"] == self.current_opt_block:
|
||||
element["value"].append(line.strip()) # indentation is removed
|
||||
break
|
||||
name: str = OPTION_RE.match(line).group(1)
|
||||
val: str = OPTION_RE.match(line).group(2)
|
||||
opt = Option(
|
||||
name=name,
|
||||
raw=line,
|
||||
value=val,
|
||||
)
|
||||
self._curr_sect.items.append(opt)
|
||||
return
|
||||
|
||||
elif self._match_empty_line(line) or self._match_line_comment(line):
|
||||
self.current_opt_block = None
|
||||
if self._match_options_block_start(line):
|
||||
self._reset_special_items()
|
||||
|
||||
# if current_section is None, we are at the beginning of the file,
|
||||
# so we consider the part up to the first section as the file header
|
||||
if not self.current_section:
|
||||
self.config.setdefault(HEADER_IDENT, []).append(line)
|
||||
name: str = OPTIONS_BLOCK_START_RE.match(line).group(1)
|
||||
ml_opt = MultiLineOption(
|
||||
name=name,
|
||||
raw=line,
|
||||
)
|
||||
self._curr_ml_opt = ml_opt
|
||||
self._curr_sect.items.append(ml_opt)
|
||||
return
|
||||
|
||||
if self._curr_ml_opt is not None:
|
||||
# we are in an option block, so we consecutively add values
|
||||
# to the current multiline option until we hit a different line type
|
||||
|
||||
if "#" in line:
|
||||
value = line.split("#", 1)[0].strip()
|
||||
elif ";" in line:
|
||||
value = line.split(";", 1)[0].strip()
|
||||
else:
|
||||
element_type = LineType.BLANK.value if self._match_empty_line(line) else LineType.COMMENT.value
|
||||
self.config[self.current_section]["elements"].append({
|
||||
"type": element_type,
|
||||
"content": line
|
||||
})
|
||||
value = line.strip()
|
||||
|
||||
ml_value = MLOptionValue(
|
||||
raw=line,
|
||||
indent=self._get_indent(line),
|
||||
value=value,
|
||||
)
|
||||
self._curr_ml_opt.values.append(ml_value)
|
||||
return
|
||||
|
||||
if self._match_gcode_block_start(line):
|
||||
self._curr_gcode = Gcode(
|
||||
name="gcode",
|
||||
raw=line,
|
||||
)
|
||||
self._curr_sect.items.append(self._curr_gcode)
|
||||
return
|
||||
|
||||
if self._curr_gcode is not None:
|
||||
# we are in a gcode block, so we add any following line
|
||||
# without further checks to the gcode block
|
||||
self._curr_gcode.gcode.append(line)
|
||||
return
|
||||
|
||||
if self._match_save_config_start(line):
|
||||
self._reset_special_items()
|
||||
self._save_config_block.append(line)
|
||||
return
|
||||
|
||||
if self._match_save_config_content(line):
|
||||
self._reset_special_items()
|
||||
self._save_config_block.append(line)
|
||||
return
|
||||
|
||||
if self._match_empty_line(line):
|
||||
self._reset_special_items()
|
||||
self._curr_sect.items.append(BlankLine(raw=line))
|
||||
return
|
||||
|
||||
if self._match_line_comment(line):
|
||||
self._reset_special_items()
|
||||
self._curr_sect.items.append(CommentLine(raw=line))
|
||||
return
|
||||
|
||||
def _reset_special_items(self) -> None:
|
||||
"""Reset special items like current multine option and gcode block"""
|
||||
self._curr_ml_opt = None
|
||||
self._curr_gcode = None
|
||||
|
||||
def _get_indent(self, line: str) -> int:
|
||||
"""Return the indentation level of a line"""
|
||||
return len(line) - len(line.lstrip())
|
||||
|
||||
def read_file(self, file: Path) -> None:
|
||||
"""Read and parse a config file"""
|
||||
with open(file, "r") as file:
|
||||
self._config = []
|
||||
with open(file, "r", encoding="utf-8") as file:
|
||||
for line in file:
|
||||
self._parse_line(line)
|
||||
|
||||
@@ -149,110 +350,72 @@ class SimpleConfigParser:
|
||||
if path is None:
|
||||
raise ValueError("File path cannot be None")
|
||||
|
||||
with open(path, "w", encoding="utf-8") as f:
|
||||
if HEADER_IDENT in self.config:
|
||||
for line in self.config[HEADER_IDENT]:
|
||||
f.write(line)
|
||||
# first write the header
|
||||
content: List[str] = list(self._header)
|
||||
|
||||
sections = self.get_sections()
|
||||
for i, section in enumerate(sections):
|
||||
f.write(self.config[section]["header"])
|
||||
# then write all sections
|
||||
for i in self._config:
|
||||
content.append(i.raw)
|
||||
for item in i.items:
|
||||
content.append(item.raw)
|
||||
if isinstance(item, MultiLineOption):
|
||||
content.extend(val.raw for val in item.values)
|
||||
elif isinstance(item, Gcode):
|
||||
content.extend(item.gcode)
|
||||
|
||||
for element in self.config[section]["elements"]:
|
||||
if element["type"] == LineType.OPTION.value:
|
||||
f.write(element["raw"])
|
||||
elif element["type"] == LineType.OPTION_BLOCK.value:
|
||||
f.write(element["raw"])
|
||||
for line in element["value"]:
|
||||
f.write(INDENT + line.strip() + "\n")
|
||||
elif element["type"] in [LineType.COMMENT.value, LineType.BLANK.value]:
|
||||
f.write(element["content"])
|
||||
else:
|
||||
raise UnknownLineError(element["raw"])
|
||||
# then write the save config block
|
||||
content.extend(self._save_config_block)
|
||||
|
||||
# Ensure file ends with a single newline
|
||||
if sections: # Only if we have any sections
|
||||
last_section = sections[-1]
|
||||
last_elements = self.config[last_section]["elements"]
|
||||
# ensure file ends with a newline
|
||||
if content and not content[-1].endswith("\n"):
|
||||
content.append("\n")
|
||||
|
||||
if last_elements:
|
||||
last_element = last_elements[-1]
|
||||
if "raw" in last_element:
|
||||
last_line = last_element["raw"]
|
||||
else: # comment or blank line
|
||||
last_line = last_element["content"]
|
||||
with open(path, "w", encoding="utf-8", newline="\n") as f:
|
||||
f.writelines(content)
|
||||
|
||||
if not last_line.endswith("\n"):
|
||||
f.write("\n")
|
||||
|
||||
def get_sections(self) -> List[str]:
|
||||
"""Return a list of all section names, but exclude any section starting with '#_'"""
|
||||
return list(
|
||||
filter(
|
||||
lambda section: not section.startswith("#_"),
|
||||
self.config.keys(),
|
||||
)
|
||||
)
|
||||
def get_sections(self) -> Set[str]:
|
||||
"""Return a set of all section names"""
|
||||
return {s.name for s in self._config} if self._config else set()
|
||||
|
||||
def has_section(self, section: str) -> bool:
|
||||
"""Check if a section exists"""
|
||||
return section in self.get_sections()
|
||||
|
||||
def add_section(self, section: str) -> None:
|
||||
def add_section(self, section: str) -> Section:
|
||||
"""Add a new section to the config"""
|
||||
if section in self.get_sections():
|
||||
raise DuplicateSectionError(section)
|
||||
|
||||
if len(self.get_sections()) >= 1:
|
||||
self._check_set_section_spacing()
|
||||
if not self._config:
|
||||
new_sect = Section(name=section, raw=f"[{section}]\n")
|
||||
self._config.append(new_sect)
|
||||
return new_sect
|
||||
|
||||
self.config[section] = {
|
||||
"header": f"[{section}]\n",
|
||||
"elements": []
|
||||
}
|
||||
last_sect: Section = self._config[-1]
|
||||
if not last_sect.items or (
|
||||
last_sect.items and not isinstance(last_sect.items[-1], BlankLine)
|
||||
):
|
||||
last_sect.items.append(BlankLine())
|
||||
|
||||
def _check_set_section_spacing(self):
|
||||
"""Check if there is a blank line between the last section and the new section"""
|
||||
prev_section_name: str = self.get_sections()[-1]
|
||||
prev_section = self.config[prev_section_name]
|
||||
prev_elements = prev_section["elements"]
|
||||
|
||||
if prev_elements:
|
||||
last_element = prev_elements[-1]
|
||||
|
||||
# If the last element is a comment or blank line
|
||||
if last_element["type"] in [LineType.COMMENT.value, LineType.BLANK.value]:
|
||||
last_content = last_element["content"]
|
||||
|
||||
# If the last element doesn't end with a newline, add one
|
||||
if not last_content.endswith("\n"):
|
||||
last_element["content"] += "\n"
|
||||
|
||||
# If the last element is not a blank line, add a blank line
|
||||
if last_content.strip() != "":
|
||||
prev_elements.append({
|
||||
"type": "blank",
|
||||
"content": "\n"
|
||||
})
|
||||
else:
|
||||
# If the last element is an option, add a blank line
|
||||
prev_elements.append({
|
||||
"type": LineType.BLANK.value,
|
||||
"content": "\n"
|
||||
})
|
||||
new_sect = Section(name=section, raw=f"[{section}]\n")
|
||||
self._config.append(new_sect)
|
||||
return new_sect
|
||||
|
||||
def remove_section(self, section: str) -> None:
|
||||
"""Remove a section from the config"""
|
||||
self.config.pop(section, None)
|
||||
"""Remove a section from the config
|
||||
|
||||
def get_options(self, section: str) -> List[str]:
|
||||
"""Return a list of all option names for a given section"""
|
||||
options = []
|
||||
if self.has_section(section):
|
||||
for element in self.config[section]["elements"]:
|
||||
if element["type"] in [LineType.OPTION.value, LineType.OPTION_BLOCK.value]:
|
||||
options.append(element["name"])
|
||||
return options
|
||||
This will remove ALL occurences of sections with the given name.
|
||||
"""
|
||||
self._config = [s for s in self._config if s.name != section]
|
||||
|
||||
def get_options(self, section: str) -> Set[str]:
|
||||
"""Return a set of all option names for a given section"""
|
||||
sections: List[Section] = [s for s in self._config if s.name == section]
|
||||
all_items: List[SectionItem] = [
|
||||
item for section in sections for item in section.items
|
||||
]
|
||||
|
||||
return {o.name for o in all_items if isinstance(o, (Option, MultiLineOption))}
|
||||
|
||||
def has_option(self, section: str, option: str) -> bool:
|
||||
"""Check if an option exists in a section"""
|
||||
@@ -263,56 +426,141 @@ class SimpleConfigParser:
|
||||
Set the value of an option in a section. If the section does not exist,
|
||||
it is created. If the option does not exist, it is created.
|
||||
"""
|
||||
if not self.has_section(section):
|
||||
|
||||
# when adding options, we add them to the first matching section
|
||||
# if the section does not exist, we create it
|
||||
section: Section = (
|
||||
self.add_section(section)
|
||||
if not self.has_section(section)
|
||||
else next(s for s in self._config if s.name == section)
|
||||
)
|
||||
|
||||
# Check if option already exists
|
||||
for element in self.config[section]["elements"]:
|
||||
if element["type"] in [LineType.OPTION.value, LineType.OPTION_BLOCK.value] and element["name"] == option:
|
||||
# Update existing option
|
||||
opt = self._find_option_by_name(option, section=section)
|
||||
if opt is None:
|
||||
if isinstance(value, list):
|
||||
element["type"] = LineType.OPTION_BLOCK.value
|
||||
element["value"] = value
|
||||
element["raw"] = f"{option}:\n"
|
||||
indent = 4
|
||||
_opt = MultiLineOption(
|
||||
name=option,
|
||||
raw=f"{option}:\n",
|
||||
values=[
|
||||
MLOptionValue(
|
||||
raw=f"{' ' * indent}{val}\n",
|
||||
indent=indent,
|
||||
value=val,
|
||||
)
|
||||
for val in value
|
||||
],
|
||||
)
|
||||
else:
|
||||
element["type"] = LineType.OPTION.value
|
||||
element["value"] = value
|
||||
element["raw"] = f"{option}: {value}\n"
|
||||
return
|
||||
_opt = Option(
|
||||
name=option,
|
||||
raw=f"{option}: {value}\n",
|
||||
value=value,
|
||||
)
|
||||
|
||||
# Option doesn't exist, create new one
|
||||
if isinstance(value, list):
|
||||
new_element = {
|
||||
"type": LineType.OPTION_BLOCK.value,
|
||||
"name": option,
|
||||
"value": value,
|
||||
"raw": f"{option}:\n"
|
||||
}
|
||||
last_opt_idx: int = 0
|
||||
for idx, item in enumerate(section.items):
|
||||
if isinstance(item, (Option, MultiLineOption)):
|
||||
last_opt_idx = idx
|
||||
# insert the new option after the last existing option
|
||||
section.items.insert(last_opt_idx + 1, _opt)
|
||||
|
||||
elif opt and isinstance(opt, Option) and isinstance(value, str):
|
||||
curr_val = opt.value
|
||||
new_val = value
|
||||
opt.value = new_val
|
||||
opt.raw = opt.raw.replace(curr_val, new_val)
|
||||
|
||||
elif opt and isinstance(opt, MultiLineOption) and isinstance(value, list):
|
||||
# note: we completely replace the existing values
|
||||
# so any existing indentation, comments, etc. will be lost
|
||||
indent = 4
|
||||
opt.values = [
|
||||
MLOptionValue(
|
||||
raw=f"{' ' * indent}{val}\n",
|
||||
indent=indent,
|
||||
value=val,
|
||||
)
|
||||
for val in value
|
||||
]
|
||||
|
||||
def _find_section_by_name(
|
||||
self, sect_name: str
|
||||
) -> Union[None, Section, List[Section]]:
|
||||
"""Find a section by name"""
|
||||
_sects = [s for s in self._config if s.name == sect_name]
|
||||
if len(_sects) > 1:
|
||||
return _sects
|
||||
elif len(_sects) == 1:
|
||||
return _sects[0]
|
||||
else:
|
||||
new_element = {
|
||||
"type": LineType.OPTION.value,
|
||||
"name": option,
|
||||
"value": value,
|
||||
"raw": f"{option}: {value}\n"
|
||||
}
|
||||
return None
|
||||
|
||||
# scan through elements to find the last option, after which we insert the new option
|
||||
insert_pos = 0
|
||||
elements = self.config[section]["elements"]
|
||||
for i, element in enumerate(elements):
|
||||
if element["type"] in [LineType.OPTION.value, LineType.OPTION_BLOCK.value]:
|
||||
insert_pos = i + 1
|
||||
def _find_option_by_name(
|
||||
self,
|
||||
opt_name: str,
|
||||
section: Union[Section, None] = None,
|
||||
sections: Union[List[Section], None] = None,
|
||||
) -> Union[None, Option, MultiLineOption]:
|
||||
"""Find an option or multi-line option by name in a section"""
|
||||
|
||||
elements.insert(insert_pos, new_element)
|
||||
# if a single section is provided, search its items for the option
|
||||
if section is not None:
|
||||
for item in section.items:
|
||||
if (
|
||||
isinstance(item, (Option, MultiLineOption))
|
||||
and item.name == opt_name
|
||||
):
|
||||
return item
|
||||
|
||||
# if multiple sections with the same name are provided, merge their
|
||||
# items and search for the option
|
||||
if sections is not None:
|
||||
all_items: List[SectionItem] = [
|
||||
item for sect in sections for item in sect.items
|
||||
]
|
||||
for item in all_items:
|
||||
if (
|
||||
isinstance(item, (Option, MultiLineOption))
|
||||
and item.name == opt_name
|
||||
):
|
||||
return item
|
||||
|
||||
return None
|
||||
|
||||
def remove_option(self, section: str, option: str) -> None:
|
||||
"""Remove an option from a section"""
|
||||
if self.has_section(section):
|
||||
elements = self.config[section]["elements"]
|
||||
for i, element in enumerate(elements):
|
||||
if element["type"] in [LineType.OPTION.value, LineType.OPTION_BLOCK.value] and element["name"] == option:
|
||||
elements.pop(i)
|
||||
break
|
||||
"""Remove an option from a section
|
||||
|
||||
This will remove the option from ALL occurences of sections with the given name.
|
||||
Other non-option items (comments, blank lines, etc.) are preserved.
|
||||
"""
|
||||
sections: List[Section] = [s for s in self._config if s.name == section]
|
||||
if not sections:
|
||||
return
|
||||
|
||||
for sect in sections:
|
||||
sect.items = [
|
||||
item
|
||||
for item in sect.items
|
||||
if not (
|
||||
isinstance(item, (Option, MultiLineOption)) and item.name == option
|
||||
)
|
||||
]
|
||||
|
||||
def _get_option(
|
||||
self, section: str, option: str
|
||||
) -> Union[Option, MultiLineOption, None]:
|
||||
"""Internal helper to resolve an option or multi-line option."""
|
||||
if section not in self.get_sections():
|
||||
raise NoSectionError(section)
|
||||
if option not in self.get_options(section):
|
||||
raise NoOptionError(option, section)
|
||||
sects: List[Section] = [s for s in self._config if s.name == section]
|
||||
return (
|
||||
self._find_option_by_name(option, sections=sects)
|
||||
if len(sects) > 1
|
||||
else self._find_option_by_name(option, section=sects[0])
|
||||
)
|
||||
|
||||
def getval(self, section: str, option: str, fallback: str | _UNSET = _UNSET) -> str:
|
||||
"""
|
||||
@@ -322,22 +570,20 @@ class SimpleConfigParser:
|
||||
a fallback value.
|
||||
"""
|
||||
try:
|
||||
if section not in self.get_sections():
|
||||
raise NoSectionError(section)
|
||||
if option not in self.get_options(section):
|
||||
opt = self._get_option(section, option)
|
||||
if not isinstance(opt, Option):
|
||||
raise NoOptionError(option, section)
|
||||
|
||||
for element in self.config[section]["elements"]:
|
||||
if element["type"] is LineType.OPTION.value and element["name"] == option:
|
||||
return str(element["value"].strip().replace("\n", ""))
|
||||
return ""
|
||||
return opt.value if opt else ""
|
||||
|
||||
except (NoSectionError, NoOptionError):
|
||||
if fallback is _UNSET:
|
||||
raise
|
||||
return fallback
|
||||
|
||||
def getvals(self, section: str, option: str, fallback: List[str] | _UNSET = _UNSET) -> List[str]:
|
||||
def getvals(
|
||||
self, section: str, option: str, fallback: List[str] | _UNSET = _UNSET
|
||||
) -> List[str]:
|
||||
"""
|
||||
Return the values of the given multi-line option in the given section
|
||||
|
||||
@@ -345,15 +591,11 @@ class SimpleConfigParser:
|
||||
a fallback value.
|
||||
"""
|
||||
try:
|
||||
if section not in self.get_sections():
|
||||
raise NoSectionError(section)
|
||||
if option not in self.get_options(section):
|
||||
opt = self._get_option(section, option)
|
||||
if not isinstance(opt, MultiLineOption):
|
||||
raise NoOptionError(option, section)
|
||||
|
||||
for element in self.config[section]["elements"]:
|
||||
if element["type"] is LineType.OPTION_BLOCK.value and element["name"] == option:
|
||||
return [val.strip() for val in element["value"] if val.strip()]
|
||||
return []
|
||||
return [v.value for v in opt.values] if opt else []
|
||||
|
||||
except (NoSectionError, NoOptionError):
|
||||
if fallback is _UNSET:
|
||||
@@ -391,7 +633,7 @@ class SimpleConfigParser:
|
||||
section: str,
|
||||
option: str,
|
||||
conv: Callable[[str], int | float | bool],
|
||||
fallback: _UNSET = _UNSET,
|
||||
fallback: Any = _UNSET,
|
||||
) -> int | float | bool:
|
||||
"""Return the value of the given option in the given section as a converted value"""
|
||||
try:
|
||||
|
||||
@@ -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,14 @@
|
||||
# Header line
|
||||
# Another header comment
|
||||
[toolhead]
|
||||
option_a: 1
|
||||
option_b: true
|
||||
|
||||
[gcode_macro test]
|
||||
gcode: # start gcode block
|
||||
G28 ; home all
|
||||
M118 Done ; echo
|
||||
G1 X10 Y10 F3000
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
gcode:
|
||||
gcode:
|
||||
gcode: # comment
|
||||
gcode: ; comment
|
||||
gcode :
|
||||
gcode :
|
||||
gcode : # comment
|
||||
gcode : ; comment
|
||||
gcode=
|
||||
gcode=
|
||||
gcode= # comment
|
||||
gcode= ; comment
|
||||
gcode =
|
||||
gcode =
|
||||
gcode = # comment
|
||||
gcode = ; comment
|
||||
@@ -0,0 +1,39 @@
|
||||
type: jsonfile
|
||||
path: /dev/shm/drying_box.json
|
||||
baud: 250000
|
||||
minimum_cruise_ratio: 0.5
|
||||
square_corner_velocity: 5.0
|
||||
full_steps_per_rotation: 200
|
||||
position_min: 0
|
||||
homing_speed: 5.0
|
||||
# baud: 250000
|
||||
# minimum_cruise_ratio: 0.5
|
||||
# square_corner_velocity: 5.0
|
||||
# full_steps_per_rotation: 200
|
||||
# position_min: 0
|
||||
# homing_speed: 5.0
|
||||
|
||||
option:
|
||||
option :
|
||||
option :
|
||||
option=
|
||||
option =
|
||||
option =
|
||||
|
||||
|
||||
### this is a comment
|
||||
; this is also a comment
|
||||
;
|
||||
#
|
||||
homing_speed::
|
||||
homing_speed::
|
||||
homing_speed ::
|
||||
homing_speed ::
|
||||
homing_speed==
|
||||
homing_speed==
|
||||
homing_speed ==
|
||||
homing_speed ==
|
||||
homing_speed :=
|
||||
homing_speed :=
|
||||
homing_speed =:
|
||||
homing_speed =:
|
||||
@@ -0,0 +1,39 @@
|
||||
# ======================================================================= #
|
||||
# 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()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("line", load_testdata_from_file(MATCHING_TEST_DATA_PATH))
|
||||
def test_match_gcode_block_start(parser, line):
|
||||
"""Test that a line matches the definition of an options block start"""
|
||||
assert parser._match_gcode_block_start(line) is True, (
|
||||
f"Expected line '{line}' to match gcode block start definition!"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("line", load_testdata_from_file(NON_MATCHING_TEST_DATA_PATH))
|
||||
def test_non_matching_gcode_block_start(parser, line):
|
||||
"""Test that a line does not match the definition of an options block start"""
|
||||
assert parser._match_gcode_block_start(line) is False, (
|
||||
f"Expected line '{line}' to not match gcode block start definition!"
|
||||
)
|
||||
@@ -1,5 +1,4 @@
|
||||
trusted_clients:
|
||||
gcode:
|
||||
cors_domains:
|
||||
an_options_block_start_with_comment: ; this is a comment
|
||||
an_options_block_start_with_comment: # this is a comment
|
||||
|
||||
@@ -29,3 +29,9 @@ homing_speed :=
|
||||
homing_speed :=
|
||||
homing_speed =:
|
||||
homing_speed =:
|
||||
gcode:
|
||||
gcode :
|
||||
gcode :
|
||||
gcode=
|
||||
gcode =
|
||||
gcode =
|
||||
|
||||
@@ -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}"
|
||||
@@ -5,75 +5,217 @@
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
# ======================================================================= #
|
||||
import json
|
||||
from pathlib import Path
|
||||
from typing import List
|
||||
|
||||
import pytest
|
||||
|
||||
from src.simple_config_parser.constants import HEADER_IDENT, LineType
|
||||
from src.simple_config_parser.simple_config_parser import SimpleConfigParser
|
||||
from tests.utils import load_testdata_from_file
|
||||
from src.simple_config_parser.simple_config_parser import (
|
||||
BlankLine,
|
||||
CommentLine,
|
||||
MLOptionValue,
|
||||
MultiLineOption,
|
||||
Option,
|
||||
Section,
|
||||
SimpleConfigParser,
|
||||
)
|
||||
|
||||
BASE_DIR = Path(__file__).parent.parent.joinpath("assets")
|
||||
TEST_DATA_PATH = BASE_DIR.joinpath("test_config_1.cfg")
|
||||
ASSETS_DIR = Path(__file__).parent.parent / "assets"
|
||||
TEST_CFG = ASSETS_DIR / "test_config_1.cfg"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def parser():
|
||||
parser = SimpleConfigParser()
|
||||
for line in load_testdata_from_file(TEST_DATA_PATH):
|
||||
parser._parse_line(line) # noqa
|
||||
|
||||
return parser
|
||||
@pytest.fixture()
|
||||
def parser() -> SimpleConfigParser:
|
||||
p = SimpleConfigParser()
|
||||
p.read_file(TEST_CFG)
|
||||
return p
|
||||
|
||||
|
||||
def test_section_parsing(parser):
|
||||
expected_keys = {"section_1", "section_2", "section_3", "section_4"}
|
||||
assert expected_keys.issubset(
|
||||
parser.config.keys()
|
||||
), f"Expected keys: {expected_keys}, got: {parser.config.keys()}"
|
||||
assert parser.in_option_block is False
|
||||
assert parser.current_section == parser.get_sections()[-1]
|
||||
assert parser.config["section_2"] is not None
|
||||
assert parser.config["section_2"]["header"] == "[section_2] ; comment"
|
||||
assert parser.config["section_2"]["elements"] is not None
|
||||
assert len(parser.config["section_2"]["elements"]) > 0
|
||||
# ----------------------------- Helper utils ----------------------------- #
|
||||
|
||||
|
||||
def test_option_parsing(parser):
|
||||
assert parser.config["section_1"]["elements"][0]["type"] == LineType.OPTION.value
|
||||
assert parser.config["section_1"]["elements"][0]["name"] == "option_1"
|
||||
assert parser.config["section_1"]["elements"][0]["value"] == "value_1"
|
||||
assert parser.config["section_1"]["elements"][0]["raw"] == "option_1: value_1"
|
||||
def _get_section(p: SimpleConfigParser, name: str) -> Section:
|
||||
sect = [s for s in p._config if s.name == name]
|
||||
assert sect, f"Section '{name}' not found"
|
||||
return sect[0]
|
||||
|
||||
|
||||
def test_header_parsing(parser):
|
||||
header = parser.config[HEADER_IDENT]
|
||||
assert isinstance(header, list)
|
||||
assert len(header) > 0
|
||||
def _get_option(sect: Section, name: str):
|
||||
for item in sect.items:
|
||||
if isinstance(item, (Option, MultiLineOption)) and item.name == name:
|
||||
return item
|
||||
return None
|
||||
|
||||
|
||||
def test_option_block_parsing(parser):
|
||||
section = "section number 5"
|
||||
option_block = None
|
||||
for element in parser.config[section]["elements"]:
|
||||
if (element["type"] == LineType.OPTION_BLOCK.value and
|
||||
element["name"] == "multi_option"):
|
||||
option_block = element
|
||||
break
|
||||
# ------------------------------ Basic parsing --------------------------- #
|
||||
|
||||
assert option_block is not None, "multi_option block not found"
|
||||
assert option_block["type"] == LineType.OPTION_BLOCK.value
|
||||
assert option_block["name"] == "multi_option"
|
||||
assert option_block["raw"] == "multi_option:"
|
||||
|
||||
expected_values = [
|
||||
"# these are multi-line values",
|
||||
"value_5_1",
|
||||
"value_5_2 ; here is a comment",
|
||||
"value_5_3"
|
||||
]
|
||||
assert option_block["value"] == expected_values, (
|
||||
f"Expected values: {expected_values}, "
|
||||
f"got: {option_block['value']}"
|
||||
def test_header_lines_preserved(parser: SimpleConfigParser):
|
||||
# Lines before first section become header; ensure we captured them
|
||||
assert parser._header, "Header should not be empty"
|
||||
# The first section name should not appear inside header lines
|
||||
assert all("[section_1]" not in ln for ln in parser._header)
|
||||
# Ensure comments retained verbatim
|
||||
assert any("a comment at the very top" in ln for ln in parser._header)
|
||||
|
||||
|
||||
def test_section_names(parser: SimpleConfigParser):
|
||||
expected = {"section_1", "section_2", "section_3", "section_4", "section number 5"}
|
||||
assert parser.get_sections() == expected
|
||||
|
||||
|
||||
def test_section_raw_line(parser: SimpleConfigParser):
|
||||
s2 = _get_section(parser, "section_2")
|
||||
assert s2.raw.startswith("[section_2]")
|
||||
assert "; comment" in s2.raw
|
||||
|
||||
|
||||
def test_single_line_option_parsing(parser: SimpleConfigParser):
|
||||
s1 = _get_section(parser, "section_1")
|
||||
opt = _get_option(s1, "option_1")
|
||||
assert isinstance(opt, Option)
|
||||
assert opt.name == "option_1"
|
||||
assert opt.value == "value_1"
|
||||
assert opt.raw.strip() == "option_1: value_1"
|
||||
|
||||
|
||||
def test_other_single_line_option_values(parser: SimpleConfigParser):
|
||||
s1 = _get_section(parser, "section_1")
|
||||
bool_opt = _get_option(s1, "option_1_1")
|
||||
int_opt = _get_option(s1, "option_1_2")
|
||||
float_opt = _get_option(s1, "option_1_3")
|
||||
assert isinstance(bool_opt, Option) and bool_opt.value == "True"
|
||||
assert isinstance(int_opt, Option) and int_opt.value.startswith("5")
|
||||
assert isinstance(float_opt, Option) and float_opt.value.startswith("1.123")
|
||||
|
||||
|
||||
def test_comment_and_blank_lines_preserved(parser: SimpleConfigParser):
|
||||
s4 = _get_section(parser, "section_4")
|
||||
# Expect first item is a comment line, followed by an option
|
||||
assert any(isinstance(i, CommentLine) for i in s4.items), "Comment line missing"
|
||||
# Ensure at least one blank line exists in some section
|
||||
assert any(isinstance(i, BlankLine) for s in parser._config for i in s.items), (
|
||||
"No blank lines parsed"
|
||||
)
|
||||
|
||||
|
||||
def test_multiline_option_parsing(parser: SimpleConfigParser):
|
||||
s5 = _get_section(parser, "section number 5")
|
||||
ml = _get_option(s5, "multi_option")
|
||||
assert isinstance(ml, MultiLineOption), "multi_option should be a MultiLineOption"
|
||||
# Raw line ends with ':'
|
||||
assert ml.raw.strip().startswith("multi_option:")
|
||||
values: List[MLOptionValue] = ml.values
|
||||
# Ensure values captured (includes comment lines inside block)
|
||||
assert len(values) >= 4
|
||||
trimmed_values = [v.value for v in values]
|
||||
# Comments are stripped from value field; original raw retains them
|
||||
assert trimmed_values[0] == "" or "multi-line" not in trimmed_values[0], (
|
||||
"First value should be empty or comment stripped"
|
||||
)
|
||||
assert "value_5_1" in trimmed_values
|
||||
assert any("value_5_2" == v for v in trimmed_values)
|
||||
assert any("value_5_3" == v for v in trimmed_values)
|
||||
# Indentation should be consistent (4 spaces in test data)
|
||||
assert all(v.indent == 4 for v in values), "Indentation should be 4 spaces"
|
||||
|
||||
|
||||
def test_option_after_multiline_block(parser: SimpleConfigParser):
|
||||
s5 = _get_section(parser, "section number 5")
|
||||
opt = _get_option(s5, "option_5_1")
|
||||
assert isinstance(opt, Option)
|
||||
assert opt.value == "value_5_1"
|
||||
|
||||
|
||||
def test_getval_and_conversions(parser: SimpleConfigParser):
|
||||
assert parser.getval("section_1", "option_1") == "value_1"
|
||||
assert parser.getboolean("section_1", "option_1_1") is True
|
||||
assert parser.getint("section_1", "option_1_2") == 5
|
||||
assert abs(parser.getfloat("section_1", "option_1_3") - 1.123) < 1e-9
|
||||
|
||||
|
||||
def test_getval_fallback(parser: SimpleConfigParser):
|
||||
assert parser.getval("missing_section", "missing", fallback="fb") == "fb"
|
||||
assert parser.getint("missing_section", "missing", fallback=42) == 42
|
||||
|
||||
|
||||
def test_getvals_on_multiline_option(parser: SimpleConfigParser):
|
||||
vals = parser.getvals("section number 5", "multi_option")
|
||||
# Should not include inline comments, should capture cleaned values
|
||||
assert any(v == "value_5_2" for v in vals)
|
||||
|
||||
|
||||
def test_round_trip_write(tmp_path: Path, parser: SimpleConfigParser):
|
||||
out_file = tmp_path / "round_trip.cfg"
|
||||
parser.write_file(out_file)
|
||||
original = TEST_CFG.read_text(encoding="utf-8")
|
||||
written = out_file.read_text(encoding="utf-8")
|
||||
# Files should match exactly (parser aims for perfect reproduction)
|
||||
assert original == written, "Round-trip file content mismatch"
|
||||
|
||||
|
||||
def test_set_option_adds_and_updates(parser: SimpleConfigParser):
|
||||
# Add new option
|
||||
parser.set_option("section_3", "new_opt", "some_value")
|
||||
s3 = _get_section(parser, "section_3")
|
||||
new_opt = _get_option(s3, "new_opt")
|
||||
assert isinstance(new_opt, Option) and new_opt.value == "some_value"
|
||||
# Update existing option value
|
||||
parser.set_option("section_3", "new_opt", "other")
|
||||
new_opt_after = _get_option(s3, "new_opt")
|
||||
assert new_opt_after.value == "other"
|
||||
|
||||
|
||||
def test_set_option_multiline(parser: SimpleConfigParser):
|
||||
parser.set_option("section_2", "multi_new", ["a", "b", "c"])
|
||||
s2 = _get_section(parser, "section_2")
|
||||
ml = _get_option(s2, "multi_new")
|
||||
assert isinstance(ml, MultiLineOption)
|
||||
assert [v.value for v in ml.values] == ["a", "b", "c"]
|
||||
|
||||
|
||||
def test_remove_section(parser: SimpleConfigParser):
|
||||
parser.remove_section("section_4")
|
||||
assert "section_4" not in parser.get_sections()
|
||||
|
||||
|
||||
def test_remove_option(parser: SimpleConfigParser):
|
||||
parser.remove_option("section_1", "option_1")
|
||||
s1 = _get_section(parser, "section_1")
|
||||
assert _get_option(s1, "option_1") is None
|
||||
|
||||
|
||||
def test_multiline_option_comment_stripping(parser: SimpleConfigParser):
|
||||
# Ensure inline comments removed from value attribute but remain in raw
|
||||
s5 = _get_section(parser, "section number 5")
|
||||
ml = _get_option(s5, "multi_option")
|
||||
assert isinstance(ml, MultiLineOption)
|
||||
raw_with_comment = [v.raw for v in ml.values if "; here is a comment" in v.raw]
|
||||
assert raw_with_comment, "Expected raw line with inline comment"
|
||||
# Corresponding cleaned value should not contain the comment part
|
||||
cleaned_match = [v.value for v in ml.values if v.value == "value_5_2"]
|
||||
assert cleaned_match, "Expected cleaned value 'value_5_2' without comment"
|
||||
|
||||
|
||||
def test_blank_lines_between_sections(parser: SimpleConfigParser):
|
||||
# Ensure at least one blank line exists before section_2 (from original file structure)
|
||||
idx_section_1 = [i for i, s in enumerate(parser._config) if s.name == "section_1"][
|
||||
0
|
||||
]
|
||||
idx_section_2 = [i for i, s in enumerate(parser._config) if s.name == "section_2"][
|
||||
0
|
||||
]
|
||||
# Collect lines after section_1 items end until next section raw
|
||||
assert idx_section_2 == idx_section_1 + 1, "Sections not consecutive as expected"
|
||||
# Validate section_2 has a preceding blank line inside previous section or header logic
|
||||
s1 = _get_section(parser, "section_1")
|
||||
assert any(isinstance(i, BlankLine) for i in s1.items), (
|
||||
"Expected blank line at end of section_1"
|
||||
)
|
||||
|
||||
|
||||
def test_write_preserves_trailing_newline(tmp_path: Path, parser: SimpleConfigParser):
|
||||
out_file = tmp_path / "ensure_newline.cfg"
|
||||
parser.write_file(out_file)
|
||||
content = out_file.read_bytes()
|
||||
assert content.endswith(b"\n"), "Written file must end with newline"
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
# ======================================================================= #
|
||||
# Tests: Verhalten beim Aktualisieren von Multiline-Optionen #
|
||||
# ======================================================================= #
|
||||
from pathlib import Path
|
||||
|
||||
from src.simple_config_parser.simple_config_parser import (
|
||||
BlankLine,
|
||||
MultiLineOption,
|
||||
SimpleConfigParser,
|
||||
)
|
||||
|
||||
ASSETS_DIR = Path(__file__).parent.parent / "assets"
|
||||
TEST_CFG = ASSETS_DIR / "test_config_1.cfg"
|
||||
|
||||
|
||||
def test_update_existing_multiline_option_replaces_values_and_drops_comments(tmp_path):
|
||||
parser = SimpleConfigParser()
|
||||
parser.read_file(TEST_CFG)
|
||||
|
||||
assert parser.getvals("section number 5", "multi_option")
|
||||
orig_values = parser.getvals("section number 5", "multi_option")
|
||||
assert "value_5_2" in orig_values
|
||||
|
||||
new_values = ["alpha", "beta", "gamma"]
|
||||
parser.set_option("section number 5", "multi_option", new_values)
|
||||
|
||||
updated = parser.getvals("section number 5", "multi_option")
|
||||
assert updated == new_values
|
||||
|
||||
sect = [s for s in parser._config if s.name == "section number 5"][0]
|
||||
ml = [
|
||||
i
|
||||
for i in sect.items
|
||||
if isinstance(i, MultiLineOption) and i.name == "multi_option"
|
||||
][0]
|
||||
assert all("value_5_2" not in v.value for v in ml.values)
|
||||
# Nach komplettem Replace keine alten Inline-Kommentare mehr
|
||||
assert all("; here is a comment" not in v.raw for v in ml.values)
|
||||
|
||||
out_file = tmp_path / "updated_multiline.cfg"
|
||||
parser.write_file(out_file)
|
||||
assert out_file.read_text(encoding="utf-8").endswith("\n")
|
||||
|
||||
|
||||
def test_add_section_inserts_blank_line_if_needed():
|
||||
parser = SimpleConfigParser()
|
||||
parser.read_file(TEST_CFG)
|
||||
|
||||
last_before = parser._config[-1]
|
||||
had_blank_before = bool(last_before.items) and isinstance(
|
||||
last_before.items[-1], BlankLine
|
||||
)
|
||||
|
||||
parser.add_section("new_last_section")
|
||||
assert parser.has_section("new_last_section")
|
||||
|
||||
# Vorherige letzte Section wurde ggf. um eine BlankLine erweitert
|
||||
prev_last = [s for s in parser._config if s.name == last_before.name][0]
|
||||
if not had_blank_before:
|
||||
assert isinstance(prev_last.items[-2], BlankLine) or isinstance(
|
||||
prev_last.items[-1], BlankLine
|
||||
)
|
||||
else:
|
||||
# Falls bereits BlankLine vorhanden war, bleibt sie bestehen
|
||||
assert isinstance(prev_last.items[-1], BlankLine)
|
||||
@@ -10,17 +10,19 @@ 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.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)
|
||||
def parser(request):
|
||||
parser = SimpleConfigParser()
|
||||
file_path = BASE_DIR.joinpath(request.param)
|
||||
for line in load_testdata_from_file(file_path):
|
||||
parser._parse_line(line) # noqa
|
||||
|
||||
parser.read_file(file_path)
|
||||
return parser
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
from pathlib import Path
|
||||
|
||||
from src.simple_config_parser.simple_config_parser import Gcode, SimpleConfigParser
|
||||
|
||||
ASSETS = Path(__file__).parent.parent / "assets"
|
||||
GCODE_FILE = ASSETS / "test_gcode.cfg"
|
||||
|
||||
|
||||
def test_gcode_block_parsing():
|
||||
parser = SimpleConfigParser()
|
||||
parser.read_file(GCODE_FILE)
|
||||
|
||||
assert "gcode_macro test" in parser.get_sections()
|
||||
sect = [s for s in parser._config if s.name == "gcode_macro test"][0]
|
||||
gcode_items = [i for i in sect.items if isinstance(i, Gcode)]
|
||||
assert gcode_items, "No Gcode block found in section"
|
||||
|
||||
gc = gcode_items[0]
|
||||
assert gc.raw.strip().startswith("gcode:")
|
||||
assert any("G28" in ln for ln in gc.gcode)
|
||||
assert any("M118" in ln for ln in gc.gcode)
|
||||
assert all(ln.startswith(" ") or ln == "\n" for ln in gc.gcode if ln.strip())
|
||||
|
||||
tmp_out = GCODE_FILE.parent / "tmp_gcode_roundtrip.cfg"
|
||||
parser.write_file(tmp_out)
|
||||
assert tmp_out.read_text(encoding="utf-8") == GCODE_FILE.read_text(encoding="utf-8")
|
||||
tmp_out.unlink()
|
||||
@@ -8,41 +8,33 @@
|
||||
|
||||
import pytest
|
||||
|
||||
from src.simple_config_parser.constants import LineType
|
||||
from src.simple_config_parser.simple_config_parser import (
|
||||
MultiLineOption,
|
||||
NoOptionError,
|
||||
NoSectionError,
|
||||
SimpleConfigParser,
|
||||
)
|
||||
|
||||
|
||||
def test_get_options(parser):
|
||||
def test_get_options(parser: SimpleConfigParser):
|
||||
expected_options = {
|
||||
"section_1": {"option_1"},
|
||||
"section_1": {"option_1", "option_1_1", "option_1_2", "option_1_3"},
|
||||
"section_2": {"option_2"},
|
||||
"section_3": {"option_3"},
|
||||
"section_4": {"option_4"},
|
||||
"section number 5": {"option_5", "multi_option", "option_5_1"},
|
||||
}
|
||||
|
||||
for section, options in expected_options.items():
|
||||
assert options.issubset(
|
||||
parser.get_options(section)
|
||||
), f"Expected options: {options} in section: {section}, got: {parser.get_options(section)}"
|
||||
assert "_raw" not in parser.get_options(section)
|
||||
assert all(
|
||||
not option.startswith("#_") for option in parser.get_options(section)
|
||||
)
|
||||
for sect, opts in expected_options.items():
|
||||
assert opts.issubset(parser.get_options(sect))
|
||||
|
||||
|
||||
def test_has_option(parser):
|
||||
assert parser.has_option("section_1", "option_1") is True
|
||||
assert parser.has_option("section_1", "option_128") is False
|
||||
# section does not exist:
|
||||
assert parser.has_option("section_128", "option_1") is False
|
||||
|
||||
|
||||
def test_getval(parser):
|
||||
# test regular option values
|
||||
assert parser.getval("section_1", "option_1") == "value_1"
|
||||
assert parser.getval("section_3", "option_3") == "value_3"
|
||||
assert parser.getval("section_4", "option_4") == "value_4"
|
||||
@@ -50,137 +42,69 @@ def test_getval(parser):
|
||||
assert parser.getval("section number 5", "option_5_1") == "value_5_1"
|
||||
assert parser.getval("section_2", "option_2") == "value_2"
|
||||
|
||||
# test multiline option values
|
||||
ml_val = parser.getvals("section number 5", "multi_option")
|
||||
assert isinstance(ml_val, list)
|
||||
assert len(ml_val) > 0
|
||||
|
||||
def test_getvals_multiline(parser):
|
||||
vals = parser.getvals("section number 5", "multi_option")
|
||||
assert isinstance(vals, list) and len(vals) >= 3
|
||||
assert "value_5_2" in vals
|
||||
|
||||
|
||||
def test_getval_fallback(parser):
|
||||
assert parser.getval("section_1", "option_128", "fallback") == "fallback"
|
||||
assert parser.getval("section_1", "option_128", None) is None
|
||||
assert parser.getval("section_1", "option_128", fallback="fallback") == "fallback"
|
||||
with pytest.raises(NoOptionError):
|
||||
parser.getval("section_1", "option_128")
|
||||
|
||||
|
||||
def test_getval_exceptions(parser):
|
||||
with pytest.raises(NoSectionError):
|
||||
parser.getval("section_128", "option_1")
|
||||
|
||||
with pytest.raises(NoOptionError):
|
||||
parser.getval("section_1", "option_128")
|
||||
|
||||
|
||||
def test_getint(parser):
|
||||
value = parser.getint("section_1", "option_1_2")
|
||||
assert isinstance(value, int)
|
||||
def test_type_conversions(parser):
|
||||
assert parser.getint("section_1", "option_1_2") == 5
|
||||
assert pytest.approx(parser.getfloat("section_1", "option_1_3"), rel=1e-9) == 1.123
|
||||
assert parser.getboolean("section_1", "option_1_1") is True
|
||||
|
||||
|
||||
def test_getint_from_val(parser):
|
||||
def test_type_conversion_errors(parser):
|
||||
with pytest.raises(ValueError):
|
||||
parser.getint("section_1", "option_1")
|
||||
|
||||
|
||||
def test_getint_from_float(parser):
|
||||
with pytest.raises(ValueError):
|
||||
parser.getint("section_1", "option_1_3")
|
||||
|
||||
|
||||
def test_getint_from_boolean(parser):
|
||||
with pytest.raises(ValueError):
|
||||
parser.getint("section_1", "option_1_1")
|
||||
|
||||
|
||||
def test_getint_fallback(parser):
|
||||
assert parser.getint("section_1", "option_128", 128) == 128
|
||||
assert parser.getint("section_1", "option_128", None) is None
|
||||
|
||||
|
||||
def test_getboolean(parser):
|
||||
value = parser.getboolean("section_1", "option_1_1")
|
||||
assert isinstance(value, bool)
|
||||
assert value is True or value is False
|
||||
|
||||
|
||||
def test_getboolean_from_val(parser):
|
||||
with pytest.raises(ValueError):
|
||||
parser.getboolean("section_1", "option_1")
|
||||
|
||||
|
||||
def test_getboolean_from_int(parser):
|
||||
with pytest.raises(ValueError):
|
||||
parser.getboolean("section_1", "option_1_2")
|
||||
|
||||
|
||||
def test_getboolean_from_float(parser):
|
||||
with pytest.raises(ValueError):
|
||||
parser.getboolean("section_1", "option_1_3")
|
||||
|
||||
|
||||
def test_getboolean_fallback(parser):
|
||||
assert parser.getboolean("section_1", "option_128", True) is True
|
||||
assert parser.getboolean("section_1", "option_128", False) is False
|
||||
assert parser.getboolean("section_1", "option_128", None) is None
|
||||
|
||||
|
||||
def test_getfloat(parser):
|
||||
value = parser.getfloat("section_1", "option_1_3")
|
||||
assert isinstance(value, float)
|
||||
|
||||
|
||||
def test_getfloat_from_val(parser):
|
||||
with pytest.raises(ValueError):
|
||||
parser.getfloat("section_1", "option_1")
|
||||
|
||||
|
||||
def test_getfloat_from_int(parser):
|
||||
value = parser.getfloat("section_1", "option_1_2")
|
||||
assert isinstance(value, float)
|
||||
def test_type_conversion_fallbacks(parser):
|
||||
assert parser.getint("section_1", "missing", fallback=99) == 99
|
||||
assert parser.getfloat("section_1", "missing", fallback=3.14) == 3.14
|
||||
assert parser.getboolean("section_1", "missing", fallback=False) is False
|
||||
|
||||
|
||||
def test_getfloat_from_boolean(parser):
|
||||
with pytest.raises(ValueError):
|
||||
parser.getfloat("section_1", "option_1_1")
|
||||
def test_set_option_creates_and_updates(parser):
|
||||
parser.set_option("section_1", "new_option", "nv")
|
||||
assert parser.getval("section_1", "new_option") == "nv"
|
||||
parser.set_option("section_1", "new_option", "nv2")
|
||||
assert parser.getval("section_1", "new_option") == "nv2"
|
||||
|
||||
|
||||
def test_getfloat_fallback(parser):
|
||||
assert parser.getfloat("section_1", "option_128", 1.234) == 1.234
|
||||
assert parser.getfloat("section_1", "option_128", None) is None
|
||||
|
||||
|
||||
def test_set_existing_option(parser):
|
||||
parser.set_option("section_1", "new_option", "new_value")
|
||||
assert parser.getval("section_1", "new_option") == "new_value"
|
||||
assert parser.config["section_1"]["elements"][4] is not None
|
||||
assert parser.config["section_1"]["elements"][4]["type"] == LineType.OPTION.value
|
||||
assert parser.config["section_1"]["elements"][4]["name"] == "new_option"
|
||||
assert parser.config["section_1"]["elements"][4]["value"] == "new_value"
|
||||
assert parser.config["section_1"]["elements"][4]["raw"] == "new_option: new_value\n"
|
||||
|
||||
|
||||
def test_set_new_option(parser):
|
||||
parser.set_option("new_section", "very_new_option", "very_new_value")
|
||||
assert (
|
||||
parser.has_section("new_section") is True
|
||||
), f"Expected 'new_section' in {parser.get_sections()}"
|
||||
assert parser.getval("new_section", "very_new_option") == "very_new_value"
|
||||
|
||||
def test_set_multiline_option(parser):
|
||||
parser.set_option("section_2", "array_option", ["value_1", "value_2", "value_3"])
|
||||
assert parser.getvals("section_2", "array_option") == [
|
||||
"value_1",
|
||||
"value_2",
|
||||
"value_3",
|
||||
]
|
||||
|
||||
assert parser.config["section_2"]["elements"][1] is not None
|
||||
assert parser.config["section_2"]["elements"][1]["type"] == LineType.OPTION_BLOCK.value
|
||||
assert parser.config["section_2"]["elements"][1]["name"] == "array_option"
|
||||
assert parser.config["section_2"]["elements"][1]["value"] == [
|
||||
"value_1",
|
||||
"value_2",
|
||||
"value_3",
|
||||
]
|
||||
assert parser.config["section_2"]["elements"][1]["raw"] == "array_option:\n"
|
||||
vals = parser.getvals("section_2", "array_option")
|
||||
assert vals == ["value_1", "value_2", "value_3"]
|
||||
# Prüfe Typ
|
||||
sect = [s for s in parser._config if s.name == "section_2"][0]
|
||||
ml = [
|
||||
i
|
||||
for i in sect.items
|
||||
if isinstance(i, MultiLineOption) and i.name == "array_option"
|
||||
][0]
|
||||
assert isinstance(ml, MultiLineOption)
|
||||
assert ml.raw == "array_option:\n"
|
||||
|
||||
|
||||
def test_remove_option(parser):
|
||||
parser.remove_option("section_1", "option_1")
|
||||
assert parser.has_option("section_1", "option_1") is False
|
||||
assert not parser.has_option("section_1", "option_1")
|
||||
|
||||
@@ -7,16 +7,32 @@
|
||||
# ======================================================================= #
|
||||
from pathlib import Path
|
||||
|
||||
from src.simple_config_parser.simple_config_parser import (
|
||||
SimpleConfigParser,
|
||||
)
|
||||
from src.simple_config_parser.simple_config_parser import Section, SimpleConfigParser
|
||||
|
||||
BASE_DIR = Path(__file__).parent.parent.joinpath("assets")
|
||||
TEST_DATA_PATH = BASE_DIR.joinpath("test_config_1.cfg")
|
||||
BASE_DIR = Path(__file__).parent.parent / "assets"
|
||||
TEST_DATA_PATH = BASE_DIR / "test_config_1.cfg"
|
||||
|
||||
|
||||
def test_read_file():
|
||||
def test_read_file_sections_and_header():
|
||||
parser = SimpleConfigParser()
|
||||
parser.read_file(TEST_DATA_PATH)
|
||||
assert parser.config is not None
|
||||
assert parser.config.keys() is not None
|
||||
|
||||
# Header erhalten
|
||||
assert parser._header, "Header darf nicht leer sein"
|
||||
assert any("a comment at the very top" in ln for ln in parser._header)
|
||||
|
||||
# Sektionen korrekt eingelesen
|
||||
expected = {"section_1", "section_2", "section_3", "section_4", "section number 5"}
|
||||
assert parser.get_sections() == expected
|
||||
|
||||
# Reihenfolge bleibt erhalten
|
||||
assert [s.name for s in parser._config] == [
|
||||
"section_1",
|
||||
"section_2",
|
||||
"section_3",
|
||||
"section_4",
|
||||
"section number 5",
|
||||
]
|
||||
|
||||
# Jede Section ist ein Section-Dataclass
|
||||
assert all(isinstance(s, Section) for s in parser._config)
|
||||
|
||||
@@ -14,16 +14,17 @@ from src.simple_config_parser.simple_config_parser import (
|
||||
|
||||
|
||||
def test_get_sections(parser):
|
||||
expected_keys = {
|
||||
expected_core = {
|
||||
"section_1",
|
||||
"section_2",
|
||||
"section_3",
|
||||
"section_4",
|
||||
"section number 5",
|
||||
}
|
||||
assert expected_keys.issubset(
|
||||
parser.get_sections()
|
||||
), f"Expected keys: {expected_keys}, got: {parser.get_sections()}"
|
||||
parsed = parser.get_sections()
|
||||
assert expected_core.issubset(parsed), (
|
||||
f"Missing core sections: {expected_core - parsed}"
|
||||
)
|
||||
|
||||
|
||||
def test_has_section(parser):
|
||||
@@ -39,18 +40,6 @@ def test_add_section(parser):
|
||||
assert parser.has_section("new_section2") is True
|
||||
assert len(parser.get_sections()) == pre_add_count + 2
|
||||
|
||||
new_section = parser.config["new_section"]
|
||||
assert isinstance(new_section, dict)
|
||||
assert new_section["header"] == "[new_section]\n"
|
||||
assert new_section["elements"] is not None
|
||||
assert new_section["elements"] == []
|
||||
|
||||
new_section2 = parser.config["new_section2"]
|
||||
assert isinstance(new_section2, dict)
|
||||
assert new_section2["header"] == "[new_section2]\n"
|
||||
assert new_section2["elements"] is not None
|
||||
assert new_section2["elements"] == []
|
||||
|
||||
|
||||
def test_add_section_duplicate(parser):
|
||||
with pytest.raises(DuplicateSectionError):
|
||||
@@ -62,4 +51,3 @@ def test_remove_section(parser):
|
||||
parser.remove_section("section_1")
|
||||
assert parser.has_section("section_1") is False
|
||||
assert len(parser.get_sections()) == pre_remove_count - 1
|
||||
assert "section_1" not in parser.config
|
||||
|
||||
@@ -9,110 +9,91 @@ from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from src.simple_config_parser.simple_config_parser import (
|
||||
SimpleConfigParser,
|
||||
)
|
||||
from src.simple_config_parser.simple_config_parser import SimpleConfigParser
|
||||
|
||||
BASE_DIR = Path(__file__).parent.parent.joinpath("assets")
|
||||
TEST_DATA_PATH = BASE_DIR.joinpath("test_config_1.cfg")
|
||||
# TEST_DATA_PATH_2 = BASE_DIR.joinpath("test_config_1_write.cfg")
|
||||
BASE_DIR = Path(__file__).parent.parent / "assets"
|
||||
TEST_DATA_PATH = BASE_DIR / "test_config_1.cfg"
|
||||
|
||||
|
||||
def test_write_file_exception():
|
||||
parser = SimpleConfigParser()
|
||||
with pytest.raises(ValueError):
|
||||
parser.write_file(None) # noqa
|
||||
parser.write_file(None) # noqa: intentionally invalid
|
||||
|
||||
|
||||
def test_write_to_file(tmp_path):
|
||||
tmp_file = Path(tmp_path).joinpath("tmp_config.cfg")
|
||||
tmp_file = Path(tmp_path) / "tmp_config.cfg"
|
||||
parser1 = SimpleConfigParser()
|
||||
parser1.read_file(TEST_DATA_PATH)
|
||||
# parser1.write_file(TEST_DATA_PATH_2)
|
||||
parser1.write_file(tmp_file)
|
||||
|
||||
parser2 = SimpleConfigParser()
|
||||
parser2.read_file(tmp_file)
|
||||
|
||||
assert tmp_file.exists()
|
||||
assert parser2.config is not None
|
||||
# gleiche Sections & Round-Trip identisch
|
||||
assert parser2.get_sections() == parser1.get_sections()
|
||||
assert tmp_file.read_text(encoding="utf-8") == TEST_DATA_PATH.read_text(
|
||||
encoding="utf-8"
|
||||
)
|
||||
|
||||
with open(TEST_DATA_PATH, "r") as original, open(tmp_file, "r") as written:
|
||||
assert original.read() == written.read()
|
||||
|
||||
def test_remove_option_and_write(tmp_path):
|
||||
# Setup paths
|
||||
test_dir = BASE_DIR.joinpath("write_tests/remove_option")
|
||||
input_file = test_dir.joinpath("input.cfg")
|
||||
expected_file = test_dir.joinpath("expected.cfg")
|
||||
output_file = Path(tmp_path).joinpath("output.cfg")
|
||||
test_dir = BASE_DIR / "write_tests" / "remove_option"
|
||||
input_file = test_dir / "input.cfg"
|
||||
expected_file = test_dir / "expected.cfg"
|
||||
output_file = Path(tmp_path) / "output.cfg"
|
||||
|
||||
# Read input file and remove option
|
||||
parser = SimpleConfigParser()
|
||||
parser.read_file(input_file)
|
||||
parser.remove_option("section_1", "option_to_remove")
|
||||
|
||||
# Write modified config
|
||||
parser.write_file(output_file)
|
||||
# parser.write_file(test_dir.joinpath("output.cfg"))
|
||||
|
||||
# Compare with expected output
|
||||
with open(expected_file, "r") as expected, open(output_file, "r") as actual:
|
||||
assert expected.read() == actual.read()
|
||||
assert output_file.read_text(encoding="utf-8") == expected_file.read_text(
|
||||
encoding="utf-8"
|
||||
)
|
||||
|
||||
# Additional verification
|
||||
parser2 = SimpleConfigParser()
|
||||
parser2.read_file(output_file)
|
||||
assert not parser2.has_option("section_1", "option_to_remove")
|
||||
|
||||
def test_remove_section_and_write(tmp_path):
|
||||
# Setup paths
|
||||
test_dir = BASE_DIR.joinpath("write_tests/remove_section")
|
||||
input_file = test_dir.joinpath("input.cfg")
|
||||
expected_file = test_dir.joinpath("expected.cfg")
|
||||
output_file = Path(tmp_path).joinpath("output.cfg")
|
||||
|
||||
# Read input file and remove section
|
||||
def test_remove_section_and_write(tmp_path):
|
||||
test_dir = BASE_DIR / "write_tests" / "remove_section"
|
||||
input_file = test_dir / "input.cfg"
|
||||
expected_file = test_dir / "expected.cfg"
|
||||
output_file = Path(tmp_path) / "output.cfg"
|
||||
|
||||
parser = SimpleConfigParser()
|
||||
parser.read_file(input_file)
|
||||
parser.remove_section("section_to_remove")
|
||||
|
||||
# Write modified config
|
||||
parser.write_file(output_file)
|
||||
# parser.write_file(test_dir.joinpath("output.cfg"))
|
||||
|
||||
# Compare with expected output
|
||||
with open(expected_file, "r") as expected, open(output_file, "r") as actual:
|
||||
assert expected.read() == actual.read()
|
||||
assert output_file.read_text(encoding="utf-8") == expected_file.read_text(
|
||||
encoding="utf-8"
|
||||
)
|
||||
|
||||
# Additional verification
|
||||
parser2 = SimpleConfigParser()
|
||||
parser2.read_file(output_file)
|
||||
assert not parser2.has_section("section_to_remove")
|
||||
assert "section_1" in parser2.get_sections()
|
||||
assert "section_2" in parser2.get_sections()
|
||||
assert {"section_1", "section_2"}.issubset(parser2.get_sections())
|
||||
|
||||
|
||||
def test_add_option_and_write(tmp_path):
|
||||
# Setup paths
|
||||
test_dir = BASE_DIR.joinpath("write_tests/add_option")
|
||||
input_file = test_dir.joinpath("input.cfg")
|
||||
expected_file = test_dir.joinpath("expected.cfg")
|
||||
output_file = Path(tmp_path).joinpath("output.cfg")
|
||||
test_dir = BASE_DIR / "write_tests" / "add_option"
|
||||
input_file = test_dir / "input.cfg"
|
||||
expected_file = test_dir / "expected.cfg"
|
||||
output_file = Path(tmp_path) / "output.cfg"
|
||||
|
||||
# Read input file and add option
|
||||
parser = SimpleConfigParser()
|
||||
parser.read_file(input_file)
|
||||
parser.set_option("section_1", "new_option", "new_value")
|
||||
|
||||
# Write modified config
|
||||
parser.write_file(output_file)
|
||||
# parser.write_file(test_dir.joinpath("output.cfg"))
|
||||
|
||||
# Compare with expected output
|
||||
with open(expected_file, "r") as expected, open(output_file, "r") as actual:
|
||||
assert expected.read() == actual.read()
|
||||
assert output_file.read_text(encoding="utf-8") == expected_file.read_text(
|
||||
encoding="utf-8"
|
||||
)
|
||||
|
||||
# Additional verification
|
||||
parser2 = SimpleConfigParser()
|
||||
parser2.read_file(output_file)
|
||||
assert parser2.has_option("section_1", "new_option")
|
||||
|
||||
@@ -10,80 +10,58 @@ 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.parent.joinpath("assets")
|
||||
TEST_DATA_PATH = BASE_DIR.joinpath("test_config_1.cfg")
|
||||
BASE_DIR = Path(__file__).parent.parent / "assets"
|
||||
TEST_DATA_PATH = BASE_DIR / "test_config_1.cfg"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def parser():
|
||||
parser = SimpleConfigParser()
|
||||
for line in load_testdata_from_file(TEST_DATA_PATH):
|
||||
parser._parse_line(line) # noqa
|
||||
|
||||
return parser
|
||||
p = SimpleConfigParser()
|
||||
p.read_file(TEST_DATA_PATH)
|
||||
return p
|
||||
|
||||
|
||||
def test_get_int_conv(parser):
|
||||
should_be_int = parser._get_conv("section_1", "option_1_2", int)
|
||||
assert isinstance(should_be_int, int)
|
||||
assert parser.getint("section_1", "option_1_2") == 5
|
||||
|
||||
|
||||
def test_get_float_conv(parser):
|
||||
should_be_float = parser._get_conv("section_1", "option_1_3", float)
|
||||
assert isinstance(should_be_float, float)
|
||||
assert pytest.approx(parser.getfloat("section_1", "option_1_3"), rel=1e-9) == 1.123
|
||||
|
||||
|
||||
def test_get_bool_conv(parser):
|
||||
should_be_bool = parser._get_conv(
|
||||
"section_1", "option_1_1", parser._convert_to_boolean
|
||||
)
|
||||
assert isinstance(should_be_bool, bool)
|
||||
assert parser.getboolean("section_1", "option_1_1") is True
|
||||
|
||||
|
||||
def test_get_int_conv_fallback(parser):
|
||||
should_be_fallback_int = parser._get_conv(
|
||||
"section_1", "option_128", int, fallback=128
|
||||
)
|
||||
assert isinstance(should_be_fallback_int, int)
|
||||
assert should_be_fallback_int == 128
|
||||
assert parser._get_conv("section_1", "option_128", int, None) is None
|
||||
assert parser.getint("section_1", "missing", fallback=128) == 128
|
||||
with pytest.raises(Exception):
|
||||
parser.getint("section_1", "missing")
|
||||
|
||||
|
||||
def test_get_float_conv_fallback(parser):
|
||||
should_be_fallback_float = parser._get_conv(
|
||||
"section_1", "option_128", float, fallback=1.234
|
||||
)
|
||||
assert isinstance(should_be_fallback_float, float)
|
||||
assert should_be_fallback_float == 1.234
|
||||
|
||||
assert parser._get_conv("section_1", "option_128", float, None) is None
|
||||
assert parser.getfloat("section_1", "missing", fallback=1.234) == 1.234
|
||||
with pytest.raises(Exception):
|
||||
parser.getfloat("section_1", "missing")
|
||||
|
||||
|
||||
def test_get_bool_conv_fallback(parser):
|
||||
should_be_fallback_bool = parser._get_conv(
|
||||
"section_1", "option_128", parser._convert_to_boolean, fallback=True
|
||||
)
|
||||
assert isinstance(should_be_fallback_bool, bool)
|
||||
assert should_be_fallback_bool is True
|
||||
|
||||
assert (
|
||||
parser._get_conv("section_1", "option_128", parser._convert_to_boolean, None)
|
||||
is None
|
||||
)
|
||||
assert parser.getboolean("section_1", "missing", fallback=True) is True
|
||||
with pytest.raises(Exception):
|
||||
parser.getboolean("section_1", "missing")
|
||||
|
||||
|
||||
def test_get_int_conv_exception(parser):
|
||||
with pytest.raises(ValueError):
|
||||
parser._get_conv("section_1", "option_1", int)
|
||||
parser.getint("section_1", "option_1")
|
||||
|
||||
|
||||
def test_get_float_conv_exception(parser):
|
||||
with pytest.raises(ValueError):
|
||||
parser._get_conv("section_1", "option_1", float)
|
||||
parser.getfloat("section_1", "option_1")
|
||||
|
||||
|
||||
def test_get_bool_conv_exception(parser):
|
||||
with pytest.raises(ValueError):
|
||||
parser._get_conv("section_1", "option_1", parser._convert_to_boolean)
|
||||
parser.getboolean("section_1", "option_1")
|
||||
|
||||
@@ -150,9 +150,9 @@ class ExtensionSubmenu(BaseMenu):
|
||||
if website or repo:
|
||||
links_lines: List[str] = ["Links:"]
|
||||
if website:
|
||||
links_lines.append(f"- Website: {website}")
|
||||
links_lines.append(f"● {website}")
|
||||
if repo:
|
||||
links_lines.append(f"- GitHub: {repo}")
|
||||
links_lines.append(f"● {repo}")
|
||||
|
||||
links_text = Logger.format_content(
|
||||
links_lines,
|
||||
|
||||
@@ -16,6 +16,7 @@ class ShellCommand:
|
||||
self.gcode = self.printer.lookup_object("gcode")
|
||||
cmd = config.get("command")
|
||||
cmd = os.path.expanduser(cmd)
|
||||
cmd = os.path.expandvars(cmd)
|
||||
self.command = shlex.split(cmd)
|
||||
self.timeout = config.getfloat("timeout", 2.0, above=0.0)
|
||||
self.verbose = config.getboolean("verbose", True)
|
||||
|
||||
@@ -9,12 +9,13 @@
|
||||
|
||||
import os
|
||||
import shutil
|
||||
from datetime import datetime
|
||||
from typing import List
|
||||
|
||||
from components.klipper.klipper import Klipper
|
||||
from core.backup_manager.backup_manager import BackupManager
|
||||
from core.instance_manager.instance_manager import InstanceManager
|
||||
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 (
|
||||
SimpleConfigParser,
|
||||
)
|
||||
@@ -106,14 +107,16 @@ class GcodeShellCmdExtension(BaseExtension):
|
||||
shutil.copy(EXAMPLE_CFG_SRC, cfg_dir)
|
||||
Logger.print_ok("Done!")
|
||||
except OSError as e:
|
||||
Logger.warn(f"Unable to create example config: {e}")
|
||||
Logger.print_error(f"Unable to create example config: {e}")
|
||||
|
||||
# backup each printer.cfg before modification
|
||||
bm = BackupManager()
|
||||
svc = BackupService()
|
||||
timestamp = datetime.now().strftime("%Y%m%d-%H%M%S")
|
||||
for instance in instances:
|
||||
bm.backup_file(
|
||||
instance.cfg_file,
|
||||
custom_filename=f"{instance.suffix}.printer.cfg",
|
||||
svc.backup_file(
|
||||
source_path=instance.cfg_file,
|
||||
target_path=f"{instance.data_dir.name}/config_{timestamp}",
|
||||
target_name=instance.cfg_file.name,
|
||||
)
|
||||
|
||||
# add section to printer.cfg if not already defined
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
"module": "gcode_shell_cmd_extension",
|
||||
"maintained_by": "dw-0",
|
||||
"display_name": "G-Code Shell Command",
|
||||
"description": ["Run a shell commands from gcode."]
|
||||
"description": ["Run a shell commands from gcode."],
|
||||
"updates": false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
"maintained_by": "Staubgeborener",
|
||||
"display_name": "Klipper-Backup",
|
||||
"description": ["Backup all your Klipper files to GitHub"],
|
||||
"website": "https://klipperbackup.xyz",
|
||||
"repo": "https://github.com/Staubgeborener/klipper-backup",
|
||||
"updates": true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
"module": "mainsail_theme_installer_extension",
|
||||
"maintained_by": "dw-0",
|
||||
"display_name": "Mainsail Theme Installer",
|
||||
"description": ["Install Mainsail Themes maintained by the Mainsail community."]
|
||||
"description": ["Install Mainsail Themes maintained by the Mainsail community."],
|
||||
"website": "https://docs.mainsail.xyz/theming/themes",
|
||||
"updates": false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from core.backup_manager import BACKUP_ROOT_DIR
|
||||
from core.constants import SYSTEMD
|
||||
|
||||
# repo
|
||||
@@ -23,7 +22,6 @@ MOBILERAKER_LOG_NAME = "mobileraker.log"
|
||||
# directories
|
||||
MOBILERAKER_DIR = Path.home().joinpath("mobileraker_companion")
|
||||
MOBILERAKER_ENV_DIR = Path.home().joinpath("mobileraker-env")
|
||||
MOBILERAKER_BACKUP_DIR = BACKUP_ROOT_DIR.joinpath("mobileraker-backups")
|
||||
|
||||
# files
|
||||
MOBILERAKER_INSTALL_SCRIPT = MOBILERAKER_DIR.joinpath("scripts/install.sh")
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
"description": [
|
||||
"Companion for Mobileraker, enabling push notification for Klipper using Moonraker."
|
||||
],
|
||||
"repo": "https://github.com/Clon1998/mobileraker_companion",
|
||||
"updates": true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,13 +13,12 @@ from typing import List
|
||||
|
||||
from components.klipper.klipper import Klipper
|
||||
from components.moonraker.moonraker import Moonraker
|
||||
from core.backup_manager.backup_manager import BackupManager
|
||||
from core.instance_manager.instance_manager import InstanceManager
|
||||
from core.logger import DialogType, Logger
|
||||
from core.services.backup_service import BackupService
|
||||
from core.settings.kiauh_settings import KiauhSettings
|
||||
from extensions.base_extension import BaseExtension
|
||||
from extensions.mobileraker import (
|
||||
MOBILERAKER_BACKUP_DIR,
|
||||
MOBILERAKER_DIR,
|
||||
MOBILERAKER_ENV_DIR,
|
||||
MOBILERAKER_INSTALL_SCRIPT,
|
||||
@@ -152,6 +151,7 @@ class MobilerakerExtension(BaseExtension):
|
||||
Logger.print_status(
|
||||
"Removing Mobileraker's companion from update manager ..."
|
||||
)
|
||||
BackupService().backup_moonraker_conf()
|
||||
remove_config_section(MOBILERAKER_UPDATER_SECTION_NAME, mr_instances)
|
||||
Logger.print_ok(
|
||||
"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}")
|
||||
|
||||
def _patch_mobileraker_update_manager(self, instances: List[Moonraker]) -> None:
|
||||
BackupService().backup_moonraker_conf()
|
||||
add_config_section(
|
||||
section=MOBILERAKER_UPDATER_SECTION_NAME,
|
||||
instances=instances,
|
||||
@@ -179,14 +180,14 @@ class MobilerakerExtension(BaseExtension):
|
||||
)
|
||||
|
||||
def _backup_mobileraker_dir(self) -> None:
|
||||
bm = BackupManager()
|
||||
bm.backup_directory(
|
||||
MOBILERAKER_DIR.name,
|
||||
source=MOBILERAKER_DIR,
|
||||
target=MOBILERAKER_BACKUP_DIR,
|
||||
svc = BackupService()
|
||||
svc.backup_directory(
|
||||
source_path=MOBILERAKER_DIR,
|
||||
backup_name="mobileraker",
|
||||
target_path="mobileraker",
|
||||
)
|
||||
bm.backup_directory(
|
||||
MOBILERAKER_ENV_DIR.name,
|
||||
source=MOBILERAKER_ENV_DIR,
|
||||
target=MOBILERAKER_BACKUP_DIR,
|
||||
svc.backup_directory(
|
||||
source_path=MOBILERAKER_ENV_DIR,
|
||||
backup_name="mobileraker-env",
|
||||
target_path="mobileraker",
|
||||
)
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
"- 25FPS High-Def Webcam Streaming",
|
||||
"- Free 4.9-Star Mobile App"
|
||||
],
|
||||
"website": "https://obico.io",
|
||||
"repo": "github.com/TheSpaghettiDetective/moonraker-obico",
|
||||
"updates": true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ from components.moonraker.moonraker import Moonraker
|
||||
from core.instance_manager.base_instance import SUFFIX_BLACKLIST
|
||||
from core.instance_manager.instance_manager import InstanceManager
|
||||
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 (
|
||||
SimpleConfigParser,
|
||||
)
|
||||
@@ -31,7 +32,10 @@ from extensions.obico import (
|
||||
from extensions.obico.moonraker_obico import (
|
||||
MoonrakerObico,
|
||||
)
|
||||
from utils.common import check_install_dependencies, moonraker_exists
|
||||
from utils.common import (
|
||||
check_install_dependencies,
|
||||
moonraker_exists,
|
||||
)
|
||||
from utils.config_utils import (
|
||||
add_config_section,
|
||||
remove_config_section,
|
||||
@@ -119,6 +123,8 @@ class ObicoExtension(BaseExtension):
|
||||
|
||||
cmd_sysctl_manage("daemon-reload")
|
||||
|
||||
BackupService().backup_printer_config_dir()
|
||||
|
||||
# add to klippers config
|
||||
self._patch_printer_cfg(kl_instances)
|
||||
InstanceManager.restart_all(kl_instances)
|
||||
@@ -165,6 +171,7 @@ class ObicoExtension(BaseExtension):
|
||||
self._remove_obico_instances(ob_instances)
|
||||
self._remove_obico_dir()
|
||||
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_UPDATE_CFG_NAME}", mr_instances)
|
||||
Logger.print_dialog(
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
"- Live Gcode preview",
|
||||
"- And much much more!"
|
||||
],
|
||||
"repo": "https://github.com/crysxd/OctoApp-Plugin",
|
||||
"updates": true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ from components.klipper.klipper import Klipper
|
||||
from components.moonraker.moonraker import Moonraker
|
||||
from core.instance_manager.instance_manager import InstanceManager
|
||||
from core.logger import DialogType, Logger
|
||||
from core.services.backup_service import BackupService
|
||||
from extensions.base_extension import BaseExtension
|
||||
from extensions.octoapp import (
|
||||
OA_DEPS_JSON_FILE,
|
||||
@@ -133,6 +134,7 @@ class OctoappExtension(BaseExtension):
|
||||
self._remove_OA_store_dirs()
|
||||
self._remove_OA_dir()
|
||||
self._remove_OA_env()
|
||||
BackupService().backup_moonraker_conf()
|
||||
remove_config_section(f"include {OA_SYS_CFG_NAME}", mr_instances)
|
||||
run_remove_routines(OA_INSTALLER_LOG_FILE)
|
||||
Logger.print_dialog(
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
"- Real-time Notifications",
|
||||
"- Live Streaming, and More!"
|
||||
],
|
||||
"website": "https://octoeverywhere.com",
|
||||
"repo": "github.com/QuinnDamerell/OctoPrint-OctoEverywhere",
|
||||
"updates": true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ from typing import List
|
||||
from components.moonraker.moonraker import Moonraker
|
||||
from core.instance_manager.instance_manager import InstanceManager
|
||||
from core.logger import DialogType, Logger
|
||||
from core.services.backup_service import BackupService
|
||||
from extensions.base_extension import BaseExtension
|
||||
from extensions.octoeverywhere import (
|
||||
OE_DEPS_JSON_FILE,
|
||||
@@ -133,6 +134,7 @@ class OctoeverywhereExtension(BaseExtension):
|
||||
self._remove_oe_instances(ob_instances)
|
||||
self._remove_oe_dir()
|
||||
self._remove_oe_env()
|
||||
BackupService().backup_moonraker_conf()
|
||||
remove_config_section(f"include {OE_SYS_CFG_NAME}", mr_instances)
|
||||
run_remove_routines(OE_INSTALLER_LOG_FILE)
|
||||
Logger.print_dialog(
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
"maintained_by": "Kragrathea",
|
||||
"display_name": "PrettyGCode for Klipper",
|
||||
"description": ["3D G-Code viewer for Klipper"],
|
||||
"repo": "https://github.com/Kragrathea/pgcode",
|
||||
"updates": true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
"3D Printer Cloud Management Software.",
|
||||
"\n\n",
|
||||
"3D printing doesn't have to be a complicated, analog, SD card-filled experience; step into the future of modern 3D printing"
|
||||
]
|
||||
],
|
||||
"website": "https://simplyprint.io",
|
||||
"repo": "https://github.com/SimplyPrint",
|
||||
"updates": false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,11 +11,12 @@ from typing import List
|
||||
from components.moonraker.moonraker import Moonraker
|
||||
from core.instance_manager.instance_manager import InstanceManager
|
||||
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 (
|
||||
SimpleConfigParser,
|
||||
)
|
||||
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
|
||||
|
||||
|
||||
@@ -112,10 +113,10 @@ class SimplyPrintExtension(BaseExtension):
|
||||
continue
|
||||
|
||||
if is_install and not scp.has_section("simplyprint"):
|
||||
backup_printer_config_dir()
|
||||
BackupService().backup_printer_config_dir()
|
||||
scp.add_section(section)
|
||||
elif not is_install and scp.has_section("simplyprint"):
|
||||
backup_printer_config_dir()
|
||||
BackupService().backup_printer_config_dir()
|
||||
scp.remove_section(section)
|
||||
scp.write_file(moonraker.cfg_file)
|
||||
patched_files.append(moonraker.cfg_file)
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
"\n\n",
|
||||
"Note: This extension installs Spoolman using Docker. Docker must be installed on your system before installing Spoolman."
|
||||
],
|
||||
"repo": "https://github.com/Donkie/Spoolman",
|
||||
"updates": true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
# ======================================================================= #
|
||||
|
||||
import re
|
||||
from pathlib import Path
|
||||
from subprocess import CalledProcessError, run
|
||||
from typing import List, Tuple
|
||||
|
||||
@@ -15,9 +16,9 @@ from components.moonraker.moonraker import Moonraker
|
||||
from components.moonraker.services.moonraker_instance_service import (
|
||||
MoonrakerInstanceService,
|
||||
)
|
||||
from core.backup_manager.backup_manager import BackupManager
|
||||
from core.instance_manager.instance_manager import InstanceManager
|
||||
from core.logger import DialogType, Logger
|
||||
from core.services.backup_service import BackupService
|
||||
from extensions.base_extension import BaseExtension
|
||||
from extensions.spoolman import (
|
||||
SPOOLMAN_COMPOSE_FILE,
|
||||
@@ -100,6 +101,7 @@ class SpoolmanExtension(BaseExtension):
|
||||
mr_instances: List[Moonraker] = mrsvc.get_all_instances()
|
||||
|
||||
Logger.print_status("Removing Spoolman configuration from moonraker.conf...")
|
||||
BackupService().backup_moonraker_conf()
|
||||
remove_config_section("spoolman", mr_instances)
|
||||
|
||||
Logger.print_status("Removing Spoolman from moonraker.asvc...")
|
||||
@@ -123,16 +125,15 @@ class SpoolmanExtension(BaseExtension):
|
||||
"Failed to remove Spoolman image! Please remove it manually."
|
||||
)
|
||||
|
||||
# backup Spoolman directory to ~/spoolman_data-<timestamp> before removing it
|
||||
try:
|
||||
bm = BackupManager()
|
||||
result = bm.backup_directory(
|
||||
f"{SPOOLMAN_DIR.name}_data",
|
||||
source=SPOOLMAN_DIR,
|
||||
target=SPOOLMAN_DIR.parent,
|
||||
svc = BackupService()
|
||||
success = svc.backup_directory(
|
||||
source_path=SPOOLMAN_DIR,
|
||||
backup_name="spoolman",
|
||||
target_path="spoolman",
|
||||
)
|
||||
if result:
|
||||
Logger.print_ok(f"Spoolman data backed up to {result}")
|
||||
if success:
|
||||
Logger.print_ok(f"Spoolman data backed up to {success}")
|
||||
Logger.print_status("Removing Spoolman directory...")
|
||||
if run_remove_routines(SPOOLMAN_DIR):
|
||||
Logger.print_ok("Spoolman directory removed!")
|
||||
@@ -290,6 +291,7 @@ class SpoolmanExtension(BaseExtension):
|
||||
mrsvc.load_instances()
|
||||
mr_instances = mrsvc.get_all_instances()
|
||||
|
||||
BackupService().backup_moonraker_conf()
|
||||
# noinspection HttpUrlsUsage
|
||||
add_config_section(
|
||||
section="spoolman",
|
||||
@@ -310,13 +312,19 @@ class SpoolmanExtension(BaseExtension):
|
||||
mrsvc.load_instances()
|
||||
mr_instances = mrsvc.get_all_instances()
|
||||
for instance in mr_instances:
|
||||
asvc_path = instance.data_dir.joinpath("moonraker.asvc")
|
||||
if asvc_path.exists():
|
||||
if "Spoolman" in open(asvc_path).read():
|
||||
Logger.print_info(f"Spoolman already in {asvc_path}. Skipping...")
|
||||
asvc_path: Path = instance.data_dir.joinpath("moonraker.asvc")
|
||||
if asvc_path.exists() and asvc_path.is_file():
|
||||
with open(asvc_path, "a+") as f:
|
||||
if "Spoolman" in f.read():
|
||||
Logger.print_info(
|
||||
f"Spoolman already in {asvc_path}. Skipping..."
|
||||
)
|
||||
continue
|
||||
|
||||
with open(asvc_path, "a") as f:
|
||||
content: List[str] = f.readlines()
|
||||
if content and not content[-1].endswith("\n"):
|
||||
f.write("\n")
|
||||
|
||||
f.write("Spoolman\n")
|
||||
|
||||
Logger.print_ok(f"Spoolman added to {asvc_path}!")
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
"maintained_by": "nlef",
|
||||
"display_name": "Moonraker Telegram Bot",
|
||||
"description": ["Control your printer with the Telegram messenger app."],
|
||||
"project_url": "https://github.com/nlef/moonraker-telegram-bot",
|
||||
"repo": "https://github.com/nlef/moonraker-telegram-bot",
|
||||
"updates": true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ from typing import List
|
||||
from components.moonraker.moonraker import Moonraker
|
||||
from core.instance_manager.instance_manager import InstanceManager
|
||||
from core.logger import DialogType, Logger
|
||||
from core.services.backup_service import BackupService
|
||||
from extensions.base_extension import BaseExtension
|
||||
from extensions.telegram_bot import TG_BOT_REPO, TG_BOT_REQ_FILE
|
||||
from extensions.telegram_bot.moonraker_telegram_bot import (
|
||||
@@ -105,6 +106,7 @@ class TelegramBotExtension(BaseExtension):
|
||||
cmd_sysctl_manage("daemon-reload")
|
||||
|
||||
# add to moonraker update manager
|
||||
BackupService().backup_moonraker_conf()
|
||||
self._patch_bot_update_manager(mr_instances)
|
||||
|
||||
# restart moonraker
|
||||
@@ -150,6 +152,7 @@ class TelegramBotExtension(BaseExtension):
|
||||
self._remove_bot_instances(tb_instances)
|
||||
self._remove_bot_dir()
|
||||
self._remove_bot_env()
|
||||
BackupService().backup_moonraker_conf()
|
||||
remove_config_section("update_manager moonraker-telegram-bot", mr_instances)
|
||||
self._delete_bot_logs(tb_instances)
|
||||
except Exception as e:
|
||||
|
||||
@@ -27,3 +27,7 @@ def main() -> None:
|
||||
MainMenu().run()
|
||||
except KeyboardInterrupt:
|
||||
Logger.print_ok("\nHappy printing!\n", prefix=False)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
@@ -13,7 +13,6 @@ from pathlib import Path
|
||||
from typing import Literal
|
||||
|
||||
from components.klipper import (
|
||||
KLIPPER_BACKUP_DIR,
|
||||
KLIPPER_DIR,
|
||||
KLIPPER_ENV_DIR,
|
||||
KLIPPER_REQ_FILE,
|
||||
@@ -21,7 +20,6 @@ from components.klipper import (
|
||||
from components.klipper.klipper import Klipper
|
||||
from components.klipper.klipper_utils import install_klipper_packages
|
||||
from components.moonraker import (
|
||||
MOONRAKER_BACKUP_DIR,
|
||||
MOONRAKER_DIR,
|
||||
MOONRAKER_ENV_DIR,
|
||||
MOONRAKER_REQ_FILE,
|
||||
@@ -30,10 +28,10 @@ from components.moonraker.moonraker import Moonraker
|
||||
from components.moonraker.services.moonraker_setup_service import (
|
||||
install_moonraker_packages,
|
||||
)
|
||||
from core.backup_manager.backup_manager import BackupManager, BackupManagerException
|
||||
from core.instance_manager.instance_manager import InstanceManager
|
||||
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.sys_utils import (
|
||||
VenvCreationFailedException,
|
||||
@@ -52,7 +50,6 @@ def run_switch_repo_routine(
|
||||
repo_dir: Path = KLIPPER_DIR if name == "klipper" else MOONRAKER_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
|
||||
backup_dir: Path = KLIPPER_BACKUP_DIR if name == "klipper" else MOONRAKER_BACKUP_DIR
|
||||
_type = Klipper if name == "klipper" else Moonraker
|
||||
|
||||
# step 1: stop all instances
|
||||
@@ -64,19 +61,17 @@ def run_switch_repo_routine(
|
||||
env_dir_backup_path: Path | None = None
|
||||
|
||||
try:
|
||||
# step 2: backup old repo and env
|
||||
org, _ = get_repo_name(repo_dir)
|
||||
backup_dir = backup_dir.joinpath(org)
|
||||
bm = BackupManager()
|
||||
repo_dir_backup_path = bm.backup_directory(
|
||||
repo_dir.name,
|
||||
repo_dir,
|
||||
backup_dir,
|
||||
svc = BackupService()
|
||||
svc.backup_directory(
|
||||
source_path=repo_dir,
|
||||
backup_name=name,
|
||||
target_path=name,
|
||||
)
|
||||
env_dir_backup_path = bm.backup_directory(
|
||||
env_dir.name,
|
||||
env_dir,
|
||||
backup_dir,
|
||||
env_backup_name: str = f"{name if name == 'moonraker' else 'klippy'}-env"
|
||||
svc.backup_directory(
|
||||
source_path=env_dir,
|
||||
backup_name=env_backup_name,
|
||||
target_path=name,
|
||||
)
|
||||
|
||||
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}!")
|
||||
|
||||
except BackupManagerException as e:
|
||||
Logger.print_error(f"Error during backup of repository: {e}")
|
||||
raise RepoSwitchFailedException(e)
|
||||
|
||||
except (GitException, VenvCreationFailedException) as e:
|
||||
# if something goes wrong during cloning or recreating the virtualenv,
|
||||
# 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}")
|
||||
return
|
||||
|
||||
except Exception as e:
|
||||
raise RepoSwitchFailedException(e)
|
||||
|
||||
Logger.print_status(f"Restarting all {_type.__name__} instances ...")
|
||||
InstanceManager.start_all(instances)
|
||||
|
||||
|
||||
@@ -14,11 +14,9 @@ from datetime import datetime
|
||||
from pathlib import Path
|
||||
from typing import Dict, List, Literal, Set
|
||||
|
||||
from components.klipper.klipper import Klipper
|
||||
from components.moonraker.moonraker import Moonraker
|
||||
from core.constants import (
|
||||
GLOBAL_DEPS,
|
||||
PRINTER_DATA_BACKUP_DIR,
|
||||
)
|
||||
from core.logger import DialogType, Logger
|
||||
from core.types.color import Color
|
||||
@@ -151,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]:
|
||||
"""
|
||||
Helper method to check if a Moonraker instance exists
|
||||
|
||||
@@ -48,7 +48,9 @@ def add_config_section(
|
||||
|
||||
if options is not None:
|
||||
for option in reversed(options):
|
||||
scp.set_option(section, option[0], option[1])
|
||||
opt_name = option[0]
|
||||
opt_value = option[1]
|
||||
scp.set_option(section, opt_name, opt_value)
|
||||
|
||||
scp.write_file(cfg_file)
|
||||
|
||||
@@ -73,7 +75,7 @@ def add_config_section_at_top(section: str, instances: List[InstanceType]) -> No
|
||||
tmp.writelines(org_content)
|
||||
|
||||
cfg_file.unlink()
|
||||
shutil.move(tmp_cfg_path, cfg_file)
|
||||
shutil.move(tmp_cfg_path.as_posix(), cfg_file)
|
||||
|
||||
Logger.print_ok("OK!")
|
||||
|
||||
@@ -81,7 +83,7 @@ def add_config_section_at_top(section: str, instances: List[InstanceType]) -> No
|
||||
def remove_config_section(
|
||||
section: str, instances: List[InstanceType]
|
||||
) -> List[InstanceType]:
|
||||
removed_from: List[instances] = []
|
||||
removed_from: List[InstanceType] = []
|
||||
for instance in instances:
|
||||
cfg_file = instance.cfg_file
|
||||
Logger.print_status(f"Remove section '[{section}]' from '{cfg_file}' ...")
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import re
|
||||
import shutil
|
||||
import urllib.request
|
||||
from http.client import HTTPResponse
|
||||
@@ -121,6 +120,59 @@ def get_local_tags(repo_path: Path, _filter: str | None = None) -> List[str]:
|
||||
:param _filter: Optional filter to filter the tags by
|
||||
:return: List of tags
|
||||
"""
|
||||
|
||||
def parse_version(version: str) -> tuple:
|
||||
# Remove 'v' prefix if present
|
||||
if version.startswith("v") and version[1:][0].isdigit():
|
||||
version = version[1:]
|
||||
|
||||
# Split into version parts and pre-release parts
|
||||
if "-" in version:
|
||||
version_part, pre_part = version.split("-", 1)
|
||||
pre_parts = pre_part.replace("-", ".").split(".")
|
||||
else:
|
||||
version_part = version
|
||||
pre_parts = []
|
||||
|
||||
# Split version into components
|
||||
version_parts = version_part.split(".")
|
||||
|
||||
# Convert to integers where possible
|
||||
def try_int(x):
|
||||
try:
|
||||
return int(x)
|
||||
except ValueError:
|
||||
return (
|
||||
x.lower()
|
||||
) # Convert strings to lowercase for case-insensitive comparison
|
||||
|
||||
version_ints = [try_int(part) for part in version_parts]
|
||||
|
||||
# Pad version parts to at least 3 components
|
||||
while len(version_ints) < 3:
|
||||
version_ints.append(0)
|
||||
|
||||
# Handle pre-release versions
|
||||
pre_type = 999 # High number for stable releases
|
||||
pre_num = 0
|
||||
|
||||
if pre_parts:
|
||||
pre_type_map = {"alpha": 0, "beta": 1, "rc": 2}
|
||||
pre_type = pre_type_map.get(
|
||||
pre_parts[0].lower(), 3
|
||||
) # Default to 3 for unknown pre-release types
|
||||
|
||||
if len(pre_parts) > 1 and str(pre_parts[1]).isdigit():
|
||||
pre_num = int(pre_parts[1])
|
||||
|
||||
return (
|
||||
version_ints[0], # major
|
||||
version_ints[1], # minor
|
||||
version_ints[2], # patch
|
||||
pre_type, # pre-release type (higher number = more stable)
|
||||
pre_num, # pre-release number
|
||||
)
|
||||
|
||||
try:
|
||||
cmd: List[str] = ["git", "tag", "-l"]
|
||||
|
||||
@@ -135,10 +187,8 @@ def get_local_tags(repo_path: Path, _filter: str | None = None) -> List[str]:
|
||||
|
||||
tags: List[str] = result.split("\n")[:-1]
|
||||
|
||||
return sorted(
|
||||
tags,
|
||||
key=lambda x: [int(i) if i.isdigit() else i for i in re.split(r"(\d+)", x)],
|
||||
)
|
||||
# Sort using our custom version parser
|
||||
return sorted(tags, key=parse_version)
|
||||
|
||||
except CalledProcessError:
|
||||
return []
|
||||
|
||||
84
mkdocs.yml
84
mkdocs.yml
@@ -1,84 +0,0 @@
|
||||
site_name: KIAUH Documentation
|
||||
site_description: Documentation for the Klipper Installation And Update Helper
|
||||
repo_url: https://github.com/dw-0/kiauh
|
||||
repo_name: dw-0/kiauh
|
||||
edit_uri: edit/master/docs
|
||||
|
||||
copyright: Copyright © 2025 Dominik Willner
|
||||
|
||||
theme:
|
||||
name: material
|
||||
logo: assets/logo.png
|
||||
favicon: assets/logo.png
|
||||
icon:
|
||||
repo: fontawesome/brands/github
|
||||
palette:
|
||||
- media: "(prefers-color-scheme: light)"
|
||||
scheme: default
|
||||
primary: blue-grey
|
||||
accent: cyan
|
||||
toggle:
|
||||
icon: material/weather-night
|
||||
name: Switch to dark mode
|
||||
- media: "(prefers-color-scheme: dark)"
|
||||
scheme: slate
|
||||
primary: blue-grey
|
||||
accent: cyan
|
||||
toggle:
|
||||
icon: material/weather-sunny
|
||||
name: Switch to light mode
|
||||
features:
|
||||
- navigation.instant
|
||||
- navigation.tracking
|
||||
- navigation.sections
|
||||
- navigation.expand
|
||||
- navigation.indexes
|
||||
- navigation.top
|
||||
- toc.follow
|
||||
- content.code.copy
|
||||
|
||||
plugins:
|
||||
- search
|
||||
- git-revision-date-localized:
|
||||
enable_creation_date: true
|
||||
- mkdocstrings:
|
||||
handlers:
|
||||
python:
|
||||
paths: [.]
|
||||
options:
|
||||
docstring_style: google
|
||||
|
||||
markdown_extensions:
|
||||
- admonition
|
||||
- pymdownx.details
|
||||
- pymdownx.superfences
|
||||
- pymdownx.highlight:
|
||||
anchor_linenums: true
|
||||
- pymdownx.inlinehilite
|
||||
- pymdownx.snippets
|
||||
- pymdownx.superfences
|
||||
- tables
|
||||
- attr_list
|
||||
- md_in_html
|
||||
|
||||
nav:
|
||||
- Home: index.md
|
||||
- Installation:
|
||||
- setup/raspberry-pi-setup.md
|
||||
- setup/installation.md
|
||||
- Configuration: configuration.md
|
||||
- Extensions:
|
||||
- extensions/index.md
|
||||
- extensions/gcode-shell-command.md
|
||||
- Development:
|
||||
- development/contributing.md
|
||||
- development/changelog.md
|
||||
|
||||
extra:
|
||||
social:
|
||||
- icon: simple/github
|
||||
link: https://github.com/dw-0
|
||||
- icon: simple/kofi
|
||||
link: https://ko-fi.com/dw__0
|
||||
- icon: simple/paypal
|
||||
link: https://www.paypal.com/paypalme/dwillner0
|
||||
@@ -2,7 +2,7 @@
|
||||
requires-python = ">=3.8"
|
||||
|
||||
[project.optional-dependencies]
|
||||
dev=["ruff", "pyright"]
|
||||
dev=["ruff", "mypy"]
|
||||
|
||||
[tool.ruff]
|
||||
required-version = ">=0.9.10"
|
||||
@@ -20,3 +20,14 @@ quote-style = "double"
|
||||
|
||||
[tool.ruff.lint]
|
||||
extend-select = ["I"]
|
||||
|
||||
[tool.mypy]
|
||||
python_version = "3.8"
|
||||
platform = "linux"
|
||||
# strict = true # TODO: enable this once everything is else is handled
|
||||
check_untyped_defs = true
|
||||
ignore_missing_imports = true
|
||||
warn_redundant_casts = true
|
||||
warn_unused_ignores = true
|
||||
warn_return_any = true
|
||||
warn_unreachable = true
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"pythonVersion": "3.8",
|
||||
"pythonPlatform": "Linux",
|
||||
"typeCheckingMode": "standard",
|
||||
"venvPath": "./.kiauh-env"
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user