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

Merge dev into release #59

Merged
merged 183 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
183 commits
Select commit Hold shift + click to select a range
3951a4b
Add fader live tracking to player
mstratford Jun 20, 2021
639b82a
Add Controller support for fader lives.
mstratford Jun 22, 2021
8d98410
demo pydub normalisation
mstratford Jul 16, 2021
cb42568
Add requirements.txt
markspolakovs Aug 7, 2021
4434673
Add a few missing deps
markspolakovs Aug 7, 2021
6cbb894
Add requirements.txt version freeze.
mstratford Aug 11, 2021
883b877
Removing top level requirements.txt for ones in /build.
mstratford Aug 11, 2021
104197b
Merge pull request #21 from UniversityRadioYork/marks/requirements
mstratford Aug 11, 2021
b90330f
Fix failing to return when no shows.
mstratford Aug 16, 2021
e696e22
WIP Normalisation in filemanager.
mstratford Aug 16, 2021
55e18ee
Fix aiohttp requirement
mstratford Aug 16, 2021
5e364f0
Bump websockets from 8.1 to 9.1 in /build
dependabot[bot] Aug 16, 2021
a8b6036
Include nunito font locally.
mstratford Aug 16, 2021
d4f75aa
Merge pull request #26 from UniversityRadioYork/mstratford/local-reso…
mstratford Aug 17, 2021
b1d9ad8
Fix normalised files being incorrectly named.
mstratford Aug 17, 2021
b3ac0a8
Fix comment.
mstratford Aug 17, 2021
27974ab
Optimise preload/normalisation idle states.
mstratford Aug 17, 2021
48b5ff7
Merge pull request #24 from UniversityRadioYork/mstratford/normalisation
mstratford Aug 17, 2021
c2141c7
Fix error animation
mstratford Aug 17, 2021
1261679
Fix UI being 0 width on small window widths.
mstratford Aug 17, 2021
f28f76f
Get sanic to log to file.
mstratford Aug 17, 2021
9e6db5b
Merge branch 'dev' into faderama
mstratford Sep 1, 2021
7095c64
show current tracklist on status page.
mstratford Sep 1, 2021
6c80a8c
Fix logging to render escaped classes etc. Improve colouring
mstratford Sep 1, 2021
0e040d2
Fix controller to serial "None" option as None correctly.
mstratford Sep 1, 2021
be885d8
Fix API debug prints
mstratford Sep 1, 2021
1de449f
Fix tracklisting start timer not clearing.
mstratford Sep 1, 2021
d3df33e
More logging improvements.
mstratford Sep 1, 2021
127d995
Fix duplicate get request breaking await
mstratford Sep 1, 2021
e208736
Merge pull request #27 from UniversityRadioYork/faderama
mstratford Sep 1, 2021
be18552
Fix api call logic warnings.
mstratford Sep 1, 2021
e3854b5
Change order of shutdown to shorten audio gap
mstratford Sep 1, 2021
0076ea9
Add default audio output option and improve text.
mstratford Sep 1, 2021
d6bf061
Reinitialise audio output on every load, to fix silent channels.
mstratford Sep 1, 2021
9ce43d5
Fix error handling for non existent serial ports
mstratford Sep 2, 2021
3ac694e
Make uninitialised sound-card output obvious
mstratford Sep 2, 2021
95c0843
Add pydub requirement
mstratford Sep 3, 2021
ff605bf
Update GET_PLAN to GETPLAN and add SETPLAYED
mstratford Sep 3, 2021
ca96d7e
Fix other GETPLAN references
mstratford Sep 3, 2021
cade8ec
Support recording played at times for licensing warnings in WS
mstratford Sep 3, 2021
8a66ad8
Improve handling of dead processes
mstratford Sep 4, 2021
10c33af
Logging improvements
mstratford Sep 8, 2021
217a7df
Update to merged WebStudio / BAPS3 presenter
mstratford Sep 8, 2021
ce17793
Fix MacOS bundled launch with sanic logging dir.
mstratford Sep 8, 2021
398c0ac
Fix await for response text.
mstratford Sep 8, 2021
2941d90
Lint with black for formatting.
mstratford Sep 11, 2021
e5e3267
Add linting for autopep8
mstratford Sep 11, 2021
0848771
Tweaked autopep8 lint
mstratford Sep 11, 2021
ec2ddd0
update tests for python 3.10 and complexity
mstratford Sep 11, 2021
30a5309
try 3.10 rc.
mstratford Sep 11, 2021
55309c5
3.10 rc attempt 3
mstratford Sep 11, 2021
794433f
Pull in newer pygame for 3.10 support
mstratford Sep 11, 2021
315d3ae
Remove python 3.10 for now, pygame doesn't build.
mstratford Sep 11, 2021
8b3f527
try news branch
mstratford Sep 11, 2021
3ccd00e
Try build with no news wavs to break CI.
mstratford Sep 11, 2021
f75702a
Fix wav error in presenter
mstratford Sep 11, 2021
540704a
Another import fix
mstratford Sep 11, 2021
2cc4a57
make presenter-start baps version too.
mstratford Sep 11, 2021
b405b7b
Install wheel in CI.
mstratford Sep 11, 2021
55f6fcc
Take master branch webstudio with news fixes.
mstratford Sep 11, 2021
502c7e3
Merge pull request #28 from UniversityRadioYork/mstratford/server-opt…
mstratford Sep 11, 2021
ac54095
Add WIP UI and manager for alerts.
mstratford Sep 11, 2021
477ef64
Bump bapsicle to 3.1.0
mstratford Sep 11, 2021
a3d0635
Fix 404 for logs pages, add 500 error page.
mstratford Sep 16, 2021
4f21bee
Add first server alerts, improve UI a bit.
mstratford Sep 16, 2021
f1e04c3
Switch sanic debug to follow package.BETA
mstratford Sep 16, 2021
7dc0fac
Add basic player restart alerts
mstratford Sep 21, 2021
642aaf0
Remove channel states from alerts page info
mstratford Sep 21, 2021
4e9a1c4
Switch to quit.
mstratford Sep 21, 2021
382de93
Allow player config to better handle borked players.
mstratford Sep 21, 2021
bc2e60c
Update alerts to actually update/end, move list to macro.
mstratford Sep 21, 2021
b8c6f08
Tidy up alert rendering.
mstratford Sep 21, 2021
a172d03
pep8
mstratford Sep 22, 2021
0cdfd7b
Fix linting
mstratford Sep 22, 2021
fe562ac
Correct comment
mstratford Sep 22, 2021
432c645
Fix returning OKAY to play when unloaded. Closes #16
mstratford Sep 22, 2021
5103023
Try non-normalised / redownload file on failure to load.
mstratford Sep 22, 2021
84f0bae
Add better linting and 3.1.0
mstratford Sep 22, 2021
827b7c6
Little lint
mstratford Sep 22, 2021
b79a4a6
Try unique package names per build.
mstratford Sep 22, 2021
dd0c3f3
Try other refs.
mstratford Sep 22, 2021
8428298
Just pull request with sha.
mstratford Sep 22, 2021
485a799
Try getting branch via bash.
mstratford Sep 23, 2021
076440d
Get branch without user prefix (can't have / in filename)
mstratford Sep 23, 2021
c82b193
Make sure server definitely quits with timeout.
mstratford Sep 24, 2021
bc1bd45
Switch to a single queue wherever possible
mstratford Sep 24, 2021
d6751dc
clear all the queues on exit.
mstratford Sep 24, 2021
5d0d111
Show proxy manager threads in VScode debugger
mstratford Sep 24, 2021
896af07
Merge pull request #29 from UniversityRadioYork/mstratford/alerts
mstratford Sep 25, 2021
ae0d85d
Merge remote-tracking branch 'origin/dev' into mstratford/reload-repair
mstratford Sep 25, 2021
212f449
Show loaded status
mstratford Sep 25, 2021
2b2e77f
Fix borked API, makes webstudio not white screen.
mstratford Sep 25, 2021
1b6b3aa
404 correctly on missing audio files.
mstratford Sep 25, 2021
49590dc
Fix a failed download leaving temp file.
mstratford Sep 25, 2021
6cfded2
Semi-fix load failed error in webstudio not showing
mstratford Sep 25, 2021
3bf05b2
Fix preloader not preloading due to GET_PLAN change to GETPLAN
mstratford Sep 25, 2021
8cc342b
3.1.0 again?
mstratford Sep 25, 2021
9dc0990
Add normalisation switch option.
mstratford Sep 30, 2021
1ee542e
Fix linux to use pulseaudio.
mstratford Oct 12, 2021
e4cc6f7
Prompt before restarting the server if anything is playing
markspolakovs Oct 20, 2021
8896dc4
Merge pull request #35 from UniversityRadioYork/marks/restart-confirm
markspolakovs Oct 26, 2021
ecbfaa4
use sudo to install audio pkg
mstratford Nov 2, 2021
592cf11
Fix mp3 support on linux with pygame 2.0.1
mstratford Nov 2, 2021
c475dbb
Switch to SDL outputs with pulseaudio for linux
mstratford Nov 2, 2021
65944e5
Fix lints.
mstratford Nov 2, 2021
0f25345
Fix pulseaudio error on !linux
mstratford Nov 2, 2021
53b26e2
Merge pull request #36 from UniversityRadioYork/mstratford/linux-audio
mstratford Nov 2, 2021
778c22b
Merge branch 'dev' into mstratford/reload-repair
mstratford Nov 2, 2021
7b75724
Merge pull request #30 from UniversityRadioYork/mstratford/reload-repair
mstratford Nov 2, 2021
e287e65
Default normalisation off due to ffmpeg requirement.
mstratford Nov 3, 2021
04cf5a6
Merge remote-tracking branch 'origin/dev' into mstratford/norm-switch
mstratford Nov 3, 2021
71689ce
Update presenter webstudio to fix node production builds.
mstratford Nov 3, 2021
5a69c09
Merge pull request #40 from UniversityRadioYork/mstratford/webstudio-…
mstratford Nov 3, 2021
31532b6
Merge pull request #39 from UniversityRadioYork/mstratford/norm-switch
mstratford Nov 5, 2021
b7f75df
Fix marking played / unplayed to all channels from 0.
mstratford Dec 6, 2021
a041a6e
Merge branch 'dev' into dependabot/pip/build/websockets-9.1
mstratford Dec 23, 2021
ac7d7d0
merge of "dependabot/pip/build/websockets-9.1" and "dev"
mstratford Dec 23, 2021
fd87bbd
Bump to websockets 10.1
mstratford Dec 23, 2021
8b4265a
Force node 14
mstratford Dec 23, 2021
84c48ca
Merge pull request #25 from UniversityRadioYork/dependabot/pip/build/…
mstratford Dec 23, 2021
ba4e257
Fix player bootlooping if mixer doesn't init
mstratford Dec 23, 2021
04790f8
Merge remote-tracking branch 'origin/dev' into dependabot/pip/build/w…
mstratford Dec 23, 2021
7a1f7be
Improve efficiency by reducing file test load spam
mstratford Dec 23, 2021
c538ce3
Fix "STOPPED" message.
mstratford Dec 23, 2021
325f62e
Comments and reordering.
mstratford Dec 23, 2021
0b6e245
Add ffmpeg for ubuntu
mstratford Mar 11, 2022
2515ddf
Ignore node_modules.
mstratford Mar 11, 2022
92a6b86
Merge branch 'dev' into mstratford/quitting
mstratford Mar 11, 2022
853efa6
Fix file manager using single msg queue.
mstratford Mar 11, 2022
7400272
Enable debugging by default on dev builds.
mstratford Mar 11, 2022
52248be
Flake 8 lint
mstratford Mar 11, 2022
45e3a83
Merge pull request #31 from UniversityRadioYork/mstratford/quitting
mstratford Mar 12, 2022
358b5bb
Update aiohttp for dependabot
mstratford Mar 12, 2022
7c547bc
Merge remote-tracking branch 'origin/dev' into docs-and-logging
mstratford Mar 12, 2022
81d9860
Fix dragging items caused by plan item not being list.
mstratford Mar 12, 2022
aba3104
Put BAPSicle in process names for htop filtering.
mstratford Mar 12, 2022
02137a3
Improve launcher printing.
mstratford Mar 12, 2022
1e77f33
Improve shutdown time of Controller Handler.
mstratford Mar 12, 2022
873fd45
Cleanup queues more reliably
mstratford Mar 12, 2022
f73845b
Further cleanup.
mstratford Mar 12, 2022
47fcf40
Don't bother cleaning queues, it fails on hot-restarts.
mstratford Mar 12, 2022
5d4c722
Pep8 lint
mstratford Mar 12, 2022
7912b2c
Merge pull request #42 from UniversityRadioYork/docs-and-logging
mstratford Mar 18, 2022
978c042
Revert sanic version to fix OSError on linux.
mstratford Mar 18, 2022
f7e71cc
Build for python3.8 and 3.9
mstratford Mar 19, 2022
a838ef7
Fix exit hang on linux
mstratford Mar 19, 2022
86c0ca1
Fix exit hang on linux
mstratford Mar 19, 2022
01dfb3f
Update sanic deprications and remove asyncio stuff not needed.
mstratford Mar 19, 2022
d6304cc
Fix missing pyinstaller in path
mstratford Mar 19, 2022
64b1ef7
Update sanic requirements.
mstratford Mar 19, 2022
efd0273
Revert "Fix exit hang on linux"
mstratford Mar 19, 2022
330a1de
Revert "Fix exit hang on linux"
mstratford Mar 19, 2022
617376a
Shutdown webserver cleanly and let server.py restart it.
mstratford Mar 19, 2022
c70092f
Make sure all sanic deps are included
mstratford Mar 19, 2022
433d053
Let script fail if it errors.
mstratford Mar 19, 2022
67c74b0
Fix typo
mstratford Mar 19, 2022
76ddea5
Attempt fix of setproctitle missing
mstratford Mar 19, 2022
1bd5779
Don't log MyRadio API keys
markspolakovs Oct 16, 2022
92dbd19
Remove space.
mstratford Oct 17, 2022
d6ee435
Merge pull request #48 from UniversityRadioYork/marks/dont-log-api-keys
mstratford Oct 17, 2022
06812b9
List filename in 404 error
mstratford Mar 10, 2023
6d7c3aa
Merge pull request #43 from UniversityRadioYork/linux-again
mstratford Mar 10, 2023
ab2aead
chore: updates to build on latest python/linux
ashhhleyyy Mar 23, 2024
4fcd72a
fix(ci): add new python/node versions to CI
ashhhleyyy Mar 23, 2024
3cd7069
fix: fix presenter build on windows
ashhhleyyy Mar 24, 2024
058e529
fix: bump presenter to support building with latest node on all platf…
ashhhleyyy Mar 29, 2024
237f21a
chore(ci): disable broken MacOS builds
ashhhleyyy Mar 29, 2024
0e13dc0
feat: migrate to poetry
ashhhleyyy Mar 29, 2024
5409758
fix(ci): use poetry
ashhhleyyy Mar 29, 2024
7018f91
fix: include BAPS as a package, loosen python version requirement
ashhhleyyy Mar 29, 2024
ee93a45
chore: general dependency updates (no breaking changes)
ashhhleyyy Mar 31, 2024
1e26fc8
fix(ci): update to actions/upload-artifact@v4 and set unique names fo…
ashhhleyyy Mar 31, 2024
45a3568
fix(ci): hopefully fix the test workflow
ashhhleyyy Mar 31, 2024
c2795b8
fix(ci): install poetry
ashhhleyyy Mar 31, 2024
046fd3e
fix(ci): run python commands with poetry
ashhhleyyy Mar 31, 2024
00c3cf9
Merge pull request #57 from UniversityRadioYork/ash-linux-updates
ashhhleyyy Apr 3, 2024
7a21453
feat: update sanic to latest release
ashhhleyyy Mar 31, 2024
5e489a6
chore: bump minimum versions of other packages
ashhhleyyy Mar 31, 2024
f04e1ad
docs: tested up to python 3.11
ashhhleyyy Mar 31, 2024
16a5a94
Merge pull request #58 from UniversityRadioYork/ash-python-updates
ashhhleyyy Apr 3, 2024
9993308
fix: include resources from tracerite package in final build
ashhhleyyy Apr 3, 2024
a10c33a
chore: bump to 3.1.1
ashhhleyyy Apr 3, 2024
505a632
Merge branch 'release' into dev
ashhhleyyy Apr 3, 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
94 changes: 64 additions & 30 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,42 @@ name: Package
on: [push]

jobs:
build-macos:
# build-macos:

runs-on: macos-latest
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
python-version: [3.9]
# runs-on: macos-latest
# timeout-minutes: 15
# strategy:
# fail-fast: false
# matrix:
# python-version: ['3.9', '3.11']
# node-version: ['20']

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Build .app
run: |
npm run presenter-make
build/build-macos.sh
zip -r build/output/BAPSicle.zip build/output/BAPSicle.app
- name: Archive Build
uses: actions/upload-artifact@v2
with:
name: Package - MacOS
path: |
build/output/BAPSicle.zip
# steps:
# - uses: actions/checkout@v2
# - name: Set up Python ${{ matrix.python-version }}
# uses: actions/setup-python@v2
# with:
# python-version: ${{ matrix.python-version }}
# - uses: actions/checkout@v2
# - name: Set up Node ${{ matrix.node-version }}
# uses: actions/setup-node@v2
# with:
# node-version: ${{ matrix.node-version }}
# - name: Build .app
# run: |
# npm run presenter-make
# build/build-macos.sh
# zip -r build/output/BAPSicle.zip build/output/BAPSicle.app
# - name: Extract branch name
# shell: bash
# run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF##*/})"
# id: extract_branch
# - name: Archive Build
# uses: actions/upload-artifact@v2
# with:
# name: BAPSicle-${{ steps.extract_branch.outputs.branch }}-${{github.sha}}-MacOS
# path: |
# build/output/BAPSicle.zip

build-ubuntu:

Expand All @@ -36,22 +46,34 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.9]
python-version: ['3.8','3.9', '3.11']
node-version: ['20']

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Setup poetry
uses: Gr1N/setup-poetry@v8
- uses: actions/checkout@v2
- name: Set up Node ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: Build executable
run: |
npm run presenter-make
build/build-linux.sh
- name: Extract branch name
shell: bash
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF##*/})"
id: extract_branch
- name: Archive Build
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: Package - Ubuntu
name: BAPSicle-${{ steps.extract_branch.outputs.branch }}-${{github.sha}}-Ubuntu-python${{matrix.python-version}}-node${{matrix.node-version}}
path: |
build/output/BAPSicle

