break config module apart
This commit is contained in:
36
owrx/config/migration.py
Normal file
36
owrx/config/migration.py
Normal file
@@ -0,0 +1,36 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
|
||||
class ConfigMigrator(ABC):
|
||||
@abstractmethod
|
||||
def migrate(self, config):
|
||||
pass
|
||||
|
||||
def renameKey(self, config, old, new):
|
||||
if old in config and new not in config:
|
||||
config[new] = config[old]
|
||||
del config[old]
|
||||
|
||||
|
||||
class ConfigMigratorVersion1(ConfigMigrator):
|
||||
def migrate(self, config):
|
||||
if "receiver_gps" in config:
|
||||
gps = config["receiver_gps"]
|
||||
config["receiver_gps"] = {"lat": gps[0], "lon": gps[1]}
|
||||
|
||||
if "waterfall_auto_level_margin" in config:
|
||||
levels = config["waterfall_auto_level_margin"]
|
||||
config["waterfall_auto_level_margin"] = {"min": levels[0], "max": levels[1]}
|
||||
|
||||
self.renameKey(config, "wsjt_queue_workers", "decoding_queue_workers")
|
||||
self.renameKey(config, "wsjt_queue_length", "decoding_queue_length")
|
||||
|
||||
config["version"] = 2
|
||||
return config
|
||||
|
||||
|
||||
class ConfigMigratorVersion2(ConfigMigrator):
|
||||
def migrate(self, config):
|
||||
if "waterfall_colors" in config and any(v > 0xFFFFFF for v in config["waterfall_colors"]):
|
||||
config["waterfall_colors"] = [v >> 8 for v in config["waterfall_colors"]]
|
||||
return config
|
||||
Reference in New Issue
Block a user