You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.3 KiB
Python
62 lines
1.3 KiB
Python
#!/usr/bin/env python3
|
|
|
|
class ConfigBase:
|
|
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()
|
|
|
|
|
|
class ControllerConfig(ConfigBase):
|
|
def __init__(self, c):
|
|
self._c = c
|
|
|
|
class DatabaseConfig(ConfigBase):
|
|
pass
|
|
|
|
|
|
class DectConfig(ConfigBase):
|
|
def __init__(self, c):
|
|
self._c = c
|
|
|
|
def check(self):
|
|
return True
|
|
|
|
class YateConfig(ConfigBase):
|
|
pass
|
|
|
|
|
|
class Config:
|
|
def __init__(self, c):
|
|
self._c = c
|
|
self.controller = ControllerConfig(c.get("controller", {}))
|
|
self.database = DatabaseConfig(c.get("database", {}))
|
|
self.dect = DectConfig(c.get("dect", {}))
|
|
self.yate = YateConfig(c.get("yate", {}))
|
|
|
|
def check(self):
|
|
return self.dect.check()
|
|
|
|
|
|
class ExtensionConfig(ConfigBase):
|
|
def __init__(self, c):
|
|
self.num = c[0]
|
|
self._c = c[1]
|
|
|
|
|
|
class Extensions:
|
|
def __init__(self, c):
|
|
self._c = c
|
|
self.extensions = []
|
|
for e in self._c.get("extensions", {}).items():
|
|
self.extensions.append(ExtensionConfig(e))
|
|
|
|
def extensions_by_type(self, t):
|
|
for e in self.extensions:
|
|
if e.type == t:
|
|
yield e
|