From 6d016d272f6ef2512f16f5b5ce2d5578573cf0f2 Mon Sep 17 00:00:00 2001 From: clerie Date: Sat, 23 Dec 2023 22:13:27 +0100 Subject: [PATCH] Allow specific components to be enabled an disabled --- fieldpoc/config.py | 14 +++++++++++++- fieldpoc/fieldpoc.py | 8 ++++++-- fieldpoc_config.json | 2 ++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/fieldpoc/config.py b/fieldpoc/config.py index b2107eb..0506122 100644 --- a/fieldpoc/config.py +++ b/fieldpoc/config.py @@ -1,12 +1,18 @@ #!/usr/bin/env python3 class ConfigBase: + _DEFAULTS = {} + def __init__(self, c): self._c = c def __getattr__(self, name): + # check if key is in config if name in self._c.keys(): return self._c.get(name) + # check if key is in default config + elif name in self._DEFAULTS.keys(): + return self._DEFAULTS.get(name) else: raise AttributeError() @@ -20,6 +26,10 @@ class DatabaseConfig(ConfigBase): class DectConfig(ConfigBase): + _DEFAULTS = { + "enabled": True, + } + def __init__(self, c): self._c = c @@ -30,7 +40,9 @@ class ExtensionsConfig(ConfigBase): pass class YateConfig(ConfigBase): - pass + _DEFAULTS = { + "enabled": True, + } class Config: diff --git a/fieldpoc/fieldpoc.py b/fieldpoc/fieldpoc.py index 44ad259..62a82b3 100644 --- a/fieldpoc/fieldpoc.py +++ b/fieldpoc/fieldpoc.py @@ -42,13 +42,15 @@ class FieldPOC: logger.info("initialising threads") self.threads = { "controller": threading.Thread(target=self._controller.run), - "dect": threading.Thread(target=self._dect.run), + "dect": threading.Thread(target=self._dect.run) if self.config.dect.enabled == True else None, "routing": threading.Thread(target=self._routing.run), - "ywsd": threading.Thread(target=self._ywsd.run, daemon=True), + "ywsd": threading.Thread(target=self._ywsd.run, daemon=True) if self.config.yate.enabled == True else None, } # Set thread names for name, thread in self.threads.items(): + if thread is None: + continue thread.name = name def queue_all(self, msg): @@ -79,6 +81,8 @@ class FieldPOC: logger.info("starting threads") for name, thread in self.threads.items(): + if thread is None: + continue thread.start() logger.info("started threads") diff --git a/fieldpoc_config.json b/fieldpoc_config.json index 1ee0f2e..82e0840 100644 --- a/fieldpoc_config.json +++ b/fieldpoc_config.json @@ -7,12 +7,14 @@ "port": 9437 }, "dect": { + "enabled": false, "host": "10.222.222.11", "username": "omm", "password": "xxx", "sipsecret": "51df84aace052b0e75b8c1da5a6da9e2" }, "yate": { + "enabled": false, "host": "127.0.0.1", "port": 5039 },