def _GetPluginObj(self, plugin_obj, *args, **kwargs): if isinstance(plugin_obj, basestring): plugin_name = plugin_obj elif utils.issubclass(plugin_obj, plugin.Command): plugin_name = plugin_obj.name plugin_cls = plugin_obj elif isinstance(plugin_obj, plugin.Command): return plugin_obj else: raise TypeError( "First parameter should be a plugin name or instance.") # When passed as a string this specifies a plugin name. if isinstance(plugin_obj, basestring): plugin_cls = getattr(self.plugins, plugin_obj, None) if plugin_cls is None: self.logging.error( "Plugin %s is not active. Is it supported with " "this profile?", plugin_name) return # Instantiate the plugin object. kwargs["session"] = self return plugin_cls(*args, **kwargs)
def _GetPluginName(self, plugin_obj): """Extract the name from the plugin object.""" if isinstance(plugin_obj, basestring): return plugin_obj elif utils.issubclass(plugin_obj, plugin.Command): return plugin_obj.name elif isinstance(plugin_obj, plugin.Command): return plugin_obj.name