summaryrefslogtreecommitdiff
path: root/src/plugin.py
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2014-12-10 23:12:17 +0100
committermathieui <mathieui@mathieui.net>2014-12-10 23:12:17 +0100
commit003c28e953ccce64523946c3d3d6578c436c9f3e (patch)
tree5138d1c6ecd8923219c43bb8be84b847d2e81914 /src/plugin.py
parent4c7a470dc87686b724d9cfd67b6cb365156021ce (diff)
downloadpoezio-003c28e953ccce64523946c3d3d6578c436c9f3e.tar.gz
poezio-003c28e953ccce64523946c3d3d6578c436c9f3e.tar.bz2
poezio-003c28e953ccce64523946c3d3d6578c436c9f3e.tar.xz
poezio-003c28e953ccce64523946c3d3d6578c436c9f3e.zip
Allow the plugins to use a default configuration too
through overloading the class variable default_config. also fix a bug that would add meaningless sections to plugin configurations.
Diffstat (limited to 'src/plugin.py')
-rw-r--r--src/plugin.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/plugin.py b/src/plugin.py
index eb2a89e3..5c4a5572 100644
--- a/src/plugin.py
+++ b/src/plugin.py
@@ -19,12 +19,12 @@ class PluginConfig(config.Config):
They are accessible inside the plugin with self.config
and behave like the core Config object.
"""
- def __init__(self, filename, module_name):
- config.Config.__init__(self, filename)
+ def __init__(self, filename, module_name, default=None):
+ config.Config.__init__(self, filename, default=default)
self.module_name = module_name
self.read()
- def get(self, option, default, section=None):
+ def get(self, option, default=None, section=None):
if not section:
section = self.module_name
return config.Config.get(self, option, default, section)
@@ -364,12 +364,19 @@ class BasePlugin(object, metaclass=SafetyMetaclass):
Class that all plugins derive from.
"""
+ default_config = None
+
def __init__(self, plugin_api, core, plugins_conf_dir):
self.core = core
# More hack; luckily we'll never have more than one core object
SafetyMetaclass.core = core
conf = os.path.join(plugins_conf_dir, self.__module__+'.cfg')
- self.config = PluginConfig(conf, self.__module__)
+ try:
+ self.config = PluginConfig(conf, self.__module__,
+ default=self.default_config)
+ except Exception:
+ log.debug('Error while creating the plugin config', exc_info=True)
+ self.config = PluginConfig(conf, self.__module__)
self._api = plugin_api[self.name]
self.init()