Enable passing user config values as dictionary

parent 3f0113f8
...@@ -22,9 +22,12 @@ logger = logging.getLogger(__name__) ...@@ -22,9 +22,12 @@ logger = logging.getLogger(__name__)
class Api: class Api:
"""Public interface of module""" """Public interface of module"""
def __init__(self, conf=None): def __init__(self, conffile=None, confdict=None):
if conf: # override default config # override default config
config.load_config(conf) if conffile:
elif confdict:
plugin_dir = config.get('settings', 'plugin_dir') plugin_dir = config.get('settings', 'plugin_dir')
volatile_dir = config.get('settings', 'volatile_dir') volatile_dir = config.get('settings', 'volatile_dir')
...@@ -16,7 +16,7 @@ class Config: ...@@ -16,7 +16,7 @@ class Config:
self.conf.set("settings", "plugin_dir", "plugins") self.conf.set("settings", "plugin_dir", "plugins")
self.conf.set("settings", "cmd_timeout", "10") self.conf.set("settings", "cmd_timeout", "10")
def load_config(self, filename): def load_from_file(self, filename):
try: try:
with open(filename, 'r') as f: with open(filename, 'r') as f:
self.conf.read_file(f) self.conf.read_file(f)
...@@ -24,6 +24,9 @@ class Config: ...@@ -24,6 +24,9 @@ class Config:
logger.warning("Failed to open config file '{}'".format(filename)) logger.warning("Failed to open config file '{}'".format(filename))
# TODO: handle configparser exceptions # TODO: handle configparser exceptions
def load_from_dict(self, dictionary):
def get(self, section, key): def get(self, section, key):
return self.conf.get(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