import logging import os import sys import threading from threading import Thread from time import sleep from typing import final from starfall.config import Config from starfall.log import Log from starfall.types import SnapshotQueue from starfall.web import WebUI CURRENT_VERSION = "0.1.0-alpha.1" @final class Application: app: WebUI config: Config log: Log queue: SnapshotQueue threads: dict[str, Thread] def __init__(self): self.log = Log() logging.getLogger("app").debug( "OS Type: %s\nWorking Directory: %s\nApplication version: %s", os.name, os.path.realpath(os.curdir), CURRENT_VERSION, ) self.config = Config("config.toml", "config-sample.toml") if not self.config.get("app.run", False): logging.getLogger("app").critical( "Config file disallows execution.\n" + "Please make the necessary changes to the configuration" + " file and relaunch the program:\n\t%s", os.path.realpath(self.config.file_name), ) sys.exit() self.threads = {} self.queue = SnapshotQueue() self.app = WebUI() def start(self): self.threads["flask"] = Thread( target=self.app.run, args=( self.config, self.queue, ), daemon=True, ) self.threads["flask"].start() while threading.active_count() > 0: sleep(0.25) self.monitor_queue() def monitor_queue(self): for entry in self.queue.get_all_for_receiver("app"): logging.getLogger("app").info("Received queue message: %r", entry) if __name__ == "__main__": Application().start()