def load(self): """Load plugins from config file. """ # If plugins have been loaded then return if self.loaded == True: return plugin_list = load_plugin_config() for plugin in plugin_list: plugin_lower = plugin.lower() try: # We attempt to do the following. # 1. Load the module of the plugin. # 2. Instantiate an object of the plugin's class. # 3. Add the plugin to the list of plugins. # # #3 should only happen if #2 doesn't throw an error this_module = import_module('elodie.plugins.{}.{}'.format( plugin_lower, plugin_lower)) self.classes[plugin] = getattr(this_module, plugin)() # We only append to self.plugins if we're able to load the class self.plugins.append(plugin) except: log.error( 'An error occurred initiating plugin {}'.format(plugin)) log.error(format_exc()) self.loaded = True
def test_load_plugin_config_exists_not_set(): with open('%s/config.ini-load-plugin-config-exists-not-set' % gettempdir(), 'w') as f: f.write(""" [Plugins] """) if hasattr(load_config, 'config'): del load_config.config plugins = load_plugin_config() if hasattr(load_config, 'config'): del load_config.config assert plugins == [], plugins
def test_load_plugin_config_unset_backwards_compat(): with open( '%s/config.ini-load-plugin-config-unset-backwards-compat' % gettempdir(), 'w') as f: f.write(""" """) if hasattr(load_config, 'config'): del load_config.config plugins = load_plugin_config() if hasattr(load_config, 'config'): del load_config.config assert plugins == [], plugins
def test_load_plugin_config_one_with_invalid(): with open('%s/config.ini-load-plugin-config-one' % gettempdir(), 'w') as f: f.write(""" [Plugins] plugins=DNE """) if hasattr(load_config, 'config'): del load_config.config plugins = load_plugin_config() if hasattr(load_config, 'config'): del load_config.config assert plugins == [], plugins
def test_load_plugin_config_many(): with open('%s/config.ini-load-plugin-config-many' % gettempdir(), 'w') as f: f.write(""" [Plugins] plugins=GooglePhotos,Dummy """) if hasattr(load_config, 'config'): del load_config.config plugins = load_plugin_config() if hasattr(load_config, 'config'): del load_config.config assert plugins == ['GooglePhotos', 'Dummy'], plugins