Enable passing user config values as dictionary

parent 3f0113f8
......@@ -22,9 +22,12 @@ logger = logging.getLogger(__name__)
class Api:
"""Public interface of module"""
def __init__(self, conf=None):
if conf: # override default config
config.load_config(conf)
def __init__(self, conffile=None, confdict=None):
# override default config
if conffile:
config.load_from_file(conffile)
elif confdict:
config.load_from_dict(confdict)
plugin_dir = config.get('settings', 'plugin_dir')
volatile_dir = config.get('settings', 'volatile_dir')
......
......@@ -16,7 +16,7 @@ class Config:
self.conf.set("settings", "plugin_dir", "plugins")
self.conf.set("settings", "cmd_timeout", "10")
def load_config(self, filename):
def load_from_file(self, filename):
try:
with open(filename, 'r') as f:
self.conf.read_file(f)
......@@ -24,6 +24,9 @@ class Config:
logger.warning("Failed to open config file '{}'".format(filename))
# TODO: handle configparser exceptions
def load_from_dict(self, dictionary):
self.conf.read_dict(dictionary)
def get(self, section, key):
return self.conf.get(section, key)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment