#NEWLINE# def load( self , plugins ) : #NEWLINE# #INDENT# "Takes either a plugin name or a list of plugins and loads them.\n\n        This involves attempting to import the plugin's module, import the\n        plugin's config module, instance the plugin's object, and finding its\n        commands and events.\n\n        Keyword arguments:\n          plugins -- This can be either a single or list of plugin names.\n\n        Returns:\n          list -- A list of failed plugins, or an empty list.\n\n        Raises:\n          TypeError -- When the `plugins` argument is not a string or list.\n\n        " #NEWLINE# if isinstance ( plugins , basestring ) : #NEWLINE# #INDENT# plugins = [ plugins . encode ( 'utf-8' ) ] #NEWLINE# #UNINDENT# if ( not isinstance ( plugins , list ) ) : #NEWLINE# #INDENT# raise TypeError ( 'Plugins argument must be a string or list of plugins' ) #NEWLINE# #UNINDENT# failed_plugins = [ ] #NEWLINE# for plugin in plugins : #NEWLINE# #INDENT# reload_flag = False #NEWLINE# self . logger . info ( ( 'Attempting to load plugin: %s' % plugin ) ) #NEWLINE# try : #NEWLINE# #INDENT# if ( plugin in self . plugins . keys ( ) ) : #NEWLINE# #INDENT# self . logger . info ( ( 'Already loaded, reloading: %s' % plugin ) ) #NEWLINE# reload_flag = True #NEWLINE# try : #NEWLINE# #INDENT# self . _close_plugin_instance ( plugin ) #NEWLINE# #UNINDENT# except Exception : #NEWLINE# #INDENT# self . logger . exception ( ( "Didn't close plugin cleanly: %s" % plugin ) ) #NEWLINE# #UNINDENT# module_to_import = self . plugins [ plugin ] [ 'module' ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# module_to_import = plugin #NEWLINE# #UNINDENT# module = self . _import_module ( plugins ) #NEWLINE# #UNINDENT# except Exception : #NEWLINE# #INDENT# self . logger . exception ( ( 'Could not load plugin module: %s' % plugin ) ) #NEWLINE# failed_plugins . append ( plugin ) #NEWLINE# continue #NEWLINE# #UNINDENT# config = None #NEWLINE# try : #NEWLINE# #INDENT# config = self . _load_plugin_config ( plugin ) #NEWLINE# #UNINDENT# except AmbiguousConfigError : #NEWLINE# #INDENT# self . logger . exception ( ( 'Could not load plugin: %s' % plugin ) ) #NEWLINE# failed_plugins . append ( plugin ) #NEWLINE# continue #NEWLINE# #UNINDENT# except ConfigNotFoundError : #NEWLINE# #INDENT# self . logger . debug ( ( 'No config found for plugin: %s' % plugin ) ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# instance = self . _create_plugin_instance ( module , config ) #NEWLINE# #UNINDENT# except Exception : #NEWLINE# #INDENT# self . logger . exception ( ( 'Could not instantiate plugin: %s' % plugin ) ) #NEWLINE# failed_plugins . append ( plugin ) #NEWLINE# continue #NEWLINE# #UNINDENT# commands = self . _get_plugin_commands ( instance ) #NEWLINE# callbacks = self . _get_plugin_callbacks ( instance ) #NEWLINE# try : #NEWLINE# #INDENT# callback_ids = self . _register_plugin_callbacks ( callbacks ) #NEWLINE# #UNINDENT# except Exception : #NEWLINE# #INDENT# self . logger . exception ( ( 'Could not register events for plugin: %s' % plugin ) ) #NEWLINE# failed_plugins . append ( plugin ) #NEWLINE# continue #NEWLINE# #UNINDENT# if ( plugin in self . plugins ) : #NEWLINE# #INDENT# self . unload ( plugin ) #NEWLINE# #UNINDENT# self . plugins [ plugin ] = { #NEWLINE# #INDENT# 'name' : plugin , #NEWLINE# 'module' : module , #NEWLINE# 'instance' : instance , #NEWLINE# 'commands' : commands , #NEWLINE# 'callbacks' : callbacks , #NEWLINE# 'callback_ids' : callback_ids , #NEWLINE# 'config' : config , #NEWLINE# 'blacklist' : [ ] , #NEWLINE# #UNINDENT# } #NEWLINE# if reload_flag : #NEWLINE# #INDENT# self . cardinal . reloads += 1 #NEWLINE# #UNINDENT# self . logger . info ( ( 'Plugin %s successfully loaded' % plugin ) ) #NEWLINE# #UNINDENT# return failed_plugins