diff --git a/.gitignore b/.gitignore index ab19151..66518ac 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ venv/ build/build-exe-config.json build/build-exe-pyinstaller-command.bat build/build-exe-pyinstaller-command.sh +build/BAPSicle.platypus build/build/BAPSicle/ build/output/ *.spec diff --git a/build/BAPSicle.platypus b/build/BAPSicle.template.platypus similarity index 100% rename from build/BAPSicle.platypus rename to build/BAPSicle.template.platypus diff --git a/build/build-exe-config.template.json b/build/build-exe-config.template.json index e7167ed..42d3578 100644 --- a/build/build-exe-config.template.json +++ b/build/build-exe-config.template.json @@ -76,7 +76,11 @@ { "optionDest": "datas", "value": "/presenter-build;presenter-build/" - } + }, + { + "optionDest": "datas", + "value": "/package.json;./" + } ], "nonPyinstallerOptions": { "increaseRecursionLimit": false, diff --git a/build/build-linux.sh b/build/build-linux.sh index 47970ef..0b8e9ea 100755 --- a/build/build-linux.sh +++ b/build/build-linux.sh @@ -21,3 +21,5 @@ bash ./build-exe-pyinstaller-command.sh rm ./*.spec +rm ../build.py + diff --git a/build/build-macos.sh b/build/build-macos.sh index 8849623..bce24b8 100755 --- a/build/build-macos.sh +++ b/build/build-macos.sh @@ -3,7 +3,6 @@ cd "$(dirname "$0")" build_commit="$(git rev-parse --short HEAD)" echo "BUILD: str = \"$build_commit\"" > ../build.py -sed -i '' -e "s/BUILD_COMMIT/$build_commit/" "../config.py" python3 -m venv ../venv source ../venv/bin/activate @@ -20,6 +19,12 @@ bash ./build-exe-pyinstaller-command.sh rm ./*.spec +cd ../ +python3 build/generate-platypus-config.py +cd build + brew install platypus platypus --load-profile ./BAPSicle.platypus --overwrite ./output/BAPSicle.app + +rm ../build.py diff --git a/build/build-windows.bat b/build/build-windows.bat index 49d6ca2..314e459 100644 --- a/build/build-windows.bat +++ b/build/build-windows.bat @@ -28,5 +28,7 @@ build-exe-pyinstaller-command.bat del *.spec /q +del ..\build.py /q + echo "Output file should be located in 'output/' folder." TIMEOUT 5 diff --git a/build/generate-platypus-config.py b/build/generate-platypus-config.py new file mode 100755 index 0000000..63f1c90 --- /dev/null +++ b/build/generate-platypus-config.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python3 +from plistlib import load, dump +import package +import os +dir_path = os.path.dirname(os.path.realpath(__file__)) + +with open(dir_path + "/BAPSicle.template.platypus", 'rb') as temp: + pl = load(temp) + pl["Version"] = "{}~{}".format(package.VERSION, package.BUILD) + pl["Name"] = package.NICE_NAME + pl["StatusItemTitle"] = package.NICE_NAME + pl["Author"] = package.AUTHOR + pl["Identifier"] = "org.{}.{}".format(package.AUTHOR.lower().replace(" ", ""), package.NAME) + + with open(dir_path + "/BAPSicle.platypus", 'wb') as out: + dump(pl, out) diff --git a/build/macos-platypus.sh b/build/macos-platypus.sh index 1065d22..48cee1e 100755 --- a/build/macos-platypus.sh +++ b/build/macos-platypus.sh @@ -1,25 +1,26 @@ #!/bin/bash -if [ "$1" == "" ] -then +if [ "$1" == "" ]; then echo "DISABLED|BAPSicle Server" + echo "----" + if curl --output /dev/null --silent --fail --max-time 1 "http://localhost:13500/" + then + echo "Presenter" + echo "Server" echo "----" - if curl --output /dev/null --silent --head --fail --max-time 1 "http://localhost:13500" - then - echo "Presenter" - echo "Server" - echo "----" - echo "Stop Server" - else - echo "DISABLED|Presenter" - echo "DISABLED|Server" - echo "----" - echo "Start Server" - fi + echo "Restart Server" + echo "Stop Server" + else + echo "DISABLED|Presenter" + echo "DISABLED|Server" + echo "----" + echo "Start Server" + fi exit fi -if [ "$1" == "Stop Server" ] -then - curl "http://localhost:13500/quit" +if [ "$1" == "Stop Server" ]; then + curl --output /dev/null --silent "http://localhost:13500/quit" +elif [ "$1" == "Restart Server" ]; then + curl --output /dev/null --silent "http://localhost:13500/restart" else ./BAPSicle "$1" fi diff --git a/config.py b/config.py deleted file mode 100644 index 1b09875..0000000 --- a/config.py +++ /dev/null @@ -1,2 +0,0 @@ -# BAPSicle Details -VERSION: str = "0.1.0" diff --git a/helpers/os_environment.py b/helpers/os_environment.py index 15c8c37..27c1cf3 100644 --- a/helpers/os_environment.py +++ b/helpers/os_environment.py @@ -31,7 +31,6 @@ def resolve_local_file_path(relative_path: str): try: # PyInstaller creates a temp folder and stores path in _MEIPASS base_path: str = sys._MEIPASS - print("MEI", base_path) except Exception: base_path = os.path.abspath(".") diff --git a/launch.py b/launch.py index 8abe50a..b53a590 100755 --- a/launch.py +++ b/launch.py @@ -6,11 +6,13 @@ from typing import Any import webbrowser from setproctitle import setproctitle -from server import BAPSicleServer from helpers.the_terminator import Terminator def startServer(notifications=False): + # Only spend the time importing the Server if we want to start the server. Speeds up web browser opens. + from server import BAPSicleServer + server = multiprocessing.Process(target=BAPSicleServer) server.start() @@ -60,6 +62,7 @@ if __name__ == "__main__": # We got an argument! It's probably Platypus's UI. try: if (sys.argv[1]) == "Start Server": + print("NOTIFICATION:BAPSicle is starting, please wait...") webbrowser.open("http://localhost:13500/") startServer(notifications=True) if sys.argv[1] == "Server": @@ -67,7 +70,7 @@ if __name__ == "__main__": if sys.argv[1] == "Presenter": webbrowser.open("http://localhost:13500/presenter/") except Exception as e: - print("ALERT:BAPSicle failed with exception:\n", e) + print("ALERT:BAPSicle failed with exception of type {}:\n{}".format(type(e).__name__, str(e))) sys.exit(1) sys.exit(0) diff --git a/package.json b/package.json index 8b3fd88..7e4abca 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,8 @@ { "name": "bapsicle", + "nice_name": "BAPSicle", "version": "0.1.0", - "description": "Broadcast Playout System", + "description": "BAPS3, the third generation of University Radio York's Broadcast and Presenting Suite. This package includes the Server (BAPSicle) and Presenter (WebStudio)", "main": "index.js", "directories": { "doc": "docs", @@ -17,7 +18,7 @@ "type": "git", "url": "git+https://github.com/universityradioyork/bapsicle.git" }, - "author": "", + "author": "University Radio York", "license": "ISC", "bugs": { "url": "https://github.com/universityradioyork/bapsicle/issues" diff --git a/package.py b/package.py new file mode 100644 index 0000000..ceef218 --- /dev/null +++ b/package.py @@ -0,0 +1,20 @@ +# BAPSicle Details +from json import loads +from helpers.os_environment import resolve_local_file_path + +with open(resolve_local_file_path("package.json")) as file: + config = loads(file.read()) + VERSION: str = config["version"] + NAME: str = config["name"] + NICE_NAME: str = config["nice_name"] + DESCRIPTION: str = config["description"] + AUTHOR: str = config["author"] + LICENSE: str = config["license"] + + build_commit = "Dev" + try: + import build + build_commit = build.BUILD + except (ModuleNotFoundError, AttributeError): + pass + BUILD: str = build_commit diff --git a/server.py b/server.py index 6ab2610..34f0b98 100644 --- a/server.py +++ b/server.py @@ -28,7 +28,7 @@ if not isMacOS(): if isBundelled(): import build -import config +import package from typing import Dict, List from helpers.state_manager import StateManager from helpers.logging_manager import LoggingManager @@ -162,15 +162,11 @@ class BAPSicleServer: self.state.update("running_state", "running") - build_commit = "Dev" - if isBundelled(): - build_commit = build.BUILD - print("Launching BAPSicle...") # TODO: Check these match, if not, trigger any upgrade noticies / welcome - self.state.update("server_version", config.VERSION) - self.state.update("server_build", build_commit) + self.state.update("server_version", package.VERSION) + self.state.update("server_build", package.BUILD) channel_count = self.state.get()["num_channels"] self.player = [None] * channel_count @@ -183,7 +179,7 @@ class BAPSicleServer: self.websocket_to_q.append(multiprocessing.Queue()) self.controller_to_q.append(multiprocessing.Queue()) - print("Welcome to BAPSicle Server version: {}, build: {}.".format(config.VERSION, build_commit)) + print("Welcome to BAPSicle Server version: {}, build: {}.".format(package.VERSION, package.BUILD)) print("The Server UI is available at http://{}:{}".format(self.state.get()["host"], self.state.get()["port"])) # TODO Move this to player or installer. diff --git a/setup.py b/setup.py index 5a47eb1..b38ade3 100644 --- a/setup.py +++ b/setup.py @@ -1,3 +1,10 @@ from setuptools import setup, find_packages +import package -setup(name="bapsicle", version="0.0.1", packages=find_packages()) +setup( + name=package.NAME, + version=package.VERSION, + description=package.DESCRIPTION, + author=package.AUTHOR, + license=package.LICENSE, + packages=find_packages()) diff --git a/ui-templates/base.html b/ui-templates/base.html index 546f75c..abb98a6 100644 --- a/ui-templates/base.html +++ b/ui-templates/base.html @@ -10,7 +10,7 @@ {% block head %} {% endblock %} - BAPSicle {% if data.ui_title %} | {{data.ui_title}}{% endif %} + BAPSicle{% if data.ui_title %} | {{data.ui_title}}{% endif %} diff --git a/web_server.py b/web_server.py index 9ec7cc5..0a3ba56 100644 --- a/web_server.py +++ b/web_server.py @@ -20,7 +20,7 @@ from time import sleep import json import os -from helpers.os_environment import resolve_local_file_path +from helpers.os_environment import isBundelled, resolve_local_file_path from helpers.logging_manager import LoggingManager from helpers.device_manager import DeviceManager from helpers.state_manager import StateManager @@ -386,8 +386,9 @@ def WebServer(player_to: List[Queue], player_from: List[Queue], state: StateMana sync(app.run( host=server_state.get()["host"], port=server_state.get()["port"], - debug=True, - auto_reload=False + debug=(not isBundelled()), + auto_reload=False, + access_log=(not isBundelled()) )) except Exception: break