2021-02-11 18:31:44 +00:00
|
|
|
from owrx.property import PropertyReadOnly, PropertyLayer
|
|
|
|
from owrx.config.migration import Migrator
|
|
|
|
import importlib.util
|
|
|
|
|
|
|
|
|
|
|
|
class ClassicConfig(PropertyReadOnly):
|
|
|
|
def __init__(self):
|
|
|
|
pm = ClassicConfig._loadConfig()
|
|
|
|
Migrator.migrate(pm)
|
|
|
|
super().__init__(pm)
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _loadConfig():
|
|
|
|
for file in ["/etc/openwebrx/config_webrx.py", "./config_webrx.py"]:
|
|
|
|
try:
|
|
|
|
return ClassicConfig._loadPythonFile(file)
|
|
|
|
except FileNotFoundError:
|
|
|
|
pass
|
|
|
|
|
2021-02-23 22:23:37 +00:00
|
|
|
@staticmethod
|
|
|
|
def _toLayer(dictionary: dict):
|
|
|
|
layer = PropertyLayer()
|
|
|
|
for k, v in dictionary.items():
|
|
|
|
if isinstance(v, dict):
|
|
|
|
layer[k] = ClassicConfig._toLayer(v)
|
|
|
|
else:
|
|
|
|
layer[k] = v
|
|
|
|
return layer
|
|
|
|
|
2021-02-11 18:31:44 +00:00
|
|
|
@staticmethod
|
|
|
|
def _loadPythonFile(file):
|
|
|
|
spec = importlib.util.spec_from_file_location("config_webrx", file)
|
|
|
|
cfg = importlib.util.module_from_spec(spec)
|
|
|
|
spec.loader.exec_module(cfg)
|
2021-02-23 22:23:37 +00:00
|
|
|
return ClassicConfig._toLayer({k: v for k, v in cfg.__dict__.items() if not k.startswith("__")})
|