From 978c0424735e6ad710b45c41d02899d46b881f11 Mon Sep 17 00:00:00 2001 From: Matthew Stratford Date: Fri, 18 Mar 2022 17:33:28 +0000 Subject: [PATCH 01/15] Revert sanic version to fix OSError on linux. --- build/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/requirements.txt b/build/requirements.txt index 2dcdff0..6a1a9f0 100644 --- a/build/requirements.txt +++ b/build/requirements.txt @@ -1,6 +1,6 @@ wheel pygame==2.0.2 -sanic==21.9.3 +sanic==21.3.4 sanic-Cors==1.0.1 syncer==1.3.0 aiohttp==3.7.4 From f7e71cc32e595cf6bb0320bb5d1e908bcc41f66c Mon Sep 17 00:00:00 2001 From: Matthew Stratford Date: Sat, 19 Mar 2022 15:59:59 +0000 Subject: [PATCH 02/15] Build for python3.8 and 3.9 --- .github/workflows/build.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 32999fe..4722e68 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -46,7 +46,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ['3.9'] + python-version: ['3.8','3.9'] node-version: ['14'] steps: From a838ef76217b2cfea8f7585607b28c65257ab709 Mon Sep 17 00:00:00 2001 From: Matthew Stratford Date: Sat, 19 Mar 2022 16:01:37 +0000 Subject: [PATCH 03/15] Fix exit hang on linux --- launch.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/launch.py b/launch.py index 712bb6a..eed32ec 100755 --- a/launch.py +++ b/launch.py @@ -2,6 +2,7 @@ import multiprocessing import time import sys +import os from typing import Any import webbrowser from setproctitle import setproctitle @@ -31,11 +32,14 @@ def startServer(notifications=False): printer("Server dead. Exiting.") if notifications: notif("BAPSicle Server Stopped!") - sys.exit(0) + os._exit(0) if server and server.is_alive(): + printer("Terminating server.") server.terminate() + printer("Waiting to terminate.") server.join(timeout=20) # If we somehow get stuck stopping BAPSicle let it die. + printer("Terminated") # Catch the handler being killed externally. except Exception as e: @@ -80,9 +84,10 @@ if __name__ == "__main__": type(e).__name__, e ) ) - sys.exit(1) + os._exit(1) - sys.exit(0) + os._exit(0) else: startServer() - sys.exit(0) + printer("Exiting.") + os._exit(0) From 86c0ca14e742f05486497a849746b6806742791a Mon Sep 17 00:00:00 2001 From: Matthew Stratford Date: Sat, 19 Mar 2022 16:01:55 +0000 Subject: [PATCH 04/15] Fix exit hang on linux --- server.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server.py b/server.py index 46d7045..03b4462 100644 --- a/server.py +++ b/server.py @@ -13,6 +13,7 @@ October, November 2020 """ from datetime import datetime +import os from file_manager import FileManager import multiprocessing from multiprocessing.queues import Queue @@ -98,7 +99,7 @@ class BAPSicleServer: self.stopServer() if self.state.get()["running_state"] != "restarting": - break + os._exit(0) def check_processes(self): From 01dfb3f3d6cc915d05b93db43f6973489bb87888 Mon Sep 17 00:00:00 2001 From: Matthew Stratford Date: Sat, 19 Mar 2022 16:03:18 +0000 Subject: [PATCH 05/15] Update sanic deprications and remove asyncio stuff not needed. --- web_server.py | 60 ++++++++++++++++++++------------------------------- 1 file changed, 23 insertions(+), 37 deletions(-) diff --git a/web_server.py b/web_server.py index a14627e..48ba3c2 100644 --- a/web_server.py +++ b/web_server.py @@ -1,10 +1,8 @@ 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 json as resp_json from sanic_cors import CORS -from syncer import sync -import asyncio from jinja2 import Environment, FileSystemLoader from jinja2.utils import select_autoescape from urllib.parse import unquote @@ -89,7 +87,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): @@ -258,8 +256,7 @@ def ui_logs_render(request, path): try: log_file = open(resolve_external_file_path("/logs/{}.log").format(path)) except FileNotFoundError: - abort(404) - return + raise SanicException("Not Found",404) data = { "logs": log_file.read().splitlines()[ @@ -285,10 +282,10 @@ def player_simple(request, channel: int, command: str): player_to_q[channel].put("UI:" + command.upper()) return redirect("/status") - abort(404) + raise SanicException("Not Found",404) -@app.route("/player//seek/") +@app.route("/player//seek/") def player_seek(request, channel: int, pos: float): player_to_q[channel].put("UI:SEEK:" + str(pos)) @@ -310,7 +307,7 @@ def player_remove(request, channel: int, channel_weight: int): return redirect("/status") -@app.route("/player//output/") +@app.route("/player//output/") def player_output(request, channel: int, name: Optional[str]): player_to_q[channel].put("UI:OUTPUT:" + unquote(str(name))) return redirect("/config/player") @@ -322,7 +319,7 @@ def player_autoadvance(request, channel: int, state: int): return redirect("/status") -@app.route("/player//repeat/") +@app.route("/player//repeat/") def player_repeat(request, channel: int, state: str): player_to_q[channel].put("UI:REPEAT:" + state.upper()) return redirect("/status") @@ -386,11 +383,11 @@ async def api_search_library(request): ) -@app.route("/library/playlists/") +@app.route("/library/playlists/") async def api_get_playlists(request, type: str): if type not in ["music", "aux"]: - abort(401) + raise SanicException("Bad Request",400) if type == "music": return resp_json(await api.get_playlist_music()) @@ -398,11 +395,11 @@ async def api_get_playlists(request, type: str): return resp_json(await api.get_playlist_aux()) -@app.route("/library/playlist//") +@app.route("/library/playlist//") async def api_get_playlist(request, type: str, library_id: str): if type not in ["music", "aux"]: - abort(401) + raise SanicException("Bad Request",400) if type == "music": return resp_json(await api.get_playlist_music_items(library_id)) @@ -424,10 +421,10 @@ def json_status(request): # Get audio for UI to generate waveforms. -@app.route("/audiofile//") +@app.route("/audiofile//") async def audio_file(request, type: str, id: int): if type not in ["managed", "track"]: - abort(404) + raise SanicException("Bad Request",400) filename = resolve_external_file_path( "music-tmp/{}-{}.mp3".format(type, id)) @@ -438,8 +435,7 @@ async def audio_file(request, type: str, id: int): try: response = await file(filename) except FileNotFoundError: - abort(404) - return + raise SanicException("Not Found",404) return response @@ -552,23 +548,13 @@ def WebServer(player_to: List[Queue], player_from: Queue, state: StateManager): terminate = Terminator() while not terminate.terminate: try: - sync( - app.run( - host=server_state.get()["host"], - port=server_state.get()["port"], - auto_reload=False, - debug=not package.BETA, - access_log=not package.BETA, - ) + app.run( + host=server_state.get()["host"], + port=server_state.get()["port"], + auto_reload=False, + debug=not package.BETA, + access_log=not package.BETA, ) - except Exception: - break - try: - loop = asyncio.get_event_loop() - if loop: - loop.close() - if app: - app.stop() - del app - except Exception: - pass + except Exception as e: + logger.log.exception(e) + sleep(1) From d6304ccff8f9c35ee087d324ac4d7cb073aeff1c Mon Sep 17 00:00:00 2001 From: Matthew Stratford Date: Sat, 19 Mar 2022 16:04:13 +0000 Subject: [PATCH 06/15] Fix missing pyinstaller in path --- build/build-exe.py | 7 ++++++- build/build-linux.sh | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/build/build-exe.py b/build/build-exe.py index c3fde21..8a46cd8 100644 --- a/build/build-exe.py +++ b/build/build-exe.py @@ -1,10 +1,15 @@ import json +from helpers.os_environment import isLinux file = open('build-exe-config.json', 'r') config = json.loads(file.read()) file.close() -cmd_str = "pyinstaller " +if isLinux(): + cmd_str = "python3 -m PyInstaller " +else: + cmd_str = "pyinstaller " + json_dests = ["icon_file", "clean_build"] pyi_dests = ["icon", "clean"] diff --git a/build/build-linux.sh b/build/build-linux.sh index c5a9ea9..49d60f0 100755 --- a/build/build-linux.sh +++ b/build/build-linux.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -x cd "$(dirname "$0")" # Get the git commit / branch and write it into build.py. From 64b1ef71ac34405a130d2ad89f3f65fd799ebe40 Mon Sep 17 00:00:00 2001 From: Matthew Stratford Date: Sat, 19 Mar 2022 16:04:29 +0000 Subject: [PATCH 07/15] Update sanic requirements. --- build/requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/requirements.txt b/build/requirements.txt index 6a1a9f0..3909025 100644 --- a/build/requirements.txt +++ b/build/requirements.txt @@ -1,7 +1,7 @@ wheel pygame==2.0.2 -sanic==21.3.4 -sanic-Cors==1.0.1 +sanic==21.9.3 +sanic-Cors==2.0.1 syncer==1.3.0 aiohttp==3.7.4 mutagen==1.45.1 From efd0273feaa7bb66494a9c8c82a225a6a6173418 Mon Sep 17 00:00:00 2001 From: Matthew Stratford Date: Sat, 19 Mar 2022 17:22:04 +0000 Subject: [PATCH 08/15] Revert "Fix exit hang on linux" This reverts commit 86c0ca14e742f05486497a849746b6806742791a. --- server.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/server.py b/server.py index 03b4462..46d7045 100644 --- a/server.py +++ b/server.py @@ -13,7 +13,6 @@ October, November 2020 """ from datetime import datetime -import os from file_manager import FileManager import multiprocessing from multiprocessing.queues import Queue @@ -99,7 +98,7 @@ class BAPSicleServer: self.stopServer() if self.state.get()["running_state"] != "restarting": - os._exit(0) + break def check_processes(self): From 330a1dea5c5ef495037ffd60cec02bd88c848b77 Mon Sep 17 00:00:00 2001 From: Matthew Stratford Date: Sat, 19 Mar 2022 17:22:42 +0000 Subject: [PATCH 09/15] Revert "Fix exit hang on linux" This reverts commit a838ef76217b2cfea8f7585607b28c65257ab709. --- launch.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/launch.py b/launch.py index eed32ec..712bb6a 100755 --- a/launch.py +++ b/launch.py @@ -2,7 +2,6 @@ import multiprocessing import time import sys -import os from typing import Any import webbrowser from setproctitle import setproctitle @@ -32,14 +31,11 @@ def startServer(notifications=False): printer("Server dead. Exiting.") if notifications: notif("BAPSicle Server Stopped!") - os._exit(0) + sys.exit(0) if server and server.is_alive(): - printer("Terminating server.") server.terminate() - printer("Waiting to terminate.") server.join(timeout=20) # If we somehow get stuck stopping BAPSicle let it die. - printer("Terminated") # Catch the handler being killed externally. except Exception as e: @@ -84,10 +80,9 @@ if __name__ == "__main__": type(e).__name__, e ) ) - os._exit(1) + sys.exit(1) - os._exit(0) + sys.exit(0) else: startServer() - printer("Exiting.") - os._exit(0) + sys.exit(0) From 617376a54be80ebd597c2c192743646945a8ed43 Mon Sep 17 00:00:00 2001 From: Matthew Stratford Date: Sat, 19 Mar 2022 17:46:01 +0000 Subject: [PATCH 10/15] Shutdown webserver cleanly and let server.py restart it. --- web_server.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/web_server.py b/web_server.py index 48ba3c2..7e8af5e 100644 --- a/web_server.py +++ b/web_server.py @@ -14,6 +14,7 @@ from queue import Empty from time import sleep import json import os +import sys from helpers.os_environment import ( isLinux, @@ -557,4 +558,4 @@ def WebServer(player_to: List[Queue], player_from: Queue, state: StateManager): ) except Exception as e: logger.log.exception(e) - sleep(1) + sys.exit(1) From c70092f9d9e03435943ad1ac39ac0c4fdaae5b37 Mon Sep 17 00:00:00 2001 From: Matthew Stratford Date: Sat, 19 Mar 2022 17:46:19 +0000 Subject: [PATCH 11/15] Make sure all sanic deps are included --- build/build-exe-config.template.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/build/build-exe-config.template.json b/build/build-exe-config.template.json index 4f7e3ee..e99b569 100644 --- a/build/build-exe-config.template.json +++ b/build/build-exe-config.template.json @@ -80,6 +80,10 @@ { "optionDest": "datas", "value": "/package.json;./" + }, + { + "optionDest": "collect-all", + "value": "sanic" } ], "nonPyinstallerOptions": { From 433d05336c12b0e56086141423cd70a7db0ca148 Mon Sep 17 00:00:00 2001 From: Matthew Stratford Date: Sat, 19 Mar 2022 17:49:45 +0000 Subject: [PATCH 12/15] Let script fail if it errors. --- build/build-macos.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/build/build-macos.sh b/build/build-macos.sh index 1648b57..2b3337e 100755 --- a/build/build-macos.sh +++ b/build/build-macos.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -x cd "$(dirname "$0")" # Get the git commit / branch and write it into build.py. From 67c74b09ddfa8d5ee772227afa5756e3c5ea7cc4 Mon Sep 17 00:00:00 2001 From: Matthew Stratford Date: Sat, 19 Mar 2022 17:54:39 +0000 Subject: [PATCH 13/15] Fix typo --- ui-templates/config_server.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui-templates/config_server.html b/ui-templates/config_server.html index 18a2852..04e7d99 100644 --- a/ui-templates/config_server.html +++ b/ui-templates/config_server.html @@ -56,7 +56,7 @@ {% endfor %}

