Add plugin config API

This commit is contained in:
Chris Jones 2010-01-05 21:44:12 +00:00
parent 14543494d7
commit 299e4cc5a8
1 changed files with 33 additions and 1 deletions

View File

@ -37,6 +37,13 @@ Classes relating to configuration
'click' 'click'
>>> config['fullscreen'].__class__.__name__ >>> config['fullscreen'].__class__.__name__
'bool' 'bool'
>>> plugintest = {}
>>> plugintest['foo'] = 'bar'
>>> config.plugin_set_config('testplugin', plugintest)
>>> config.plugin_get_config('testplugin')
{'foo': 'bar'}
>>> config.plugin_get('testplugin', 'foo')
'bar'
>>> >>>
""" """
@ -220,6 +227,22 @@ class Config(object):
"""Cause ConfigBase to save our config to file""" """Cause ConfigBase to save our config to file"""
return(self.base.save()) return(self.base.save())
def plugin_get(self, pluginname, key):
"""Get a plugin config value"""
return(self.base.get_item(key, plugin=pluginname))
def plugin_set(self, pluginname, key, value):
"""Set a plugin config value"""
return(self.base.set_item(key, value, plugin=pluginname))
def plugin_get_config(self, plugin):
"""Return a whole config tree for a given plugin"""
return(self.base.get_plugin(plugin))
def plugin_set_config(self, plugin, tree):
"""Set a whole config tree for a given plugin"""
return(self.base.set_plugin(plugin, tree))
class ConfigBase(Borg): class ConfigBase(Borg):
"""Class to provide access to our user configuration""" """Class to provide access to our user configuration"""
loaded = None loaded = None
@ -419,13 +442,22 @@ class ConfigBase(Borg):
self.profiles[profile][key] = value self.profiles[profile][key] = value
elif key == 'keybindings': elif key == 'keybindings':
self.keybindings = value self.keybindings = value
elif plugin is not None and self.plugins[plugin].has_key(key): elif plugin is not None:
self.plugins[plugin][key] = value self.plugins[plugin][key] = value
else: else:
raise KeyError('ConfigBase::set_item: unknown key %s' % key) raise KeyError('ConfigBase::set_item: unknown key %s' % key)
return(True) return(True)
def get_plugin(self, plugin):
"""Return a whole tree for a plugin"""
if self.plugins.has_key(plugin):
return(self.plugins[plugin])
def set_plugin(self, plugin, tree):
"""Set a whole tree for a plugin"""
self.plugins[plugin] = tree
if __name__ == '__main__': if __name__ == '__main__':
import sys import sys
import doctest import doctest