Since PluginRegistry is a borg we can easily track if we have been loaded before and if so, not load plugins again.

This commit is contained in:
Chris Jones 2009-12-17 23:16:42 +00:00
parent 01bb454d90
commit 603da6ec16
1 changed files with 9 additions and 0 deletions

View File

@ -36,6 +36,7 @@ class PluginRegistry(borg.Borg):
"""Definition of a class to store plugin instances"""
instances = None
path = None
done = None
def __init__(self):
"""Class initialiser"""
@ -51,9 +52,15 @@ class PluginRegistry(borg.Borg):
self.path = os.path.join(head, 'plugins')
dbg('PluginRegistry::prepare_attributes: Plugin path: %s' %
self.path)
if not self.done:
self.done = False
def load_plugins(self):
"""Load all plugins present in the plugins/ directory in our module"""
if self.done:
dbg('PluginRegistry::load_plugins: Already loaded')
return
sys.path.insert(0, self.path)
files = os.listdir(self.path)
for plugin in files:
@ -71,6 +78,8 @@ class PluginRegistry(borg.Borg):
err('PluginRegistry::load_plugins: Importing plugin %s \
failed: %s' % (plugin, e))
self.done = True
def get_plugins_by_capability(self, capability):
"""Return a list of plugins with a particular capability"""
result = []