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):
|
2020-03-21 21:40:39 +00:00
|
|
|
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)
|
2020-03-15 22:32:19 +00:00
|
|
|
|
2020-03-21 21:40:39 +00:00
|
|
|
@staticmethod
|
|
|
|
def get():
|
|
|
|
if Config.sharedConfig is None:
|
2021-02-11 18:31:44 +00:00
|
|
|
Config.sharedConfig = Config()
|
2020-03-21 21:40:39 +00:00
|
|
|
return Config.sharedConfig
|
2020-03-15 22:32:19 +00:00
|
|
|
|
2021-02-11 18:31:44 +00:00
|
|
|
def store(self):
|
|
|
|
self.storableConfig.store()
|
2020-03-27 22:44:03 +00:00
|
|
|
|
2020-03-15 22:32:19 +00:00
|
|
|
@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)
|