def testCandidatesManipulation(self): """ Test querying, removing and adding plugins from/to the lkist of plugins to load. """ spm = PluginManager(directories_list=[ os.path.join( os.path.dirname(os.path.abspath(__file__)),"plugins")]) # locate the plugins that should be loaded spm.locatePlugins() # check nb of candidatesx self.assertEqual(len(spm.getPluginCandidates()),1) # get the description of the plugin candidate candidate = spm.getPluginCandidates()[0] self.assertTrue(isinstance(candidate,tuple)) # try removing the candidate spm.removePluginCandidate(candidate) self.assertEqual(len(spm.getPluginCandidates()),0) # try re-adding it spm.appendPluginCandidate(candidate) self.assertEqual(len(spm.getPluginCandidates()),1)
def testCandidatesManipulation(self): """ Test querying, removing and adding plugins from/to the lkist of plugins to load. """ spm = PluginManager(directories_list=[ os.path.join(os.path.dirname(os.path.abspath(__file__)), "plugins") ]) # locate the plugins that should be loaded spm.locatePlugins() # check nb of candidatesx self.assertEqual(len(spm.getPluginCandidates()), 1) # get the description of the plugin candidate candidate = spm.getPluginCandidates()[0] self.assertTrue(isinstance(candidate, tuple)) # try removing the candidate spm.removePluginCandidate(candidate) self.assertEqual(len(spm.getPluginCandidates()), 0) # try re-adding it spm.appendPluginCandidate(candidate) self.assertEqual(len(spm.getPluginCandidates()), 1)
def testEnforcingPluginDirsDoesNotKeepDefaultDir(self): """ Test that providing the directories list override the default search directory instead of extending the default list. """ class AcceptAllPluginFileAnalyzer(IPluginFileAnalyzer): def __init__(self): IPluginFileAnalyzer.__init__(self, "AcceptAll") def isValidPlugin(self, filename): return True def getInfosDictFromPlugin(self, dirpath, filename): return {"name": filename, "path": dirpath}, ConfigParser() pluginLocator = PluginFileLocator() pluginLocator.setAnalyzers([AcceptAllPluginFileAnalyzer()]) spm_default_dirs = PluginManager(plugin_locator=pluginLocator) spm_default_dirs.locatePlugins() candidates_in_default_dir = spm_default_dirs.getPluginCandidates() candidates_files_in_default_dir = set( [c[0] for c in candidates_in_default_dir]) pluginLocator = PluginFileLocator() pluginLocator.setAnalyzers([AcceptAllPluginFileAnalyzer()]) spm = PluginManager(plugin_locator=pluginLocator, directories_list=[ os.path.dirname(os.path.abspath(__file__)), "does-not-exists" ]) spm.locatePlugins() candidates = spm.getPluginCandidates() candidates_files = set([c[0] for c in candidates]) self.assertFalse( set(candidates_files_in_default_dir).issubset( set(candidates_files)))
def load_plugins(): """Loads plugins from the puglins folder""" plugins = PluginManager() plugins_folder = os.path.join(os.environ['LOOKDEVTOOLS'], 'python', 'ldtplugins') print plugins_folder plugins.setPluginPlaces([plugins_folder]) plugins.collectPlugins() plugins.locatePlugins() logger.info('Plugin candidates %s' % plugins.getPluginCandidates()) for pluginInfo in plugins.getAllPlugins(): plugins.activatePluginByName(pluginInfo.name) logger.info('Plugin activated %s' % plugins.activatePluginByName(pluginInfo.name)) return plugins
def load_plugins(): """ Load plugin for environment. See lib/base.py """ # Create plugin manager manager = PluginManager() # Tell it the default place(s) where to find plugins manager.setPluginPlaces(["pylons_yapsy_plugin/plugins/"]) # Define the various categories corresponding to the different # kinds of plugins you have defined manager.setCategoriesFilter({ "Menu" : menu.Menu, "Inline" : inline.Inline, }) manager.locatePlugins() # Deactivate plugin # Список деактивированных плагинов из БД deactivatedPlugins = [plugin.name for plugin in\ s.query(DeactivatedPlugins).all()] # Список кандидатов на загрузку candidates = manager.getPluginCandidates() # Список деактивированных плагинов в формате yapsy deactivatedList = [] for candidate in candidates: if candidate[2].name in deactivatedPlugins: deactivatedList.append(candidate) # Исключаем плагины которые указанны в БД for plugin in deactivatedList: manager.removePluginCandidate(plugin) # Load plugins manager.loadPlugins() return manager, [plugin[2] for plugin in deactivatedList]