use hierarchical property layers to make config changes effective
immediately
This commit is contained in:
@ -17,14 +17,19 @@ class ClassicConfig(PropertyReadOnly):
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
|
||||
@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
|
||||
|
||||
@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
|
||||
return ClassicConfig._toLayer({k: v for k, v in cfg.__dict__.items() if not k.startswith("__")})
|
||||
|
@ -8,7 +8,7 @@ defaultConfig = PropertyLayer(
|
||||
receiver_location="Budapest, Hungary",
|
||||
receiver_asl=200,
|
||||
receiver_admin="example@example.com",
|
||||
receiver_gps={"lat": 47.0, "lon": 19.0},
|
||||
receiver_gps=PropertyLayer(lat=47.0, lon=19.0),
|
||||
photo_title="Panorama of Budapest from Schönherz Zoltán Dormitory",
|
||||
photo_desc="",
|
||||
fft_fps=9,
|
||||
@ -25,7 +25,7 @@ defaultConfig = PropertyLayer(
|
||||
waterfall_scheme="GoogleTurboWaterfall",
|
||||
waterfall_min_level=-88,
|
||||
waterfall_max_level=-20,
|
||||
waterfall_auto_level_margin={"min": 3, "max": 10, "min_range": 50},
|
||||
waterfall_auto_level_margin=PropertyLayer(min=3, max=10, min_range=50),
|
||||
frequency_display_precision=4,
|
||||
squelch_auto_margin=10,
|
||||
nmux_memory=50,
|
||||
@ -34,7 +34,7 @@ defaultConfig = PropertyLayer(
|
||||
decoding_queue_workers=2,
|
||||
decoding_queue_length=10,
|
||||
wsjt_decoding_depth=3,
|
||||
wsjt_decoding_depths={"jt65": 1},
|
||||
wsjt_decoding_depths=PropertyLayer(jt65=1),
|
||||
fst4_enabled_intervals=[15, 30],
|
||||
fst4w_enabled_intervals=[120, 300],
|
||||
q65_enabled_combinations=["A30", "E120", "C60"],
|
||||
|
@ -1,6 +1,7 @@
|
||||
from owrx.config.core import CoreConfig
|
||||
from owrx.config.migration import Migrator
|
||||
from owrx.property import PropertyLayer
|
||||
from owrx.jsons import Encoder
|
||||
import json
|
||||
|
||||
|
||||
@ -10,11 +11,24 @@ class DynamicConfig(PropertyLayer):
|
||||
try:
|
||||
with open(DynamicConfig._getSettingsFile(), "r") as f:
|
||||
for k, v in json.load(f).items():
|
||||
self[k] = v
|
||||
if isinstance(v, dict):
|
||||
self[k] = DynamicConfig._toLayer(v)
|
||||
else:
|
||||
self[k] = v
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
Migrator.migrate(self)
|
||||
|
||||
@staticmethod
|
||||
def _toLayer(dictionary: dict):
|
||||
layer = PropertyLayer()
|
||||
for k, v in dictionary.items():
|
||||
if isinstance(v, dict):
|
||||
layer[k] = DynamicConfig._toLayer(v)
|
||||
else:
|
||||
layer[k] = v
|
||||
return layer
|
||||
|
||||
@staticmethod
|
||||
def _getSettingsFile():
|
||||
coreConfig = CoreConfig()
|
||||
@ -22,6 +36,6 @@ class DynamicConfig(PropertyLayer):
|
||||
|
||||
def store(self):
|
||||
# don't write directly to file to avoid corruption on exceptions
|
||||
jsonContent = json.dumps(self.__dict__(), indent=4)
|
||||
jsonContent = json.dumps(self.__dict__(), indent=4, cls=Encoder)
|
||||
with open(DynamicConfig._getSettingsFile(), "w") as file:
|
||||
file.write(jsonContent)
|
||||
|
Reference in New Issue
Block a user