ovenemprex/main.py
Trysdyn Black c83acbdcfe Reinitialize repo to remove private data
10,000 hours mucking with `git filter-repo` and no reasonable use-case
found. On the plus side, anyone looking at this and curious what I nuked
isn't missing much. This lived in a monorepo up until about a week ago.
2024-12-20 14:45:49 -08:00

59 lines
1.5 KiB
Python

"""
Management script to let trusted users control OME.
This should listen on localhost and have Caddy proxy with auth.
"""
from pathlib import Path
import cherrypy
from cherrypy.process.plugins import SignalHandler
import admission
import config
import management
import ovenapi
import status
import viewer
cherrypy.config.update({
"server.socket_host": "127.0.0.1",
"environment": "production",
"tools.proxy.on": True,
})
class Noop:
pass
def on_exit() -> None:
config.save()
cherrypy.engine.exit()
if __name__ == "__main__":
# Establish our config save-out signals
signalhandler = SignalHandler(cherrypy.engine)
signalhandler.handlers["SIGTERM"] = on_exit
signalhandler.handlers["SIGHUP"] = on_exit
signalhandler.handlers["SIGQUIT"] = on_exit
signalhandler.handlers["SIGINT"] = on_exit
signalhandler.subscribe()
# Load config values
config.load()
# If we have API access, use it to pull our stream list
if config.is_api_ready():
config.LAST_STREAM_LIST = ovenapi.OvenAPI(config.API_USER, config.API_PASS).get_stream_list()
runpath = Path(Path(__file__).parent.resolve(), "assets")
cherrypy.tree.mount(admission.Admission(), "/admission")
cherrypy.tree.mount(management.Management(), "/management")
cherrypy.tree.mount(status.Status(), "/status")
cherrypy.tree.mount(Noop(), "/assets", config={"/": {"tools.staticdir.on": True, "tools.staticdir.dir": runpath}})
cherrypy.tree.mount(viewer.Viewer(), "/")
cherrypy.engine.start()
cherrypy.engine.block()