jsonify the config object
This commit is contained in:
parent
21a524743c
commit
27fea36e48
2 changed files with 11 additions and 1 deletions
|
@ -198,4 +198,5 @@ class RelayConfig(DotDict):
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
with open(self._path, "w") as fd:
|
with open(self._path, "w") as fd:
|
||||||
yaml.dump(self, fd, sort_keys=False)
|
fd.write("---\n")
|
||||||
|
yaml.dump(self.jsonify(), fd, sort_keys=True)
|
||||||
|
|
|
@ -328,6 +328,15 @@ class DotDict(dict):
|
||||||
def to_json(self, indent=None):
|
def to_json(self, indent=None):
|
||||||
return json.dumps(self, indent=indent)
|
return json.dumps(self, indent=indent)
|
||||||
|
|
||||||
|
def jsonify(self):
|
||||||
|
def _xform(v):
|
||||||
|
if hasattr(v, 'jsonify'):
|
||||||
|
return v.jsonify()
|
||||||
|
else:
|
||||||
|
return v
|
||||||
|
|
||||||
|
return {k: _xform(v) for k, v in self.items()}
|
||||||
|
|
||||||
def update(self, _data, **kwargs):
|
def update(self, _data, **kwargs):
|
||||||
if isinstance(_data, dict):
|
if isinstance(_data, dict):
|
||||||
for key, value in _data.items():
|
for key, value in _data.items():
|
||||||
|
|
Loading…
Reference in a new issue