Expand All @@ -62,22 +84,34 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.9]
python-version: ['3.9', '3.11']
node-version: ['20']

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Setup poetry
uses: Gr1N/setup-poetry@v8
- uses: actions/checkout@v2
- name: Set up Node ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: Build .exe
run: |
npm run presenter-make
build/build-windows.bat no-venv
- name: Extract branch name
shell: bash
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF##*/})"
id: extract_branch
- name: Archive Build
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: Package - Windows
name: BAPSicle-${{ steps.extract_branch.outputs.branch }}-${{github.sha}}-Windows-python${{matrix.python-version}}-node${{matrix.node-version}}
path: |
build/output/BAPSicle.exe
install/
23 changes: 9 additions & 14 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,33 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.8, 3.9]
python-version: [3.8, 3.9, 3.11]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Setup poetry
uses: Gr1N/setup-poetry@v8
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install flake8
pip install -r build/requirements.txt
pip install -r build/requirements-macos.txt
- name: Install bapsicle as module
run: |
pip install -e .
run: poetry install --with=dev
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
poetry run flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --ignore=E402,E226,E24,W50,W690 --max-complexity=20 --max-line-length=127 --statistics
poetry run flake8 . --count --ignore=E402,E226,E24,W50,W690 --max-complexity=25 --max-line-length=127 --statistics
- name: Test with unittest
if: ${{ always() }}
timeout-minutes: 10
run: |
python -m sounddevice
python -m unittest
poetry run python -m sounddevice
poetry run python -m unittest
- name: Archive test logs
if: ${{ always() }}
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: Logs - Python ${{ matrix.python-version }}
path: |
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ music-tmp/


