Add infrastructure for managing configuration
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()
|
@ -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
|
#!/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():
|
def run():
|
||||||
threading.Thread(target=dect.run).start()
|
args = ap.parse_args()
|
||||||
|
fp = fieldpoc.FieldPOC(**args.__dict__)
|
||||||
|
fp.run()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
run()
|
run()
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"dect": {
|
||||||
|
"host": "192.168.0.100",
|
||||||
|
"username": "omm",
|
||||||
|
"password": "xxx"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1 @@
|
|||||||
|
{}
|
Loading…
Reference in New Issue