switch to json to avoid external dependency
This commit is contained in:
parent
f81e53e455
commit
2b7d6738f1
@ -2,7 +2,7 @@ from owrx.property import PropertyManager, PropertyLayer
|
|||||||
import importlib.util
|
import importlib.util
|
||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
import yaml
|
import json
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -36,21 +36,21 @@ class Config:
|
|||||||
return pm
|
return pm
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _loadYamlFile(file):
|
def _loadJsonFile(file):
|
||||||
with open(file, "r") as f:
|
with open(file, "r") as f:
|
||||||
pm = PropertyLayer()
|
pm = PropertyLayer()
|
||||||
for k, v in yaml.load(f).items():
|
for k, v in json.load(f).items():
|
||||||
pm[k] = v
|
pm[k] = v
|
||||||
return pm
|
return pm
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _loadConfig():
|
def _loadConfig():
|
||||||
for file in ["settings.yaml", "/etc/openwebrx/config_webrx.py", "./config_webrx.py"]:
|
for file in ["settings.json", "/etc/openwebrx/config_webrx.py", "./config_webrx.py"]:
|
||||||
try:
|
try:
|
||||||
if file.endswith(".py"):
|
if file.endswith(".py"):
|
||||||
return Config._loadPythonFile(file)
|
return Config._loadPythonFile(file)
|
||||||
elif file.endswith(".yaml"):
|
elif file.endswith(".json"):
|
||||||
return Config._loadYamlFile(file)
|
return Config._loadJsonFile(file)
|
||||||
else:
|
else:
|
||||||
logger.warning("unsupported file type: %s", file)
|
logger.warning("unsupported file type: %s", file)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
@ -65,8 +65,8 @@ class Config:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def store():
|
def store():
|
||||||
with open("settings.yaml", "w") as file:
|
with open("settings.json", "w") as file:
|
||||||
yaml.dump(Config.get().__dict__(), file)
|
json.dump(Config.get().__dict__(), file, indent=4)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def validateConfig():
|
def validateConfig():
|
||||||
|
Loading…
Reference in New Issue
Block a user