Add infrastructure for managing configuration

main
clerie 2 years ago
parent e5e256039c
commit 027e4b3a7f

@ -0,0 +1,22 @@
#!/usr/bin/env python3
class DectConfig:
def __init__(self, c):
self._c = c
def __getattr__(self, name):
if name in self._c.keys():
return self._c.get(name)
else:
raise AttributeError()
def check(self):
return True
class Config:
def __init__(self, c):
self._c = c
self.dect = DectConfig(c.get("dect", {}))
def check(self):
return self.dect.check()

@ -3,7 +3,22 @@
import mitel_ommclient2
import time
def run():
class Dect:
def __init__(self, fp):
self.fp = fp
def _init_client(self):
self.c = mitel_ommclient2.OMMClient2(
host=self.fp.config.dect.host,
username=self.fp.config.dect.username,
password=self.fp.config.dect.password,
ommsync=True,
)
def run(self):
self._init_client()
while True:
print("meow")
print(self.c.ping())
time.sleep(2)

@ -0,0 +1,30 @@
#!/usr/bin/env python3
import json
import pathlib
import threading
from . import config
from . import dect
class FieldPOC:
config = None
extensions = None
def __init__(self, config_file_path, extensions_file_path):
self.config_file_path = pathlib.Path(config_file_path)
self._load_config()
self.extensions_file_path = pathlib.Path(extensions_file_path)
self._load_extensions()
self._dect = dect.Dect(self)
def run(self):
self._dect_thread = threading.Thread(target=self._dect.run)
self._dect_thread.start()
def _load_config(self):
self.config = config.Config(json.loads(self.config_file_path.read_text()))
def _load_extensions(self):
self.extensions = json.loads(self.extensions_file_path.read_text())

@ -1,11 +1,16 @@
#!/usr/bin/env python3
import threading
import argparse
from . import fieldpoc
from . import dect
ap = argparse.ArgumentParser(prog="fieldpoc")
ap.add_argument("-c", "--config", dest="config_file_path", default="fieldpoc_config.json", help="Path to the fieldpoc config file")
ap.add_argument("-e", "--extensions", dest="extensions_file_path", default="fieldpoc_extensions.json", help="Path to the fieldpoc extensions file")
def run():
threading.Thread(target=dect.run).start()
args = ap.parse_args()
fp = fieldpoc.FieldPOC(**args.__dict__)
fp.run()
if __name__ == "__main__":
run()

@ -0,0 +1,7 @@
{
"dect": {
"host": "192.168.0.100",
"username": "omm",
"password": "xxx"
}
}
Loading…
Cancel
Save