Improve packaging, use package.json for all package info

This commit is contained in:
Matthew Stratford 2021-04-19 15:45:20 +01:00
parent c13e2105da
commit 2c498ff65c
17 changed files with 95 additions and 39 deletions

1
.gitignore vendored
View file

@ -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

View file

@ -76,7 +76,11 @@
{
"optionDest": "datas",
"value": "/presenter-build;presenter-build/"
}
},
{
"optionDest": "datas",
"value": "/package.json;./"
}
],
"nonPyinstallerOptions": {
"increaseRecursionLimit": false,

View file

@ -21,3 +21,5 @@ bash ./build-exe-pyinstaller-command.sh
rm ./*.spec
rm ../build.py

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -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

View file

@ -1,2 +0,0 @@
# BAPSicle Details
VERSION: str = "0.1.0"

View file

@ -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(".")

View file

@ -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)

View file

@ -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"

20
package.py Normal file
View file

@ -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

View file

@ -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.

View file

@ -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())

View file

@ -10,7 +10,7 @@
{% block head %}
{% endblock %}
<title>BAPSicle {% if data.ui_title %} | {{data.ui_title}}{% endif %}</title>
<title>BAPSicle{% if data.ui_title %} | {{data.ui_title}}{% endif %}</title>
<!-- Custom fonts for this template-->
<link href="/static/vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">

View file

@ -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