Files
package-repo/sources/eendoe_hyperdeck/packaging/eendoe-hyperdeck/usr/share/hyperdeck/main.py
T
bart 9cc903b2a4
Build and Publish Debian Packages / Build Packages (push) Failing after 18s
Build and Publish Debian Packages / Publish to eendoe repository (push) Skipped
Initial import: sources, staging packages, build scripts and CI workflow
2026-10-20 21:20:13 +02:00

71 lines
1.5 KiB
Python

import logging
import os
import sys
import getopt
from hyperdeck.application import HyperDeck
import asyncio
import uvicorn
from hyperdeck.db import create_db_and_tables
from hyperdeck.jsondb import jsonconverter
logging.basicConfig(level=logging.INFO)
opts, args = getopt.getopt(sys.argv[1:], "c:o:")
configfile = "config.json"
for opt, arg in opts:
if opt == "-h":
print("test.py -c <config>")
sys.exit()
elif opt in ("-c"):
configfile = arg
create_db_and_tables()
hApp = HyperDeck()
hApp.load_config(configfile)
if os.path.exists("schedule.json"):
logging.info("Found schedule.json, loading")
conv = jsonconverter()
conv.loadschedule()
logging.info("Loading done, creating database")
hApp.schedule.saveItems(conv.schedule)
logging.info("Database ready, moving file")
os.rename("schedule.json","schedule.json.bak")
from hyperdeck.api import app as app_fastapi
from hyperdeck.scheduler import app as app_rocketry
session = app_rocketry.session
class Server(uvicorn.Server):
def handle_exit(self, sig: int, frame) -> None:
app_rocketry.session.shut_down()
return super().handle_exit(sig, frame)
async def app():
server = Server(
config=uvicorn.Config(
app_fastapi, workers=1, host=["0.0.0.0", "::"], port=8180, loop="asyncio"
)
)
api = asyncio.create_task(server.serve())
sched = asyncio.create_task(app_rocketry.serve())
await asyncio.wait([sched, api])
if __name__ == "__main__":
asyncio.run(app())