Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

venv activation #17

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
60042f4
add setup script for rfid reader. moved python script
AlvinSchiller Jan 30, 2024
31bd3b6
add check for venv activation
AlvinSchiller Jan 31, 2024
973175f
fix
AlvinSchiller Jan 31, 2024
39f5378
fix cd fail behavior (dont start subprocess)
AlvinSchiller Jan 31, 2024
7bd2339
add script for run jukebox for venv.
AlvinSchiller Jan 31, 2024
f65d260
add setup script for audio sink. moved python script
AlvinSchiller Jan 31, 2024
73d5583
add script for rpc tool. moved python script
AlvinSchiller Jan 31, 2024
0490ca3
add script for sniffer tool. moved python script
AlvinSchiller Jan 31, 2024
dd2c7af
fixed parameter passing
AlvinSchiller Jan 31, 2024
f18dad6
fix paths
AlvinSchiller Jan 31, 2024
7248ad2
fix flake8
AlvinSchiller Jan 31, 2024
d00a203
fix comments and docs
AlvinSchiller Jan 31, 2024
7c87cea
fixed parameter passing
AlvinSchiller Jan 31, 2024
c979672
some fixes
AlvinSchiller Jan 31, 2024
e6f969c
fixed execution rights
AlvinSchiller Jan 31, 2024
4877161
some fixes
AlvinSchiller Jan 31, 2024
654d031
move scripts to python root again (failing import paths).
AlvinSchiller Feb 1, 2024
81fac26
fix relative paths
AlvinSchiller Feb 1, 2024
1b86e1a
update notes about config file paths
AlvinSchiller Feb 1, 2024
7cda2cb
update caller scripts path handling
AlvinSchiller Feb 1, 2024
6219f71
update comments
AlvinSchiller Feb 1, 2024
86b210e
add venv activation to tests
AlvinSchiller Feb 1, 2024
a33c25c
explicit installation of python3-venv not needed
AlvinSchiller Feb 1, 2024
0b5b5da
renamed audio setup file.
AlvinSchiller Feb 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions documentation/builders/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ $ systemctl --user stop jukebox-daemon
$ nano ./shared/settings/jukebox.yaml

# Start Jukebox in console and check the log output (optional)
$ cd src/jukebox
$ ./run_jukebox.py
$ ./run_jukebox.sh
# and if OK, press Ctrl-C and restart the service

# Restart the service
Expand All @@ -32,8 +31,8 @@ $ systemctl --user start jukebox-daemon
To try different configurations, you can start the Jukebox with a custom config file.
This could be useful if you want your Jukebox to only allow a lower volume when started
at night time when there is time to go to bed :-)
The path to the custom config file must be either absolute or relativ to the folder `src/jukebox/`

```bash
$ cd src/jukebox
$ ./run_jukebox.py --conf path/to/custom/config.yaml
$ ./run_jukebox.sh --conf /absolute/path/to/custom/config.yaml
```
9 changes: 3 additions & 6 deletions documentation/builders/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,10 @@ on the console log.
$ systemctl --user stop jukebox-daemon

# Start the Jukebox in debug mode:
$ cd src/jukebox

