Beispiel #1
0
    def __init__(self):
        log = logger("Database")

        db.bind(provider="sqlite",
                filename=settings.DATABASE_FILE,
                create_db=True)
        db.generate_mapping(create_tables=True)

        log.info("Database initialized")
Beispiel #2
0
    def __init__(self, settings):
        self.settings = settings
        device_config = self.get_config()

        self.log = logger(f"Plaintext fetcher {device_config['url']}")

        self.url = device_config["url"]
        self.interval = device_config["interval"]
        self.timeout = device_config["timeout"]
        self.json = device_config["json"]

        self.params = None
        self.message_queue = []
        self.success = False
        self.active = True
        self.add_changed("handlers")

        Thread(target=self._fetcher).start()
Beispiel #3
0
    def __init__(self, database):
        self.database = database
        self.data_manager = DataManager(database)
        self.registered_handlers = {}
        self.last_messages = {}
        self.active = True
        self.changed = []

        self.log = logger(f"Handler manager")

        handlers = database.get_handlers()

        self.log.info(f"Loaded {len(handlers)} handlers from database")

        for handler in handlers:
            handler_class = get_handler_class(handler.type)
            handler_instance = handler_class(handler.settings)
            self.register_handler(handler.id, handler_instance)

        self.thread = Thread(target=self._handler_watcher)
        self.thread.start()
Beispiel #4
0
    def __init__(self, settings):
        self.settings = settings
        device_config = self.get_config()

        self.log = logger(f"SerialDevice {device_config['port']}")
        self.connection = serial.Serial()

        self.connection.port = device_config["port"]
        self.connection.baudrate = device_config["baudrate"]
        self.connection.timeout = device_config["timeout"]
        self.auto_reconnect = device_config["auto_reconnect"]

        self.message_queue = [
        ]  # TODO: The list will be used in multiple threads

        self.active = False
        self.add_changed("handlers")

        if self.reconnect():
            self.active = True
            Thread(target=self._message_watcher).start()
Beispiel #5
0
def _quit_handler(_, __):
    """Handler for exit signal."""
    print("\nSIGINT signal detected. Exiting")
    for module in registered_modules:
        module.exit()


if __name__ == "__main__":

    signal(SIGINT, _quit_handler)

    # TODO: For temporary debug clarity only
    if path.isfile(settings.LOG_FILE):
        remove(settings.LOG_FILE)

    log = logger("Main")
    log.info("Starting application")

    # Initialize main modules
    db = database.Database()
    manager = HandlerManager(db)

    # Register modules for SIGINT handler
    register_modules(db, manager)

    if settings.WEB_SERVER:
        web = FlaskWebServer(manager, db)
        register_modules(web)

    # Wait for the manager thread to end
    manager.thread.join()