From d511f1774d20acaeb11c6c5387270237ec0396a0 Mon Sep 17 00:00:00 2001 From: Matthew Stratford Date: Sun, 11 Apr 2021 19:02:19 +0100 Subject: [PATCH] Add build version when packaging. --- build/build-linux.sh | 9 ++++- build/build-macos.sh | 10 +++-- build/{build-exe.bat => build-windows.bat} | 13 +++++- build/install-ubuntu.sh | 0 build/macos-platypus.sh | 0 config.py | 3 +- server.py | 47 +++++++++++++--------- templates/index.html | 5 ++- 8 files changed, 61 insertions(+), 26 deletions(-) rename build/{build-exe.bat => build-windows.bat} (57%) mode change 100644 => 100755 build/install-ubuntu.sh mode change 100644 => 100755 build/macos-platypus.sh diff --git a/build/build-linux.sh b/build/build-linux.sh index 1e66aba..f238c5e 100755 --- a/build/build-linux.sh +++ b/build/build-linux.sh @@ -1,11 +1,18 @@ #!/bin/bash cd "$(dirname "$0")" +build_commit="$(git rev-parse --short HEAD)" +echo "$build_commit" +sed -i "s/BUILD_COMMIT/$build_commit/" ../config.py + apt install libportaudio2 +python3 -m venv ../venv +source ../venv/bin/activate + pip3 install -r requirements.txt pip3 install -r requirements-linux.txt -pip3 install -e ..\ +pip3 install -e ../ python3 ./generate-build-exe-config.py diff --git a/build/build-macos.sh b/build/build-macos.sh index 0aadc0a..bc34f6c 100755 --- a/build/build-macos.sh +++ b/build/build-macos.sh @@ -1,6 +1,13 @@ #!/bin/bash cd "$(dirname "$0")" +build_commit="$(git rev-parse --short HEAD)" +echo "$build_commit" +sed -i '' -e "s/BUILD_COMMIT/$build_commit/" "../config.py" + +python3 -m venv ../venv +source ../venv/bin/activate + pip3 install -r requirements.txt pip3 install -r requirements-macos.txt pip3 install -e ..\ @@ -16,6 +23,3 @@ rm ./*.spec brew install platypus platypus --load-profile ./BAPSicle.platypus --overwrite ./output/BAPSicle.app -mkdir ./output/state -mkdir ./output/logs -mkdir ./output/music-tmp diff --git a/build/build-exe.bat b/build/build-windows.bat similarity index 57% rename from build/build-exe.bat rename to build/build-windows.bat index a2cf6e0..dfc08d0 100644 --- a/build/build-exe.bat +++ b/build/build-windows.bat @@ -1,4 +1,15 @@ cd /D "%~dp0" + +: Get the git commit and write it into config.py. +FOR /F "tokens=* USEBACKQ" %%F IN (`git rev-parse --short HEAD`) DO ( +SET build_commit=%%F +) + +(Get-Content "..\config.py") -replace 'BUILD_COMMIT', '%build_commit%' | Out-File -encoding ASCII "..\config.py" + +py -m venv ..\venv +..\venv\Scripts\activate + pip install -r requirements.txt pip install -r requirements-windows.txt pip install -e ..\ @@ -15,4 +26,4 @@ build-exe-pyinstaller-command.bat del *.spec /q echo "Output file should be located in 'output/' folder." -TIMEOUT 5 \ No newline at end of file +TIMEOUT 5 diff --git a/build/install-ubuntu.sh b/build/install-ubuntu.sh old mode 100644 new mode 100755 diff --git a/build/macos-platypus.sh b/build/macos-platypus.sh old mode 100644 new mode 100755 diff --git a/config.py b/config.py index 563451d..4de924d 100644 --- a/config.py +++ b/config.py @@ -1,2 +1,3 @@ # BAPSicle Details -VERSION: float = 0.1 +VERSION: str = "0.1.0" +BUILD: str = "2bc61be" diff --git a/server.py b/server.py index 6f71dd3..4f182b8 100644 --- a/server.py +++ b/server.py @@ -27,7 +27,7 @@ import logging from player_handler import PlayerHandler -from helpers.os_environment import isMacOS +from helpers.os_environment import isBundelled, isMacOS from helpers.device_manager import DeviceManager if not isMacOS(): @@ -48,15 +48,16 @@ class BAPSicleServer: startServer() - def __del__(self): - stopServer() + # def __del__(self): + # stopServer() def get_flask(self): return app default_state = { - "server_version": 0, + "server_version": config.VERSION, + "server_build": config.BUILD, "server_name": "URY BAPSicle", "host": "localhost", "port": 13500, @@ -64,7 +65,7 @@ default_state = { "num_channels": 3, "serial_port": None, "ser_connected": False, - "api_key": None, + "myradio_api_key": None, "myradio_base_url": "https://ury.org.uk/myradio", "myradio_api_url": "https://ury.org.uk/api" } @@ -104,7 +105,8 @@ def ui_index(): data = { "ui_page": "index", "ui_title": "", - "server_version": config.VERSION, + "server_version": state.state["server_version"], + "server_build": state.state["server_build"], "server_name": state.state["server_name"], } return render_template("index.html", data=data) @@ -467,10 +469,10 @@ def clear_all_channels(): @app.route("/logs") def list_logs(): data = { - "ui_page": "loglist", + "ui_page": "logs", "ui_title": "Logs", "logs": ["BAPSicleServer"] - + ["channel{}".format(x) for x in range(state.state["num_channels"])], + + ["Player{}".format(x) for x in range(state.state["num_channels"])], } return render_template("loglist.html", data=data) @@ -480,7 +482,7 @@ def send_logs(path): log_file = open("logs/{}.log".format(path)) data = { "logs": log_file.read().splitlines(), - "ui_page": "log", + "ui_page": "logs", "ui_title": "Logs - {}".format(path), } log_file.close() @@ -507,7 +509,13 @@ def startServer(): logger = LoggingManager("BAPSicleServer") state = StateManager("BAPSicleServer", logger, default_state) + # TODO: Check these match, if not, trigger any upgrade noticies / welcome state.update("server_version", config.VERSION) + if isBundelled(): + build = config.BUILD + else: + build = "Dev" + state.update("server_build", build) if isMacOS(): multiprocessing.set_start_method("spawn", True) @@ -610,19 +618,21 @@ def startServer(): def stopServer(): - global channel_p, channel_from_q, channel_to_q, websockets_server, webserver, controller_handler + global channel_p, channel_from_q, channel_to_q, websockets_server, controller_handler, webserver print("Stopping Controllers") - controller_handler.terminate() - controller_handler.join() + if controller_handler: + controller_handler.terminate() + controller_handler.join() print("Stopping Websockets") websocket_to_q[0].put("WEBSOCKET:QUIT") - websockets_server.join() - del websockets_server + if websockets_server: + websockets_server.join() + del websockets_server print("Stopping server.py") for q in channel_to_q: - q.put("QUIT") + q.put("ALL:QUIT") for channel in channel_p: try: channel.join() @@ -636,9 +646,10 @@ def stopServer(): print("Stopped all players.") print("Stopping webserver") - global webserver - webserver.terminate() - webserver.join() + + if webserver: + webserver.terminate() + webserver.join() print("Stopped webserver") diff --git a/templates/index.html b/templates/index.html index ac2e7d4..0015f70 100644 --- a/templates/index.html +++ b/templates/index.html @@ -17,9 +17,10 @@ Open WebStudio
-

Version: {{data.server_version}} | Server Name: {{data.server_name}}

+

Version: {{data.server_version}} - Build: {{data.server_build}}

+

Server Name: {{data.server_name}}

-{% endblock %} \ No newline at end of file +{% endblock %}