# with default logger:
$ ./run_jukebox.py
$ ./run_jukebox.sh
# or with custom logger configuration:
$ ./run_jukebox.py --logger path/to/custom/logger.yaml
$ ./run_jukebox.sh --logger path/to/custom/logger.yaml
```

### Fallback configuration
Expand All @@ -79,8 +77,7 @@ Attention: This only emits messages to the console and does not write to the log
This is more a fallback features:

```bash
$ cd src/jukebox
$ ./run_jukebox.py -vv
$ ./run_jukebox.sh -vv
```

### Extreme cases
Expand Down
14 changes: 7 additions & 7 deletions documentation/developers/coreapps.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ $ ./<scriptname> -h

## Jukebox Core

**Scriptname:** [run_jukebox.py](../../src/jukebox/run_jukebox.py)
**Scriptname:** [run_jukebox.sh](../../run_jukebox.sh)

This is the main app and starts the Jukebox Core.

Expand All @@ -25,15 +25,15 @@ See [Best practice procedure](../builders/configuration.md#best-practice-procedu

### Audio

**Scriptname:** [run_configure_audio.py](../../src/jukebox/run_configure_audio.py)
**Scriptname:** [setup_audio_sink.sh](../../installation/components/setup_audio_sink.sh)
s-martin marked this conversation as resolved.
Show resolved Hide resolved

Setup tool to register the PulseAudio sinks as primary and secondary audio outputs.

Will also setup equalizer and mono down mixer in the pulseaudio config file. Run this once after installation. Can be re-run at any time to change the settings. For more information see [Audio Configuration](../builders/audio.md).

### RFID Reader

**Scriptname:** [run_register_rfid_reader.py](../../src/jukebox/run_register_rfid_reader.py)
**Scriptname:** [setup_rfid_reader.sh](../../installation/components/setup_rfid_reader.sh)
s-martin marked this conversation as resolved.
Show resolved Hide resolved

Setup tool to configure the RFID Readers.

Expand All @@ -46,20 +46,20 @@ Run this once to register and configure the RFID readers with the Jukebox. Can b

### RPC

**Scriptname:** [run_rpc_tool.py](../../src/jukebox/run_rpc_tool.py)
**Scriptname:** [run_rpc_tool.sh](../../tools/run_rpc_tool.sh)

Command Line Interface to the Jukebox RPC Server.

A command line tool for sending RPC commands to the running jukebox app. This uses the same interface as the WebUI. Can be used for additional control or for debugging. Use `./run_rpc_tool.py` to start the tool in interactive mode.
A command line tool for sending RPC commands to the running jukebox app. This uses the same interface as the WebUI. Can be used for additional control or for debugging. Use `./run_rpc_tool.sh` to start the tool in interactive mode.

The tool features auto-completion and command history.

The list of available commands is fetched from the running Jukebox service.

The tool can also be used to send commands directly, when passing a `-c` argument, e.g. `./run_rpc_tool.py -c host.shutdown`.
The tool can also be used to send commands directly, when passing a `-c` argument, e.g. `./run_rpc_tool.sh -c host.shutdown`.

### Publicity Sniffer

**Scriptname:** [run_publicity_sniffer.py](../../src/jukebox/run_publicity_sniffer.py)
**Scriptname:** [run_publicity_sniffer.sh](../../tools/run_publicity_sniffer.sh)

A command line tool that monitors all messages being sent out from the Jukebox via the publishing interface. Received messages are printed in the console. Mainly used for debugging.
2 changes: 1 addition & 1 deletion documentation/developers/known-issues.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ RUN cd ${HOME} && mkdir ${ZMQ_TMP_DIR} && cd ${ZMQ_TMP_DIR}; \
## Configuration

In `jukebox.yaml` (and all other config files):
Always use relative path from settingsfile `../../`, but do not use relative paths with `~/`.
Always use relative path from folder `src/jukebox` (`../../`), but do not use relative paths with `~/`.

**Sole** exception is in `playermpd.mpd_conf`.
16 changes: 16 additions & 0 deletions installation/components/setup_audio_sink.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
AlvinSchiller marked this conversation as resolved.
Show resolved Hide resolved

# Runner script for sniffer tool to ensure
# - correct venv activation
# - independent from working directory

# Change working directory to project root
SOURCE=${BASH_SOURCE[0]}
SCRIPT_DIR="$(dirname "$SOURCE")"
PROJECT_ROOT="$SCRIPT_DIR"/../..
cd "$PROJECT_ROOT" || { echo "Could not change directory"; exit 1; }

source .venv/bin/activate || { echo "ERROR: Failed to activate virtual environment for python"; exit 1; }

cd src/jukebox || { echo "Could not change directory"; exit 1; }
python run_configure_audio.py $@
16 changes: 16 additions & 0 deletions installation/components/setup_rfid_reader.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

# Runner script for sniffer tool to ensure
# - correct venv activation
# - independent from working directory

# Change working directory to project root
SOURCE=${BASH_SOURCE[0]}
SCRIPT_DIR="$(dirname "$SOURCE")"
PROJECT_ROOT="$SCRIPT_DIR"/../..
cd "$PROJECT_ROOT" || { echo "Could not change directory"; exit 1; }

source .venv/bin/activate || { echo "ERROR: Failed to activate virtual environment for python"; exit 1; }

cd src/jukebox || { echo "Could not change directory"; exit 1; }
python run_register_rfid_reader.py $@
4 changes: 3 additions & 1 deletion installation/routines/setup_rfid_reader.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/usr/bin/env bash
s-martin marked this conversation as resolved.
Show resolved Hide resolved

_run_setup_rfid_reader() {
run_and_print_lc python "${INSTALLATION_PATH}/src/jukebox/run_register_rfid_reader.py"
local script="${INSTALLATION_PATH}"/installation/components/setup_rfid_reader.sh
sudo chmod +x "$script"
run_and_print_lc "$script"
}

setup_rfid_reader() {
Expand Down
4 changes: 2 additions & 2 deletions resources/default-services/jukebox-daemon.service
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ After=network.target sound.target mpd.service pulseaudio.service
Requires=mpd.service pulseaudio.service

[Service]
WorkingDirectory=%%INSTALLATION_PATH%%/src/jukebox
ExecStart=/bin/bash -c 'source %%INSTALLATION_PATH%%/.venv/bin/activate && python run_jukebox.py'
WorkingDirectory=%%INSTALLATION_PATH%%
ExecStart=/bin/bash -c '%%INSTALLATION_PATH%%/run_jukebox.sh'
StandardOutput=inherit
StandardError=inherit
Restart=always
Expand Down
2 changes: 1 addition & 1 deletion resources/default-settings/jukebox.default.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# IMPORTANT:
# Always use relative path from settingsfile `../../`, but do not use relative paths with `~/`.
# Always use relative path from folder `src/jukebox` (`../../`), but do not use relative paths with `~/`.
# Sole (!) exception is in playermpd.mpd_conf
system:
box_name: Jukebox
Expand Down
2 changes: 1 addition & 1 deletion resources/default-settings/pulseaudio.default.pa
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,5 @@ load-module module-filter-apply
#set-default-source input

### Configuration by Jukebox's Tool may come below
# Run ./run_configure_audio.py for configuration
# Run ./installation/components/run_configure_audio.sh for configuration

2 changes: 1 addition & 1 deletion run_docgeneration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Change working directory to location of script
SOURCE=${BASH_SOURCE[0]}
SCRIPT_DIR="$(dirname "$SOURCE")"
cd "$SCRIPT_DIR" || (echo "Could not change to top-level project directory" && exit 1)
cd "$SCRIPT_DIR" || { echo "Could not change to top-level project directory"; exit 1; }

# Run pydoc-markdown
# make sure, directory exists
Expand Down
2 changes: 1 addition & 1 deletion run_flake8.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# Change working directory to location of script
SOURCE=${BASH_SOURCE[0]}
SCRIPT_DIR="$(dirname "$SOURCE")"
cd "$SCRIPT_DIR" || (echo "Could not change to top-level project directory" && exit 1)
cd "$SCRIPT_DIR" || { echo "Could not change to top-level project directory"; exit 1; }

# Run flake8
flake8 --config .flake8 "$@"
16 changes: 16 additions & 0 deletions run_jukebox.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

# Runner script for sniffer tool to ensure
# - correct venv activation
# - independent from working directory

# Change working directory to project root
SOURCE=${BASH_SOURCE[0]}
SCRIPT_DIR="$(dirname "$SOURCE")"
PROJECT_ROOT="$SCRIPT_DIR"
cd "$PROJECT_ROOT" || { echo "Could not change directory"; exit 1; }

source .venv/bin/activate || { echo "ERROR: Failed to activate virtual environment for python"; exit 1; }

cd src/jukebox || { echo "Could not change directory"; exit 1; }
python run_jukebox.py $@
2 changes: 1 addition & 1 deletion run_pytest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# Change working directory to location of script
SOURCE=${BASH_SOURCE[0]}
SCRIPT_DIR="$(dirname "$SOURCE")"
cd "$SCRIPT_DIR" || (echo "Could not change to top-level project directory" && exit 1)
cd "$SCRIPT_DIR" || { echo "Could not change to top-level project directory"; exit 1; }

# Run pytest
pytest -c pytest.ini $@
2 changes: 1 addition & 1 deletion src/jukebox/components/volume/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ def parse_config() -> List[PulseAudioSinkClass]:
logger.error(f"Configured sink '{pulse_sink_name}' not available sinks '{all_sinks}!\n"
f"Using default sink '{default_sink_name}' as fallback\n"
f"Things like audio sink toggle and volume limit will not work as expected!\n"
f"Please run audio config tool: ./run_configure_audio.py")
f"Please run audio config tool: ./installation/components/run_configure_audio.sh")

sink_list.append(PulseAudioSinkClass(alias, pulse_sink_name, volume_limit))
key = 'secondary'
Expand Down
2 changes: 1 addition & 1 deletion src/jukebox/run_configure_audio.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Will also setup equalizer and mono down mixer in the pulseaudio config file.

Run this once after installation. Can be re-run at any time to change the settings.
For more information see [Audio Configuration](../../builders/audio.md#audio-configuration).
For more information see [Audio Configuration](./../../builders/audio.md#audio-configuration).
AlvinSchiller marked this conversation as resolved.
Show resolved Hide resolved
"""
import os
import argparse
Expand Down
Empty file modified src/jukebox/run_publicity_sniffer.py
100755 → 100644
Empty file.
5 changes: 3 additions & 2 deletions src/jukebox/run_register_rfid_reader.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Setup tool to configure the RFID Readers.

Run this once to register and configure the RFID readers with the Jukebox. Can be re-run at any time to change
the settings. For more information see [RFID Readers](../rfid/README.md).
the settings. For more information see [RFID Readers](./../../documentation/developers/rfid/README.md).
AlvinSchiller marked this conversation as resolved.
Show resolved Hide resolved

> [!NOTE]
> This tool will always write a new configurations file. Thus, overwrite the old one (after checking with the user).
Expand Down Expand Up @@ -33,7 +33,8 @@

def main():
# The default config file relative to this files location and independent of working directory
cfg_file_default = os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + '/../../shared/settings/rfid.yaml')
script_path = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
cfg_file_default = os.path.abspath(os.path.join(script_path, '../../shared/settings/rfid.yaml'))

parser = argparse.ArgumentParser()
parser.add_argument("-f", "--force",
Expand Down
Empty file modified src/jukebox/run_rpc_tool.py
100755 → 100644
Empty file.
16 changes: 16 additions & 0 deletions tools/run_publicity_sniffer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

# Runner script for sniffer tool to ensure
# - correct venv activation
# - independent from working directory

# Change working directory to project root
SOURCE=${BASH_SOURCE[0]}
SCRIPT_DIR="$(dirname "$SOURCE")"
PROJECT_ROOT="$SCRIPT_DIR"/..
cd "$PROJECT_ROOT" || { echo "Could not change directory"; exit 1; }

source .venv/bin/activate || { echo "ERROR: Failed to activate virtual environment for python"; exit 1; }

cd src/jukebox || { echo "Could not change directory"; exit 1; }
python run_publicity_sniffer.py $@
16 changes: 16 additions & 0 deletions tools/run_rpc_tool.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

# Runner script for sniffer tool to ensure
# - correct venv activation
# - independent from working directory

# Change working directory to project root
SOURCE=${BASH_SOURCE[0]}
SCRIPT_DIR="$(dirname "$SOURCE")"
PROJECT_ROOT="$SCRIPT_DIR"/..
cd "$PROJECT_ROOT" || { echo "Could not change directory"; exit 1; }

source .venv/bin/activate || { echo "ERROR: Failed to activate virtual environment for python"; exit 1; }

cd src/jukebox || { echo "Could not change directory"; exit 1; }
python run_rpc_tool.py $@
Loading