presenter-build

node_modules/
3 changes: 2 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[submodule "presenter"]
path = presenter
url = https://github.com/michael-grace/WebStudio.git
url = https://github.com/UniversityRadioYork/WebStudio.git
branch = master
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Starting and stopping the server, as well as UI links, are available in the Syst

On all platforms:

- Python 3.8 - 3.9 Tested
- Python 3.8 - 3.11 Tested
- Git (Obviously)

On MacOS:
Expand Down
20 changes: 20 additions & 0 deletions alerts/dummy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from helpers.alert_manager import AlertProvider
from package import BETA
from baps_types.alert import WARNING, Alert
# Dummy alert provider for testing basics like UI without needing to actually cause errors.


class DummyAlertProvider(AlertProvider):

def get_alerts(self):
if BETA:
return [Alert(
{
"start_time": -1,
"id": "test",
"title": "BAPSicle is in Debug Mode",
"description": "This is a test alert. It will not appear on production builds.",
"module": "Test",
"severity": WARNING
}
)]
99 changes: 99 additions & 0 deletions alerts/player.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Any alerts produced by the player.py instances.
import json
from typing import Any, Dict, List, Optional
from datetime import datetime, timedelta
from helpers.os_environment import resolve_external_file_path
from helpers.alert_manager import AlertProvider
from baps_types.alert import CRITICAL, WARNING, Alert
from baps_types.happytime import happytime

