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