-
Notifications
You must be signed in to change notification settings - Fork 10
Description
At the moment the emonhub.conf configuration editor is a simple text file editor:
It would be really nice to have a web ui version of the editor to make configuration easier to edit.
The configuration format used is python ConfigObj. There is no php parser of the configobj format. Eemoncms could load the config file via a socket request, MQTT or redis key made available by emonhub.
The configuration would be shared as a JSON object and changes transposed back into the original confobj object in emonhub when edits are made.
Basic example of reading from ConfigObj file, changing the apikey and writing the change back to the original file:
from configobj import ConfigObj
settings = ConfigObj("emonhub.conf", file_error=True)
settings["interfacers"]["emoncmsorg"]["runtimesettings"]["apikey"] = "test"
settings.write()
If the settings are transfered to emoncms as a json object, the json changes need to be merged with the original settings in the configobj class, preserving orignal comments, ordering, spacing and indentation:
import json
from configobj import ConfigObj
# 1. Load config object
# settings is more than a dict of the contents, it is an instance of the configobj class
settings = ConfigObj("emonhub.conf", file_error=True)
# 2. Translate configuration into json object and reload back to python dict
# json string could be sent or requested by emoncms at this point
jsonstr = json.dumps(settings)
# json string could be sent back to emonhub at this point
jsonsettings = json.loads(jsonstr)
# 3. Update apikey in dict
jsonsettings["interfacers"]["emoncmsorg"]["runtimesettings"]["apikey"] = "anther"
# 4. Merge dict with original configobj class
settings.merge(jsonsettings)
# 5. Save to conf file
settings.write()