MODULE = "Player" # This should match the log file, so the UI will link to the logs page.


class PlayerAlertProvider(AlertProvider):

_server_state: Dict[str, Any]
_states: List[Optional[Dict[str, Any]]] = []
_player_count: int

def __init__(self):
# Player count only changes after server restart, may as well just load this once.
with open(resolve_external_file_path("state/BAPSicleServer.json")) as file:
self._server_state = json.loads(file.read())

self._player_count = int(self._server_state["num_channels"])
self._states = [None] * self._player_count

# To simplify monitoring (and allow detection of things going super
# weird), we are going to read from the state file to work out the alerts.
def get_alerts(self):
for channel in range(self._player_count):
with open(resolve_external_file_path("state/Player{}.json".format(channel))) as file:
self._states[channel] = json.loads(file.read())

funcs = [self._channel_count, self._initialised, self._start_time]

alerts: List[Alert] = []

for func in funcs:
func_alerts = func()
if func_alerts:
alerts.extend(func_alerts)

return alerts

def _channel_count(self):
if self._player_count <= 0:
return [Alert({
"start_time": -1, # Now
"id": "no_channels",
"title": "There are no players configured.",
"description": "The number of channels configured is {}. \
Please set to at least 1 on the 'Server Config' page."
.format(self._player_count),
"module": MODULE+"Handler",
"severity": CRITICAL
})]

