BAPSicle/launch_standalone.py

61 lines
1.9 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
2020-10-25 01:23:24 +00:00
import multiprocessing
import time
import sys
import webbrowser
from setproctitle import setproctitle
2020-10-25 01:23:24 +00:00
from server import BAPSicleServer
2021-04-08 19:53:51 +00:00
2020-11-01 02:37:40 +00:00
def startServer():
2020-11-01 00:31:58 +00:00
server = multiprocessing.Process(target=BAPSicleServer)
server.start()
try:
while True:
time.sleep(5)
if server and server.is_alive():
pass
else:
print("Server dead. Exiting.")
sys.exit(0)
# Catch the handler being killed externally.
except KeyboardInterrupt:
print("Received KeyboardInterupt")
except SystemExit:
print("Received SystemExit")
except Exception as e:
print("Received unexpected exception: {}".format(e))
2020-11-01 00:31:58 +00:00
2020-11-01 02:37:40 +00:00
2021-04-08 19:53:51 +00:00
if __name__ == "__main__":
2020-11-01 02:37:40 +00:00
# On Windows, calling this function is necessary.
# Causes all kinds of loops if not present.
# IT HAS TO BE RIGHT HERE, AT THE TOP OF __MAIN__
# NOT INSIDE AN IF STATEMENT. RIGHT. HERE.
# If it's not here, multiprocessing just doesn't run in the package.
# Freeze support refers to being packaged with Pyinstaller.
multiprocessing.freeze_support()
setproctitle("BAPSicle - Standalone Launch")
if len(sys.argv) > 1:
# We got an argument! It's probably Platypus's UI.
try:
if (sys.argv[1]) == "Start Server":
print("NOTIFICATION:Welcome to BAPSicle!")
webbrowser.open("http://localhost:13500/")
startServer()
2021-04-08 19:53:51 +00:00
if sys.argv[1] == "Status":
webbrowser.open("http://localhost:13500/status")
2021-04-08 19:53:51 +00:00
if sys.argv[1] == "Config":
webbrowser.open("http://localhost:13500/config")
2021-04-08 19:53:51 +00:00
if sys.argv[1] == "Logs":
webbrowser.open("http://localhost:13500/logs")
except Exception as e:
print("ALERT:BAPSicle failed with exception:\n", e)
sys.exit(1)
sys.exit(0)
else:
startServer()