openwebrx-clone/owrx/config/__init__.py

44 lines
1.2 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)
2021-02-24 22:04:57 +00:00
def __delitem__(self, key):
# all deletes go to the json layer, too
return self.storableConfig.__delitem__(key)