def _initialised(self):
alerts: List[Alert] = []
for channel in range(self._player_count):
if self._states[channel] and not self._states[channel]["initialised"]:
alerts.append(Alert({
"start_time": -1, # Now
"id": "player_{}_not_initialised".format(channel),
"title": "Player {} is not initialised.".format(channel),
"description": "This typically means the player channel was not able find the configured sound output \
on the system. Please check the 'Player Config' and Player logs to determine the cause.",
"module": MODULE+str(channel),
"severity": CRITICAL
}))
return alerts

def _start_time(self):
server_start_time = self._server_state["start_time"]
server_start_time = datetime.fromtimestamp(server_start_time)
delta = timedelta(
seconds=30,
)

alerts: List[Alert] = []
for channel in range(self._player_count):
start_time = self._states[channel]["start_time"]
start_time = datetime.fromtimestamp(start_time)
if (start_time > server_start_time + delta):
alerts.append(Alert({
"start_time": -1,
"id": "player_{}_restarted".format(channel),
"title": "Player {} restarted after the server started.".format(channel),
"description":
"""Player {} last restarted at {}, after the server first started at {}, suggesting a failure.

This likely means there was an unhandled exception in the player code, causing the server to restart the player.

Please check player logs to investigate the cause. Please restart the server to clear this warning."""
.format(channel, happytime(start_time), happytime(server_start_time)),
"module": MODULE+str(channel),
"severity": WARNING
}))
return alerts
Loading
Loading