implement config layering
This commit is contained in:
30
owrx/config/classic.py
Normal file
30
owrx/config/classic.py
Normal file
@@ -0,0 +1,30 @@
|
||||
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
|
||||
|
||||
@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)
|
||||
pm = PropertyLayer()
|
||||
for name, value in cfg.__dict__.items():
|
||||
if name.startswith("__"):
|
||||
continue
|
||||
pm[name] = value
|
||||
return pm
|
||||
Reference in New Issue
Block a user