Use importlib to import providers and plugins

This commit is contained in:
Anders Ingemann 2014-04-08 21:25:39 +02:00
parent 1e14a9105a
commit 8ded026f5b
2 changed files with 4 additions and 3 deletions

View file

@ -44,7 +44,8 @@ class Manifest(object):
provider_modname = 'bootstrapvz.providers.{provider}'.format(provider=self.data['provider'])
log.debug('Loading provider `{modname}\''.format(modname=provider_modname))
# Create a modules dict that contains the loaded provider and plugins
self.modules = {'provider': __import__(provider_modname, fromlist=['providers']),
import importlib
self.modules = {'provider': importlib.import_module(provider_modname),
'plugins': [],
}
# Run through all the plugins mentioned in the manifest and load them
@ -52,7 +53,7 @@ class Manifest(object):
for plugin_name, plugin_data in self.data['plugins'].iteritems():
modname = 'bootstrapvz.plugins.{plugin}'.format(plugin=plugin_name)
log.debug('Loading plugin `{modname}\''.format(modname=modname))
plugin = __import__(modname, fromlist=['plugins'])
plugin = importlib.import_module(modname)
self.modules['plugins'].append(plugin)
# Run the initialize function on the provider and plugins

View file

@ -30,7 +30,7 @@ class TaskList(object):
# Call 'function' on the provider
getattr(manifest.modules['provider'], function)(self.tasks, manifest, *args)
for plugin in manifest.modules['plugins']:
# Plugins har not required to have whatever function we call
# Plugins are not required to have whatever function we call
fn = getattr(plugin, function, None)
if callable(fn):
fn(self.tasks, manifest, *args)