lauschkiste 0.1.0a4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lauschkiste-0.1.0a4/.gitignore +48 -0
- lauschkiste-0.1.0a4/LICENSE +22 -0
- lauschkiste-0.1.0a4/PKG-INFO +99 -0
- lauschkiste-0.1.0a4/README.md +71 -0
- lauschkiste-0.1.0a4/pyproject.toml +57 -0
- lauschkiste-0.1.0a4/src/lauschkiste_cli/__init__.py +0 -0
- lauschkiste-0.1.0a4/src/lauschkiste_cli/cli.py +50 -0
- lauschkiste-0.1.0a4/src/lauschkiste_cli/config.py +89 -0
- lauschkiste-0.1.0a4/src/lauschkiste_cli/debug.py +37 -0
- lauschkiste-0.1.0a4/src/lauschkiste_cli/environment.py +23 -0
- lauschkiste-0.1.0a4/src/lauschkiste_cli/plugin.py +147 -0
- lauschkiste-0.1.0a4/src/lauschkiste_cli/run.py +72 -0
- lauschkiste-0.1.0a4/src/lauschkiste_cli/setup/__init__.py +124 -0
- lauschkiste-0.1.0a4/src/lauschkiste_cli/setup/base.py +120 -0
- lauschkiste-0.1.0a4/src/lauschkiste_cli/setup/samba.py +60 -0
- lauschkiste-0.1.0a4/src/lauschkiste_cli/setup/steps/__init__.py +12 -0
- lauschkiste-0.1.0a4/src/lauschkiste_cli/setup/steps/extras.py +310 -0
- lauschkiste-0.1.0a4/src/lauschkiste_cli/setup/steps/lauschkiste.py +263 -0
- lauschkiste-0.1.0a4/src/lauschkiste_cli/setup/steps/system.py +204 -0
- lauschkiste-0.1.0a4/src/lauschkiste_cli/setup/system.py +178 -0
- lauschkiste-0.1.0a4/src/lauschkiste_cli/update.py +247 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Shared folder
|
|
2
|
+
/shared/library/*
|
|
3
|
+
/shared/logs/*
|
|
4
|
+
/shared/playlists/*
|
|
5
|
+
/shared/settings/*
|
|
6
|
+
/shared/logs/*.log*
|
|
7
|
+
/shared/*.*
|
|
8
|
+
/shared/*
|
|
9
|
+
/packages/webapp/public/cover-cache/*.*
|
|
10
|
+
/packages/webapp/test-results/
|
|
11
|
+
/packages/lauschkiste/src/lauschkiste/webapp/
|
|
12
|
+
/dist/
|
|
13
|
+
/packages/webapp/playwright-report/
|
|
14
|
+
|
|
15
|
+
# Byte-compiled / optimized / DLL files
|
|
16
|
+
__pycache__/
|
|
17
|
+
*.py[cod]
|
|
18
|
+
|
|
19
|
+
.git
|
|
20
|
+
.venv
|
|
21
|
+
*~
|
|
22
|
+
*.*~
|
|
23
|
+
*.pyc
|
|
24
|
+
*.idea
|
|
25
|
+
*.vscode
|
|
26
|
+
.DS_Store
|
|
27
|
+
**/.mypy_cache
|
|
28
|
+
|
|
29
|
+
# Keep folders with .gitkeep
|
|
30
|
+
!/**/.gitkeep
|
|
31
|
+
|
|
32
|
+
# Development Scratchpads
|
|
33
|
+
/**/scratch
|
|
34
|
+
/**/scratch_*
|
|
35
|
+
|
|
36
|
+
# Local debug/build artifacts
|
|
37
|
+
/app.log
|
|
38
|
+
/*.tar.gz
|
|
39
|
+
|
|
40
|
+
# bam local cache and test reports
|
|
41
|
+
/.bam/
|
|
42
|
+
/.reports/
|
|
43
|
+
/.coverage
|
|
44
|
+
/coverage.xml
|
|
45
|
+
|
|
46
|
+
# Local secrets for tests and scripts (never committed)
|
|
47
|
+
.env
|
|
48
|
+
.env.local
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 Micz Flor
|
|
4
|
+
Copyright (c) 2026 the Lauschkiste contributors
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: lauschkiste
|
|
3
|
+
Version: 0.1.0a4
|
|
4
|
+
Summary: Lauschkiste: an RFID audio player for kids (the lauschkiste server and the lauschctl commands)
|
|
5
|
+
Project-URL: Homepage, https://github.com/ladidadida/lauschkiste
|
|
6
|
+
Project-URL: Documentation, https://github.com/ladidadida/lauschkiste/tree/main/documentation
|
|
7
|
+
Project-URL: Issues, https://github.com/ladidadida/lauschkiste/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/ladidadida/lauschkiste/releases
|
|
9
|
+
Author: the Lauschkiste contributors
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: audiobooks,home automation,kids,music player,raspberry pi,rfid
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: End Users/Desktop
|
|
15
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
21
|
+
Classifier: Topic :: Home Automation
|
|
22
|
+
Classifier: Topic :: Multimedia :: Sound/Audio :: Players
|
|
23
|
+
Requires-Python: >=3.11
|
|
24
|
+
Requires-Dist: lauschkiste-core==0.1.0a4
|
|
25
|
+
Requires-Dist: typer
|
|
26
|
+
Requires-Dist: websockets
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# Lauschkiste
|
|
30
|
+
|
|
31
|
+
<img src="https://raw.githubusercontent.com/ladidadida/lauschkiste/main/documentation/assets/logo/white/lauschkiste-logo-text-berry-white.svg" alt="Lauschkiste" width="380">
|
|
32
|
+
|
|
33
|
+
**An open-source RFID audio player for kids.** Put a card on the box and music or an audiobook
|
|
34
|
+
starts. Made for the Raspberry Pi (from the Zero up), runs on any Linux computer, managed from any browser. Alpha software.
|
|
35
|
+
|
|
36
|
+
*Lauschkiste* is German: *lauschen* means to listen closely, *die Kiste* is the box.
|
|
37
|
+
|
|
38
|
+
## Features
|
|
39
|
+
|
|
40
|
+
- RFID/NFC cards start albums, audiobooks, podcasts, radio stations or actions (volume, timers, shutdown, ...)
|
|
41
|
+
- Audiobooks also from an Audiobookshelf server (with downloads for offline use); podcast and radio search
|
|
42
|
+
- Quiet hours and a daily listening time
|
|
43
|
+
- Web app for the library, cards, settings and playback
|
|
44
|
+
- Built-in player, no extra audio daemon needed; MPD as a plugin
|
|
45
|
+
- Plugins for RFID readers, Raspberry Pi hardware (buttons, encoders, LEDs, battery) and more
|
|
46
|
+
- Setup steps you can re-run safely, updates from the command line
|
|
47
|
+
|
|
48
|
+
## Installation
|
|
49
|
+
|
|
50
|
+
On a Raspberry Pi with Raspberry Pi OS (Lite) or another Debian, the installer sets up everything
|
|
51
|
+
(system packages, the service, the Samba share and more, asking before each step):
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
curl -fsSL https://raw.githubusercontent.com/ladidadida/lauschkiste/main/install.sh | bash
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Only the Python package (Python 3.11 or newer, Linux, PortAudio for the sound output). While there
|
|
58
|
+
are only pre-releases, pip needs `--pre`:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
uv tool install lauschkiste # or: pipx install --pip-args=--pre lauschkiste
|
|
62
|
+
lauschkiste # start the server, the web app is on http://localhost:5556
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
This package installs the server (`lauschkiste`) and the management command `lauschctl`:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
lauschctl setup --check # what is set up on this machine
|
|
69
|
+
lauschctl plugin list # installed plugins
|
|
70
|
+
lauschctl update # newer version
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Packages
|
|
74
|
+
|
|
75
|
+
| Package | Contents |
|
|
76
|
+
| --- | --- |
|
|
77
|
+
| `lauschkiste` | this package: the commands |
|
|
78
|
+
| `lauschkiste-core` | the player, library, cards, volume, timers, web API and web app |
|
|
79
|
+
| `lauschkiste-plugin-board-raspberry-pi` | Raspberry Pi board support (pins, boot configuration, power) |
|
|
80
|
+
| `lauschkiste-plugin-devices` | GPIO buttons, rotary encoders, LEDs, battery monitor, power button, pHAT BEAT |
|
|
81
|
+
| `lauschkiste-plugin-rfid-readers` | RFID reader drivers |
|
|
82
|
+
| `lauschkiste-plugin-mpd` | MPD as a player backend |
|
|
83
|
+
| `lauschkiste-plugin-samba` | share the library on the network |
|
|
84
|
+
| `lauschkiste-plugin-audiobookshelf` | audiobooks from an Audiobookshelf server |
|
|
85
|
+
| `lauschkiste-plugin-directories` | find podcasts and radio stations (Apple, fyyd, Podcast Index, radio-browser) |
|
|
86
|
+
|
|
87
|
+
Plugins are installed next to this package and switched on in the web app or with
|
|
88
|
+
`lauschctl plugin enable <name>`.
|
|
89
|
+
|
|
90
|
+
## Documentation
|
|
91
|
+
|
|
92
|
+
- [For builders](https://github.com/ladidadida/lauschkiste/blob/main/documentation/builders/README.md): installation, configuration, hardware
|
|
93
|
+
- [For developers](https://github.com/ladidadida/lauschkiste/blob/main/documentation/developers/README.md): architecture, plugins, development setup
|
|
94
|
+
|
|
95
|
+
## Origin and license
|
|
96
|
+
|
|
97
|
+
Lauschkiste grew out of [Phoniebox](https://github.com/MiczFlor/RPi-Jukebox-RFID), the RFID
|
|
98
|
+
jukebox started by Micz Flor, and keeps its history. It is not a drop-in replacement: settings and card files of
|
|
99
|
+
Phoniebox are not compatible. MIT license.
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# Lauschkiste
|
|
2
|
+
|
|
3
|
+
<img src="https://raw.githubusercontent.com/ladidadida/lauschkiste/main/documentation/assets/logo/white/lauschkiste-logo-text-berry-white.svg" alt="Lauschkiste" width="380">
|
|
4
|
+
|
|
5
|
+
**An open-source RFID audio player for kids.** Put a card on the box and music or an audiobook
|
|
6
|
+
starts. Made for the Raspberry Pi (from the Zero up), runs on any Linux computer, managed from any browser. Alpha software.
|
|
7
|
+
|
|
8
|
+
*Lauschkiste* is German: *lauschen* means to listen closely, *die Kiste* is the box.
|
|
9
|
+
|
|
10
|
+
## Features
|
|
11
|
+
|
|
12
|
+
- RFID/NFC cards start albums, audiobooks, podcasts, radio stations or actions (volume, timers, shutdown, ...)
|
|
13
|
+
- Audiobooks also from an Audiobookshelf server (with downloads for offline use); podcast and radio search
|
|
14
|
+
- Quiet hours and a daily listening time
|
|
15
|
+
- Web app for the library, cards, settings and playback
|
|
16
|
+
- Built-in player, no extra audio daemon needed; MPD as a plugin
|
|
17
|
+
- Plugins for RFID readers, Raspberry Pi hardware (buttons, encoders, LEDs, battery) and more
|
|
18
|
+
- Setup steps you can re-run safely, updates from the command line
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
On a Raspberry Pi with Raspberry Pi OS (Lite) or another Debian, the installer sets up everything
|
|
23
|
+
(system packages, the service, the Samba share and more, asking before each step):
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
curl -fsSL https://raw.githubusercontent.com/ladidadida/lauschkiste/main/install.sh | bash
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Only the Python package (Python 3.11 or newer, Linux, PortAudio for the sound output). While there
|
|
30
|
+
are only pre-releases, pip needs `--pre`:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
uv tool install lauschkiste # or: pipx install --pip-args=--pre lauschkiste
|
|
34
|
+
lauschkiste # start the server, the web app is on http://localhost:5556
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
This package installs the server (`lauschkiste`) and the management command `lauschctl`:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
lauschctl setup --check # what is set up on this machine
|
|
41
|
+
lauschctl plugin list # installed plugins
|
|
42
|
+
lauschctl update # newer version
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Packages
|
|
46
|
+
|
|
47
|
+
| Package | Contents |
|
|
48
|
+
| --- | --- |
|
|
49
|
+
| `lauschkiste` | this package: the commands |
|
|
50
|
+
| `lauschkiste-core` | the player, library, cards, volume, timers, web API and web app |
|
|
51
|
+
| `lauschkiste-plugin-board-raspberry-pi` | Raspberry Pi board support (pins, boot configuration, power) |
|
|
52
|
+
| `lauschkiste-plugin-devices` | GPIO buttons, rotary encoders, LEDs, battery monitor, power button, pHAT BEAT |
|
|
53
|
+
| `lauschkiste-plugin-rfid-readers` | RFID reader drivers |
|
|
54
|
+
| `lauschkiste-plugin-mpd` | MPD as a player backend |
|
|
55
|
+
| `lauschkiste-plugin-samba` | share the library on the network |
|
|
56
|
+
| `lauschkiste-plugin-audiobookshelf` | audiobooks from an Audiobookshelf server |
|
|
57
|
+
| `lauschkiste-plugin-directories` | find podcasts and radio stations (Apple, fyyd, Podcast Index, radio-browser) |
|
|
58
|
+
|
|
59
|
+
Plugins are installed next to this package and switched on in the web app or with
|
|
60
|
+
`lauschctl plugin enable <name>`.
|
|
61
|
+
|
|
62
|
+
## Documentation
|
|
63
|
+
|
|
64
|
+
- [For builders](https://github.com/ladidadida/lauschkiste/blob/main/documentation/builders/README.md): installation, configuration, hardware
|
|
65
|
+
- [For developers](https://github.com/ladidadida/lauschkiste/blob/main/documentation/developers/README.md): architecture, plugins, development setup
|
|
66
|
+
|
|
67
|
+
## Origin and license
|
|
68
|
+
|
|
69
|
+
Lauschkiste grew out of [Phoniebox](https://github.com/MiczFlor/RPi-Jukebox-RFID), the RFID
|
|
70
|
+
jukebox started by Micz Flor, and keeps its history. It is not a drop-in replacement: settings and card files of
|
|
71
|
+
Phoniebox are not compatible. MIT license.
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "lauschkiste"
|
|
3
|
+
version = "0.1.0a4"
|
|
4
|
+
description = "Lauschkiste: an RFID audio player for kids (the lauschkiste server and the lauschctl commands)"
|
|
5
|
+
license = "MIT"
|
|
6
|
+
requires-python = ">=3.11"
|
|
7
|
+
readme = "README.md"
|
|
8
|
+
authors = [{ name = "the Lauschkiste contributors" }]
|
|
9
|
+
keywords = [
|
|
10
|
+
"rfid",
|
|
11
|
+
"music player",
|
|
12
|
+
"audiobooks",
|
|
13
|
+
"kids",
|
|
14
|
+
"raspberry pi",
|
|
15
|
+
"home automation",
|
|
16
|
+
]
|
|
17
|
+
classifiers = [
|
|
18
|
+
"Development Status :: 3 - Alpha",
|
|
19
|
+
"Intended Audience :: End Users/Desktop",
|
|
20
|
+
"Operating System :: POSIX :: Linux",
|
|
21
|
+
"Programming Language :: Python :: 3",
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
"Programming Language :: Python :: 3.13",
|
|
25
|
+
"Programming Language :: Python :: 3.14",
|
|
26
|
+
"Topic :: Multimedia :: Sound/Audio :: Players",
|
|
27
|
+
"Topic :: Home Automation",
|
|
28
|
+
]
|
|
29
|
+
license-files = ["LICENSE"]
|
|
30
|
+
dependencies = [
|
|
31
|
+
"typer",
|
|
32
|
+
"websockets",
|
|
33
|
+
"lauschkiste-core==0.1.0a4",
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
[project.urls]
|
|
37
|
+
Homepage = "https://github.com/ladidadida/lauschkiste"
|
|
38
|
+
Documentation = "https://github.com/ladidadida/lauschkiste/tree/main/documentation"
|
|
39
|
+
Issues = "https://github.com/ladidadida/lauschkiste/issues"
|
|
40
|
+
Changelog = "https://github.com/ladidadida/lauschkiste/releases"
|
|
41
|
+
|
|
42
|
+
[tool.uv]
|
|
43
|
+
package = true
|
|
44
|
+
|
|
45
|
+
[tool.uv.sources]
|
|
46
|
+
lauschkiste-core = { workspace = true }
|
|
47
|
+
|
|
48
|
+
[project.scripts]
|
|
49
|
+
lauschkiste = "lauschkiste_cli.cli:server"
|
|
50
|
+
lauschctl = "lauschkiste_cli.cli:ctl"
|
|
51
|
+
|
|
52
|
+
[build-system]
|
|
53
|
+
requires = ["hatchling"]
|
|
54
|
+
build-backend = "hatchling.build"
|
|
55
|
+
|
|
56
|
+
[tool.hatch.build.targets.wheel]
|
|
57
|
+
packages = ["src/lauschkiste_cli"]
|
|
File without changes
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
from typing import Optional
|
|
3
|
+
|
|
4
|
+
import typer
|
|
5
|
+
|
|
6
|
+
import lauschkiste.paths
|
|
7
|
+
from lauschkiste_cli.run import run
|
|
8
|
+
|
|
9
|
+
HOME_HELP = ("Directory with all data (settings, music, logs). "
|
|
10
|
+
"Default: $XDG_DATA_HOME/lauschkiste (~/.local/share/lauschkiste).")
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def main(home: Optional[Path] = typer.Option(
|
|
14
|
+
None, "--home", envvar=lauschkiste.paths.env_name("HOME"), help=HOME_HELP)) -> None:
|
|
15
|
+
lauschkiste.paths.set_home(home)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def show_home() -> None:
|
|
19
|
+
"""Print the home directory and the configuration file in use."""
|
|
20
|
+
typer.echo(f"home: {lauschkiste.paths.home()}")
|
|
21
|
+
typer.echo(f"config: {lauschkiste.paths.config_file()}")
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _management_app(name: str, help_text: str) -> typer.Typer:
|
|
25
|
+
from lauschkiste_cli import config, debug, plugin
|
|
26
|
+
from lauschkiste_cli.setup import setup
|
|
27
|
+
from lauschkiste_cli.update import update
|
|
28
|
+
|
|
29
|
+
app = typer.Typer(name=name, help=help_text, no_args_is_help=True)
|
|
30
|
+
app.callback()(main)
|
|
31
|
+
app.command(name="home")(show_home)
|
|
32
|
+
app.command(name="setup")(setup)
|
|
33
|
+
app.command(name="update")(update)
|
|
34
|
+
app.add_typer(config.app, name="config")
|
|
35
|
+
app.add_typer(debug.app, name="debug")
|
|
36
|
+
app.add_typer(plugin.app, name="plugin")
|
|
37
|
+
return app
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
#: `lauschkiste`: the server
|
|
41
|
+
server = typer.Typer(name="lauschkiste", add_completion=False)
|
|
42
|
+
server.command()(run)
|
|
43
|
+
|
|
44
|
+
def __getattr__(name: str):
|
|
45
|
+
"""`ctl` (`lauschctl`: everything else) is built on first use, so the server doesn't import it."""
|
|
46
|
+
if name == 'ctl':
|
|
47
|
+
app = _management_app("lauschctl", "Manage Lauschkiste: setup, plugins, updates.")
|
|
48
|
+
globals()['ctl'] = app
|
|
49
|
+
return app
|
|
50
|
+
raise AttributeError(name)
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"""`lauschctl config ...`: read and change single settings in the configuration file."""
|
|
2
|
+
|
|
3
|
+
from io import StringIO
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Optional
|
|
6
|
+
|
|
7
|
+
import typer
|
|
8
|
+
from ruamel.yaml import YAML, YAMLError
|
|
9
|
+
|
|
10
|
+
import lauschkiste.cfghandler
|
|
11
|
+
from lauschkiste.contract.secrets import SecretStore, secrets_path
|
|
12
|
+
from lauschkiste_cli.plugin import ConfOption, _config
|
|
13
|
+
|
|
14
|
+
app = typer.Typer(help="Read and change single settings.", no_args_is_help=True)
|
|
15
|
+
|
|
16
|
+
_MISSING = object()
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def _keys(key: str) -> list:
|
|
20
|
+
keys = key.split('.')
|
|
21
|
+
if not all(keys):
|
|
22
|
+
raise typer.BadParameter(f"'{key}' is not a setting name like library.path")
|
|
23
|
+
return keys
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _dump(value) -> str:
|
|
27
|
+
if isinstance(value, bool):
|
|
28
|
+
return 'true' if value else 'false'
|
|
29
|
+
if not isinstance(value, (dict, list)):
|
|
30
|
+
return str(value)
|
|
31
|
+
out = StringIO()
|
|
32
|
+
yaml = YAML(typ='safe')
|
|
33
|
+
yaml.default_flow_style = None
|
|
34
|
+
yaml.dump(_plain(value), out)
|
|
35
|
+
return out.getvalue().rstrip()
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _plain(value):
|
|
39
|
+
if isinstance(value, dict):
|
|
40
|
+
return {k: _plain(v) for k, v in value.items()}
|
|
41
|
+
if isinstance(value, list):
|
|
42
|
+
return [_plain(v) for v in value]
|
|
43
|
+
return value
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@app.command('get')
|
|
47
|
+
def get_setting(key: str = typer.Argument(..., help="e.g. library.path"),
|
|
48
|
+
reveal: bool = typer.Option(False, "--reveal", help="print a secret instead of hiding it"),
|
|
49
|
+
conf: Optional[Path] = ConfOption) -> None:
|
|
50
|
+
"""Print a setting (a section is printed as YAML); secrets are hidden."""
|
|
51
|
+
cfg, path = _config(conf)
|
|
52
|
+
secret = SecretStore(secrets_path(str(path))).get(*_keys(key))
|
|
53
|
+
if secret is not None:
|
|
54
|
+
typer.echo(secret if reveal else '(secret, set)')
|
|
55
|
+
return
|
|
56
|
+
value = cfg.getn(*_keys(key), default=_MISSING)
|
|
57
|
+
if value is _MISSING:
|
|
58
|
+
typer.echo(f"{key} is not set in the configuration file", err=True)
|
|
59
|
+
raise typer.Exit(1)
|
|
60
|
+
typer.echo(_dump(value))
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
@app.command('set')
|
|
64
|
+
def set_setting(key: str = typer.Argument(..., help="e.g. library.path"),
|
|
65
|
+
value: Optional[str] = typer.Argument(None, help="a YAML value: text, number, true/false, [a, b]"),
|
|
66
|
+
secret: bool = typer.Option(False, "--secret", help="keep it in secrets.yaml (asks for the value)"),
|
|
67
|
+
conf: Optional[Path] = ConfOption) -> None:
|
|
68
|
+
"""Change a setting. Takes effect when Lauschkiste is restarted."""
|
|
69
|
+
keys = _keys(key)
|
|
70
|
+
if secret:
|
|
71
|
+
path = _config(conf)[1]
|
|
72
|
+
if value is None:
|
|
73
|
+
value = typer.prompt(key, hide_input=True)
|
|
74
|
+
SecretStore(secrets_path(str(path))).set(*keys, value=value)
|
|
75
|
+
typer.echo(f"{key}: (secret)")
|
|
76
|
+
return
|
|
77
|
+
if value is None:
|
|
78
|
+
raise typer.BadParameter("a value is needed (or --secret to be asked for one)")
|
|
79
|
+
try:
|
|
80
|
+
parsed = YAML(typ='safe').load(value)
|
|
81
|
+
except YAMLError:
|
|
82
|
+
parsed = value
|
|
83
|
+
cfg, path = _config(conf)
|
|
84
|
+
if isinstance(cfg.getn(*keys, default=None), dict):
|
|
85
|
+
typer.echo(f"{key} is a section; set one of its settings, e.g. {key}.<name>", err=True)
|
|
86
|
+
raise typer.Exit(1)
|
|
87
|
+
cfg.setn(*keys, value=parsed)
|
|
88
|
+
lauschkiste.cfghandler.write_yaml(cfg, str(path))
|
|
89
|
+
typer.echo(f"{key}: {_dump(parsed)}")
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import json
|
|
3
|
+
from typing import Optional
|
|
4
|
+
|
|
5
|
+
import typer
|
|
6
|
+
import websockets
|
|
7
|
+
|
|
8
|
+
app = typer.Typer(help="Developer/debugging tools.")
|
|
9
|
+
|
|
10
|
+
TOPIC_WIDTH = 40
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
async def _sniff(port: int, topics: Optional[list[str]]) -> None:
|
|
14
|
+
url = f"ws://localhost:{port}/api/v1/events"
|
|
15
|
+
async with websockets.connect(url) as websocket:
|
|
16
|
+
await websocket.send(json.dumps({'type': 'subscribe', 'topics': topics or ['']}))
|
|
17
|
+
while True:
|
|
18
|
+
message = json.loads(await websocket.recv())
|
|
19
|
+
if message['type'] == 'revoke':
|
|
20
|
+
print(f"{message['topic']:{TOPIC_WIDTH}}: <revoked>")
|
|
21
|
+
else:
|
|
22
|
+
print(f"{message['topic']:{TOPIC_WIDTH}}: {message['data']}")
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@app.command()
|
|
26
|
+
def sniff(
|
|
27
|
+
port: int = typer.Option(5556, "-p", "--port", help="Connect to the API server on this port"),
|
|
28
|
+
topics: Optional[list[str]] = typer.Option(
|
|
29
|
+
None, "-k", "--topics",
|
|
30
|
+
help="Subscribe to these topic tree(s). If omitted, all topics are subscribed.",
|
|
31
|
+
),
|
|
32
|
+
) -> None:
|
|
33
|
+
"""Monitor all messages Lauschkiste publishes (events)."""
|
|
34
|
+
try:
|
|
35
|
+
asyncio.run(_sniff(port, topics))
|
|
36
|
+
except KeyboardInterrupt:
|
|
37
|
+
pass
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""How Lauschkiste is installed: from a source checkout or as a package."""
|
|
2
|
+
|
|
3
|
+
import shutil
|
|
4
|
+
import sys
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import Optional
|
|
7
|
+
|
|
8
|
+
import lauschkiste
|
|
9
|
+
|
|
10
|
+
#: Where releases (wheels) are published
|
|
11
|
+
DEFAULT_REPO = 'ladidadida/lauschkiste'
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def checkout() -> Optional[Path]:
|
|
15
|
+
"""The repository root when running from a source checkout."""
|
|
16
|
+
root = Path(lauschkiste.__file__).resolve().parents[4]
|
|
17
|
+
return root if (root / '.git').exists() and (root / 'packages' / 'lauschkiste').is_dir() else None
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def executable(name: str) -> str:
|
|
21
|
+
"""Path of one of our commands (``lauschkiste``, ``lauschctl``) in the running environment."""
|
|
22
|
+
candidate = Path(sys.executable).parent / name
|
|
23
|
+
return str(candidate) if candidate.exists() else (shutil.which(name) or name)
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"""`lauschctl plugin ...`: list installed plugins, enable/disable them in the configuration, install new ones."""
|
|
2
|
+
|
|
3
|
+
import shutil
|
|
4
|
+
import subprocess
|
|
5
|
+
import sys
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import List, Optional
|
|
8
|
+
|
|
9
|
+
import typer
|
|
10
|
+
|
|
11
|
+
import lauschkiste.cfghandler
|
|
12
|
+
import lauschkiste.contract.plugins as plugins
|
|
13
|
+
import lauschkiste.paths
|
|
14
|
+
|
|
15
|
+
app = typer.Typer(help="Manage plugins.", no_args_is_help=True)
|
|
16
|
+
|
|
17
|
+
ConfOption = typer.Option(None, "-c", "--conf", envvar=lauschkiste.paths.env_name("CONF"),
|
|
18
|
+
help="Configuration file (default: $LAUSCHKISTE_HOME/settings/lauschkiste.yaml)")
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _config(conf: Optional[Path]):
|
|
22
|
+
path = conf or lauschkiste.paths.config_file()
|
|
23
|
+
lauschkiste.cfghandler.ensure_default_config(
|
|
24
|
+
str(path), str(lauschkiste.paths.resource('default-settings', 'lauschkiste.default.yaml')))
|
|
25
|
+
cfg = lauschkiste.cfghandler.ConfigHandler('plugin-cli')
|
|
26
|
+
lauschkiste.cfghandler.load_yaml(cfg, str(path))
|
|
27
|
+
return cfg, path
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _enabled(cfg) -> dict:
|
|
31
|
+
plugins = cfg.getn('plugins', default=None)
|
|
32
|
+
return plugins if isinstance(plugins, dict) else {}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _installed():
|
|
36
|
+
return plugins.installed()
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _load(ep):
|
|
40
|
+
return plugins.load(ep)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def install_requirements(requirements: List[str]) -> None:
|
|
44
|
+
"""Install into the environment Lauschkiste runs in (uv if available, else pip)."""
|
|
45
|
+
uv = shutil.which('uv')
|
|
46
|
+
if uv:
|
|
47
|
+
command = [uv, 'pip', 'install', '--python', sys.executable, *requirements]
|
|
48
|
+
else:
|
|
49
|
+
command = [sys.executable, '-m', 'pip', 'install', *requirements]
|
|
50
|
+
typer.echo(f"$ {' '.join(command)}")
|
|
51
|
+
subprocess.run(command, check=True)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
plugin_extras = plugins.plugin_extras
|
|
55
|
+
missing_extras = plugins.missing_extras
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def add_to_config(path: Path, names: List[str]) -> List[str]:
|
|
59
|
+
"""Add ``names`` to ``plugins:`` in the configuration at ``path``; returns the newly added ones."""
|
|
60
|
+
cfg, _ = _config(path)
|
|
61
|
+
added = [name for name in names if name not in _enabled(cfg)]
|
|
62
|
+
for name in added:
|
|
63
|
+
cfg.setndefault('plugins', name, value={})
|
|
64
|
+
if added:
|
|
65
|
+
lauschkiste.cfghandler.write_yaml(cfg, str(path))
|
|
66
|
+
return added
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
@app.command('list')
|
|
70
|
+
def list_plugins(conf: Optional[Path] = ConfOption) -> None:
|
|
71
|
+
"""Installed plugins, whether they are enabled, and why one can't be loaded."""
|
|
72
|
+
cfg, path = _config(conf)
|
|
73
|
+
enabled = _enabled(cfg)
|
|
74
|
+
installed = _installed()
|
|
75
|
+
for name in sorted(set(installed) | set(enabled)):
|
|
76
|
+
ep = installed.get(name)
|
|
77
|
+
state = 'enabled ' if name in enabled else 'disabled'
|
|
78
|
+
if ep is None:
|
|
79
|
+
typer.echo(f"{state} {name:24} NOT INSTALLED")
|
|
80
|
+
continue
|
|
81
|
+
cls, problem = _load(ep)
|
|
82
|
+
dist = f"{ep.dist.name} {ep.dist.version}" if ep.dist else ''
|
|
83
|
+
summary = problem or ((cls.__doc__ or '').strip().split('\n', 1)[0])
|
|
84
|
+
typer.echo(f"{state} {name:24} {dist:36} {summary}")
|
|
85
|
+
typer.echo(f"\n(configuration: {path})")
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
@app.command()
|
|
89
|
+
def enable(name: str, conf: Optional[Path] = ConfOption,
|
|
90
|
+
with_extras: bool = typer.Option(False, "--with-extras",
|
|
91
|
+
help="Install the dependencies the plugin declares as extras")) -> None:
|
|
92
|
+
"""Enable an installed plugin (takes effect on the next start)."""
|
|
93
|
+
ep = _installed().get(name)
|
|
94
|
+
if ep is None:
|
|
95
|
+
typer.echo(f"Plugin '{name}' is not installed. Installed: {', '.join(sorted(_installed())) or 'none'}", err=True)
|
|
96
|
+
raise typer.Exit(1)
|
|
97
|
+
_, problem = _load(ep)
|
|
98
|
+
cfg, path = _config(conf)
|
|
99
|
+
reason = plugins.why_not_enable(cfg, name)
|
|
100
|
+
if reason:
|
|
101
|
+
typer.echo(f"Can't enable '{name}': {reason}", err=True)
|
|
102
|
+
raise typer.Exit(1)
|
|
103
|
+
extras = plugin_extras(name)
|
|
104
|
+
if with_extras and extras:
|
|
105
|
+
install_requirements(extras)
|
|
106
|
+
_, problem = _load(ep)
|
|
107
|
+
elif extras:
|
|
108
|
+
typer.echo(f"Note: '{name}' needs {', '.join(extras)}; install it with --with-extras if it is missing.")
|
|
109
|
+
if problem and not with_extras:
|
|
110
|
+
typer.echo(f"Warning: '{name}' can't be loaded right now: {problem}", err=True)
|
|
111
|
+
if not add_to_config(path, [name]):
|
|
112
|
+
typer.echo(f"'{name}' is already enabled in {path}")
|
|
113
|
+
return
|
|
114
|
+
typer.echo(f"Enabled '{name}' in {path}. Restart Lauschkiste to load it.")
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
@app.command()
|
|
118
|
+
def disable(name: str, conf: Optional[Path] = ConfOption) -> None:
|
|
119
|
+
"""Disable a plugin (its settings are removed from the configuration)."""
|
|
120
|
+
cfg, path = _config(conf)
|
|
121
|
+
enabled = _enabled(cfg)
|
|
122
|
+
if name not in enabled:
|
|
123
|
+
typer.echo(f"'{name}' is not enabled in {path}")
|
|
124
|
+
return
|
|
125
|
+
del enabled[name]
|
|
126
|
+
if not enabled:
|
|
127
|
+
cfg['plugins'] = {}
|
|
128
|
+
lauschkiste.cfghandler.write_yaml(cfg, str(path))
|
|
129
|
+
typer.echo(f"Disabled '{name}' in {path}. Restart Lauschkiste to unload it.")
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
@app.command()
|
|
133
|
+
def install(spec: str, conf: Optional[Path] = ConfOption,
|
|
134
|
+
enable_plugins: bool = typer.Option(False, "--enable", help="Enable the plugins the package provides")) -> None:
|
|
135
|
+
"""Install a plugin package (a pip requirement, wheel file, URL or directory)."""
|
|
136
|
+
before = set(_installed())
|
|
137
|
+
install_requirements([spec])
|
|
138
|
+
new = sorted(set(_installed()) - before)
|
|
139
|
+
if not new:
|
|
140
|
+
typer.echo("The package provides no new plugins (or they were installed already).")
|
|
141
|
+
return
|
|
142
|
+
typer.echo(f"New plugins: {', '.join(new)}")
|
|
143
|
+
for name in new:
|
|
144
|
+
if enable_plugins:
|
|
145
|
+
enable(name, conf=conf, with_extras=False)
|
|
146
|
+
else:
|
|
147
|
+
typer.echo(f" enable with: lauschctl plugin enable {name}")
|