Merge pull request #43 from UniversityRadioYork/linux-again

Fix linux support again for Ubuntu Studio
This commit is contained in:
Matthew Stratford 2023-03-10 19:56:53 +00:00 committed by GitHub
commit 6d7c3aab2f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 43 additions and 41 deletions

View file

@ -46,7 +46,7 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
python-version: ['3.9'] python-version: ['3.8','3.9']
node-version: ['14'] node-version: ['14']
steps: steps:

View file

@ -80,6 +80,14 @@
{ {
"optionDest": "datas", "optionDest": "datas",
"value": "/package.json;./" "value": "/package.json;./"
},
{
"optionDest": "collect-all",
"value": "sanic"
},
{
"optionDest": "collect-all",
"value": "setproctitle"
} }
], ],
"nonPyinstallerOptions": { "nonPyinstallerOptions": {

View file

@ -1,10 +1,15 @@
import json import json
from helpers.os_environment import isLinux
file = open('build-exe-config.json', 'r') file = open('build-exe-config.json', 'r')
config = json.loads(file.read()) config = json.loads(file.read())
file.close() file.close()
cmd_str = "pyinstaller " if isLinux():
cmd_str = "python3 -m PyInstaller "
else:
cmd_str = "pyinstaller "
json_dests = ["icon_file", "clean_build"] json_dests = ["icon_file", "clean_build"]
pyi_dests = ["icon", "clean"] pyi_dests = ["icon", "clean"]

View file

@ -1,4 +1,5 @@
#!/bin/bash #!/bin/bash
set -x
cd "$(dirname "$0")" cd "$(dirname "$0")"
# Get the git commit / branch and write it into build.py. # Get the git commit / branch and write it into build.py.

View file

@ -1,4 +1,5 @@
#!/bin/bash #!/bin/bash
set -x
cd "$(dirname "$0")" cd "$(dirname "$0")"
# Get the git commit / branch and write it into build.py. # Get the git commit / branch and write it into build.py.

View file

@ -1,7 +1,7 @@
wheel wheel
pygame==2.0.2 pygame==2.0.2
sanic==21.9.3 sanic==21.9.3
sanic-Cors==1.0.1 sanic-Cors==2.0.1
syncer==1.3.0 syncer==1.3.0
aiohttp==3.7.4 aiohttp==3.7.4
mutagen==1.45.1 mutagen==1.45.1

View file

@ -56,7 +56,7 @@
{% endfor %} {% endfor %}
</select> </select>
<p><small> <p><small>
Normalisation requests significant CPU requirements, if you're finding the CPU usuage is too high / causing audio glitches, disable this feature. <code>ffmpeg</code> or <code>avconf</code> required. Normalisation requests significant CPU requirements, if you're finding the CPU usage is too high / causing audio glitches, disable this feature. <code>ffmpeg</code> or <code>avconf</code> required.
</small></p> </small></p>
<hr> <hr>
<input type="submit" class="btn btn-primary" value="Save & Restart Server"> <input type="submit" class="btn btn-primary" value="Save & Restart Server">

View file

@ -1,10 +1,8 @@
from sanic import Sanic from sanic import Sanic
from sanic.exceptions import NotFound, abort from sanic.exceptions import NotFound, SanicException
from sanic.response import html, file, redirect from sanic.response import html, file, redirect
from sanic.response import json as resp_json from sanic.response import json as resp_json
from sanic_cors import CORS from sanic_cors import CORS
from syncer import sync
import asyncio
from jinja2 import Environment, FileSystemLoader from jinja2 import Environment, FileSystemLoader
from jinja2.utils import select_autoescape from jinja2.utils import select_autoescape
from urllib.parse import unquote from urllib.parse import unquote
@ -16,6 +14,7 @@ from queue import Empty
from time import sleep from time import sleep
import json import json
import os import os
import sys
from helpers.os_environment import ( from helpers.os_environment import (
isLinux, isLinux,
@ -89,7 +88,7 @@ LOGGING_CONFIG = dict(
}, },
) )
app = Sanic("BAPSicle Web Server", log_config=LOGGING_CONFIG) app = Sanic("BAPSicle-WebServer", log_config=LOGGING_CONFIG)
def render_template(file, data, status=200): def render_template(file, data, status=200):
@ -258,8 +257,7 @@ def ui_logs_render(request, path):
try: try:
log_file = open(resolve_external_file_path("/logs/{}.log").format(path)) log_file = open(resolve_external_file_path("/logs/{}.log").format(path))
except FileNotFoundError: except FileNotFoundError:
abort(404) raise SanicException("Not Found",404)
return
data = { data = {
"logs": log_file.read().splitlines()[ "logs": log_file.read().splitlines()[
@ -285,10 +283,10 @@ def player_simple(request, channel: int, command: str):
player_to_q[channel].put("UI:" + command.upper()) player_to_q[channel].put("UI:" + command.upper())
return redirect("/status") return redirect("/status")
abort(404) raise SanicException("Not Found",404)
@app.route("/player/<channel:int>/seek/<pos:number>") @app.route("/player/<channel:int>/seek/<pos:float>")
def player_seek(request, channel: int, pos: float): def player_seek(request, channel: int, pos: float):
player_to_q[channel].put("UI:SEEK:" + str(pos)) player_to_q[channel].put("UI:SEEK:" + str(pos))
@ -310,7 +308,7 @@ def player_remove(request, channel: int, channel_weight: int):
return redirect("/status") return redirect("/status")
@app.route("/player/<channel:int>/output/<name:string>") @app.route("/player/<channel:int>/output/<name:str>")
def player_output(request, channel: int, name: Optional[str]): def player_output(request, channel: int, name: Optional[str]):
player_to_q[channel].put("UI:OUTPUT:" + unquote(str(name))) player_to_q[channel].put("UI:OUTPUT:" + unquote(str(name)))
return redirect("/config/player") return redirect("/config/player")
@ -322,7 +320,7 @@ def player_autoadvance(request, channel: int, state: int):
return redirect("/status") return redirect("/status")
@app.route("/player/<channel:int>/repeat/<state:string>") @app.route("/player/<channel:int>/repeat/<state:str>")
def player_repeat(request, channel: int, state: str): def player_repeat(request, channel: int, state: str):
player_to_q[channel].put("UI:REPEAT:" + state.upper()) player_to_q[channel].put("UI:REPEAT:" + state.upper())
return redirect("/status") return redirect("/status")
@ -386,11 +384,11 @@ async def api_search_library(request):
) )
@app.route("/library/playlists/<type:string>") @app.route("/library/playlists/<type:str>")
async def api_get_playlists(request, type: str): async def api_get_playlists(request, type: str):
if type not in ["music", "aux"]: if type not in ["music", "aux"]:
abort(401) raise SanicException("Bad Request",400)
if type == "music": if type == "music":
return resp_json(await api.get_playlist_music()) return resp_json(await api.get_playlist_music())
@ -398,11 +396,11 @@ async def api_get_playlists(request, type: str):
return resp_json(await api.get_playlist_aux()) return resp_json(await api.get_playlist_aux())
@app.route("/library/playlist/<type:string>/<library_id:string>") @app.route("/library/playlist/<type:str>/<library_id:str>")
async def api_get_playlist(request, type: str, library_id: str): async def api_get_playlist(request, type: str, library_id: str):
if type not in ["music", "aux"]: if type not in ["music", "aux"]:
abort(401) raise SanicException("Bad Request",400)
if type == "music": if type == "music":
return resp_json(await api.get_playlist_music_items(library_id)) return resp_json(await api.get_playlist_music_items(library_id))
@ -424,10 +422,10 @@ def json_status(request):
# Get audio for UI to generate waveforms. # Get audio for UI to generate waveforms.
@app.route("/audiofile/<type:string>/<id:int>") @app.route("/audiofile/<type:str>/<id:int>")
async def audio_file(request, type: str, id: int): async def audio_file(request, type: str, id: int):
if type not in ["managed", "track"]: if type not in ["managed", "track"]:
abort(404) raise SanicException("Bad Request",400)
filename = resolve_external_file_path( filename = resolve_external_file_path(
"music-tmp/{}-{}.mp3".format(type, id)) "music-tmp/{}-{}.mp3".format(type, id))
@ -438,8 +436,7 @@ async def audio_file(request, type: str, id: int):
try: try:
response = await file(filename) response = await file(filename)
except FileNotFoundError: except FileNotFoundError:
abort(404) raise SanicException("Not Found: "+filename,404)
return
return response return response
@ -552,23 +549,13 @@ def WebServer(player_to: List[Queue], player_from: Queue, state: StateManager):
terminate = Terminator() terminate = Terminator()
while not terminate.terminate: while not terminate.terminate:
try: try:
sync( app.run(
app.run( host=server_state.get()["host"],
host=server_state.get()["host"], port=server_state.get()["port"],
port=server_state.get()["port"], auto_reload=False,
auto_reload=False, debug=not package.BETA,
debug=not package.BETA, access_log=not package.BETA,
access_log=not package.BETA,
)
) )
except Exception: except Exception as e:
break logger.log.exception(e)
try: sys.exit(1)
loop = asyncio.get_event_loop()
if loop:
loop.close()
if app:
app.stop()
del app
except Exception:
pass