- Normalisation requests significant CPU requirements, if you're finding the CPU usuage is too high / causing audio glitches, disable this feature. ffmpeg or avconf required. + Normalisation requests significant CPU requirements, if you're finding the CPU usage is too high / causing audio glitches, disable this feature. ffmpeg or avconf required.


From 76ddea56f8225ebea55198837a7982bafd9c4061 Mon Sep 17 00:00:00 2001 From: Matthew Stratford Date: Sat, 19 Mar 2022 18:45:51 +0000 Subject: [PATCH 14/15] Attempt fix of setproctitle missing --- build/build-exe-config.template.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/build/build-exe-config.template.json b/build/build-exe-config.template.json index e99b569..c40e3c2 100644 --- a/build/build-exe-config.template.json +++ b/build/build-exe-config.template.json @@ -84,6 +84,10 @@ { "optionDest": "collect-all", "value": "sanic" + }, + { + "optionDest": "collect-all", + "value": "setproctitle" } ], "nonPyinstallerOptions": { From 06812b975ba76912c345bc5b75f179c36a37e6f8 Mon Sep 17 00:00:00 2001 From: Matthew Stratford Date: Fri, 10 Mar 2023 19:23:33 +0000 Subject: [PATCH 15/15] List filename in 404 error --- web_server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web_server.py b/web_server.py index 7e8af5e..1189abe 100644 --- a/web_server.py +++ b/web_server.py @@ -436,7 +436,7 @@ async def audio_file(request, type: str, id: int): try: response = await file(filename) except FileNotFoundError: - raise SanicException("Not Found",404) + raise SanicException("Not Found: "+filename,404) return response