openwebrx-clone/owrx/config/__init__.py

40 lines
1.0 KiB
Python
Raw Normal View History

2021-02-11 18:31:44 +00:00
from owrx.property import PropertyStack
from owrx.config.error import ConfigError
from owrx.config.defaults import defaultConfig
from owrx.config.dynamic import DynamicConfig
from owrx.config.classic import ClassicConfig
2020-03-29 16:08:26 +00:00
2021-02-11 18:31:44 +00:00
class Config(PropertyStack):
sharedConfig = None
2019-05-09 20:44:29 +00:00
2021-02-11 18:31:44 +00:00
def __init__(self):
super().__init__()
self.storableConfig = DynamicConfig()
layers = [
self.storableConfig,
ClassicConfig(),
defaultConfig,
]
for i, l in enumerate(layers):
self.addLayer(i, l)
@staticmethod
def get():
if Config.sharedConfig is None:
2021-02-11 18:31:44 +00:00
Config.sharedConfig = Config()
return Config.sharedConfig
2021-02-11 18:31:44 +00:00
def store(self):
self.storableConfig.store()
@staticmethod
def validateConfig():
2021-02-06 21:08:27 +00:00
# no config checks atm
# just basic loading verification
Config.get()
2020-03-29 16:08:26 +00:00
2021-02-11 18:31:44 +00:00
def __setitem__(self, key, value):
# in the config, all writes go to the json layer
return self.storableConfig.__setitem__(key, value)