本文整理汇总了Python中yapsy.PluginManager.PluginManager.getCategories方法的典型用法代码示例。如果您正苦于以下问题:Python PluginManager.getCategories方法的具体用法?Python PluginManager.getCategories怎么用?Python PluginManager.getCategories使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yapsy.PluginManager.PluginManager
的用法示例。
在下文中一共展示了PluginManager.getCategories方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testTwoStepsLoad
# 需要导入模块: from yapsy.PluginManager import PluginManager [as 别名]
# 或者: from yapsy.PluginManager.PluginManager import getCategories [as 别名]
def testTwoStepsLoad(self):
"""
Test loading the plugins in two steps in order to collect more
deltailed informations.
"""
spm = PluginManager(directories_list=[
os.path.join(
os.path.dirname(os.path.abspath(__file__)),"plugins")])
# trigger the first step to look up for plugins
spm.locatePlugins()
# make full use of the "feedback" the loadPlugins can give
# - set-up the callback function that will be called *before*
# loading each plugin
callback_infos = []
def preload_cbk(plugin_info):
callback_infos.append(plugin_info)
# - gather infos about the processed plugins (loaded or not)
loadedPlugins = spm.loadPlugins(callback=preload_cbk)
self.assertEqual(len(loadedPlugins),1)
self.assertEqual(len(callback_infos),1)
self.assertEqual(loadedPlugins[0].error,None)
self.assertEqual(loadedPlugins[0],callback_infos[0])
# check that the getCategories works
self.assertEqual(len(spm.getCategories()),1)
sole_category = spm.getCategories()[0]
# check the getPluginsOfCategory
self.assertEqual(len(spm.getPluginsOfCategory(sole_category)),1)
plugin_info = spm.getPluginsOfCategory(sole_category)[0]
# try to remove it and check that is worked
spm.removePluginFromCategory(plugin_info,sole_category)
self.assertEqual(len(spm.getPluginsOfCategory(sole_category)),0)
# now re-add this plugin the to same category
spm.appendPluginToCategory(plugin_info,sole_category)
self.assertEqual(len(spm.getPluginsOfCategory(sole_category)),1)
示例2: ExtInfoTest
# 需要导入模块: from yapsy.PluginManager import PluginManager [as 别名]
# 或者: from yapsy.PluginManager.PluginManager import getCategories [as 别名]
class ExtInfoTest(unittest.TestCase):
def setUp(self):
# create the plugin manager - use the base plugin manager to
# remove any unecessary dependencies
self.simplePluginManager = PluginManager(directories_list=[
os.path.join(
os.path.dirname(os.path.abspath(__file__)),"Plugins")
],
plugin_info_ext="mm-plugin",
)
#Set mode to test info class
self.simplePluginManager.setPluginInfoClass(ExtensionInfo)
# load the plugins that may be found
self.simplePluginManager.collectPlugins()
# Will be used later
self.plugin_info = None
def loading_check(self):
"""
Test the plugins load.
"""
if self.plugin_info is None:
# check nb of categories
self.assertEqual(len(self.simplePluginManager.getCategories()),1)
sole_category = self.simplePluginManager.getCategories()[0]
# check the number of plugins
self.assertEqual(len(self.simplePluginManager.getPluginsOfCategory(sole_category)),2)
self.plugin_info = [ None , None ]
self.plugin_info[0] = self.simplePluginManager.getPluginsOfCategory(sole_category)[0]
self.plugin_info[1] = self.simplePluginManager.getPluginsOfCategory(sole_category)[1]
# test that the name of the plugin has been correctly defined
self.assertTrue("FirstPlugin" in [x.name for x in self.plugin_info])
self.assertEqual(sole_category,self.plugin_info[0].category)
else:
self.assert_(True)
def testBasic(self):
self.loading_check()
def testKnownHash(self):
"""
Test hash can be fetched thru ExtensionInfo
"""
self.loading_check()
hash1=ExtensionSecureID.fromPathName(self.plugin_info[0].path+".py")
self.assertEquals(hash1,self.plugin_info[0].getSecureID())
self.assertNotEquals(self.plugin_info[0].getSecureID(),self.plugin_info[1].getSecureID())
示例3: testRecursivePluginlocation
# 需要导入模块: from yapsy.PluginManager import PluginManager [as 别名]
# 或者: from yapsy.PluginManager.PluginManager import getCategories [as 别名]
def testRecursivePluginlocation(self):
"""
Test detection of plugins which by default must be
recusrive. Here we give the test directory as a plugin place
whereas we expect the plugins to be in test/plugins.
"""
spm = PluginManager(directories_list=[
os.path.dirname(os.path.abspath(__file__))])
# load the plugins that may be found
spm.collectPlugins()
# check that the getCategories works
self.assertEqual(len(spm.getCategories()),1)
sole_category = spm.getCategories()[0]
# check the getPluginsOfCategory
self.assertEqual(len(spm.getPluginsOfCategory(sole_category)),1)
示例4: testMultipleCategoriesForASamePlugin
# 需要导入模块: from yapsy.PluginManager import PluginManager [as 别名]
# 或者: from yapsy.PluginManager.PluginManager import getCategories [as 别名]
def testMultipleCategoriesForASamePlugin(self):
"""
Test that associating a plugin to multiple categories works as expected.
"""
class AnotherPluginIfce(object):
def __init__(self):
pass
def activate(self):
pass
def deactivate(self):
pass
spm = PluginManager(
categories_filter = {
"Default": IPlugin,
"IP": IPlugin,
"Other": AnotherPluginIfce,
},
directories_list=[
os.path.join(
os.path.dirname(os.path.abspath(__file__)),"plugins")])
# load the plugins that may be found
spm.collectPlugins()
# check that the getCategories works
self.assertEqual(len(spm.getCategories()),3)
categories = spm.getCategories()
self.assertTrue("Default" in categories)
# check the getPluginsOfCategory
self.assertEqual(len(spm.getPluginsOfCategory("Default")), 1)
plugin_info = spm.getPluginsOfCategory("Default")[0]
self.assertTrue("Default" in plugin_info.categories)
self.assertTrue("IP" in plugin_info.categories)
self.assertTrue("IP" in categories)
# check the getPluginsOfCategory
self.assertEqual(len(spm.getPluginsOfCategory("IP")),1)
self.assertTrue("Other" in categories)
# check the getPluginsOfCategory
self.assertEqual(len(spm.getPluginsOfCategory("Other")),0)
# try to remove the plugin from one category and check the
# other category
spm.removePluginFromCategory(plugin_info, "Default")
self.assertEqual(len(spm.getPluginsOfCategory("Default")), 0)
self.assertEqual(len(spm.getPluginsOfCategory("IP")), 1)
# now re-add this plugin the to same category
spm.appendPluginToCategory(plugin_info, "Default")
self.assertEqual(len(spm.getPluginsOfCategory("Default")),1)
self.assertEqual(len(spm.getPluginsOfCategory("IP")),1)
示例5: testTwoStepsLoadWithError
# 需要导入模块: from yapsy.PluginManager import PluginManager [as 别名]
# 或者: from yapsy.PluginManager.PluginManager import getCategories [as 别名]
def testTwoStepsLoadWithError(self):
"""
Test loading the plugins in two steps in order to collect more
deltailed informations and take care of an erroneous plugin.
"""
spm = PluginManager(
directories_list=[os.path.join(os.path.dirname(os.path.abspath(__file__)), "plugins")],
plugin_info_ext="yapsy-error-plugin",
)
# trigger the first step to look up for plugins
spm.locatePlugins()
# make full use of the "feedback" the loadPlugins can give
# - set-up the callback function that will be called *before*
# loading each plugin
callback_infos = []
def preload_cbk(i_plugin_info):
callback_infos.append(i_plugin_info)
# - gather infos about the processed plugins (loaded or not)
# and for the test, monkey patch the logger
originalLogLevel = log.getEffectiveLevel()
log.setLevel(logging.ERROR)
errorLogCallFlag = [False]
def errorMock(*args, **kwargs):
errorLogCallFlag[0] = True
originalErrorMethod = log.error
log.error = errorMock
try:
loadedPlugins = spm.loadPlugins(callback=preload_cbk)
finally:
log.setLevel(originalLogLevel)
log.error = originalErrorMethod
self.assertTrue(errorLogCallFlag[0])
self.assertEqual(len(loadedPlugins), 1)
self.assertEqual(len(callback_infos), 1)
self.assertTrue(isinstance(callback_infos[0].error, tuple))
self.assertEqual(loadedPlugins[0], callback_infos[0])
self.assertEqual(callback_infos[0].error[0], ImportError)
# check that the getCategories works
self.assertEqual(len(spm.getCategories()), 1)
sole_category = spm.getCategories()[0]
# check the getPluginsOfCategory
self.assertEqual(len(spm.getPluginsOfCategory(sole_category)), 0)
示例6: testNonRecursivePluginlocationNotFound
# 需要导入模块: from yapsy.PluginManager import PluginManager [as 别名]
# 或者: from yapsy.PluginManager.PluginManager import getCategories [as 别名]
def testNonRecursivePluginlocationNotFound(self):
"""
Test detection of plugins when the detection is non recursive.
Here we test that it cannot look into subdirectories of the
test directory.
"""
pluginLocator = PluginFileLocator()
pluginLocator.setPluginPlaces([
os.path.dirname(os.path.abspath(__file__))])
pluginLocator.disableRecursiveScan()
spm = PluginManager()
spm.setPluginLocator(pluginLocator)
# load the plugins that may be found
spm.collectPlugins()
# check that the getCategories works
self.assertEqual(len(spm.getCategories()),1)
sole_category = spm.getCategories()[0]
# check the getPluginsOfCategory
self.assertEqual(len(spm.getPluginsOfCategory(sole_category)),0)
示例7: testCategoryManipulation
# 需要导入模块: from yapsy.PluginManager import PluginManager [as 别名]
# 或者: from yapsy.PluginManager.PluginManager import getCategories [as 别名]
def testCategoryManipulation(self):
"""
Test querying, removing and adding plugins from/to a category.
"""
spm = PluginManager(directories_list=[
os.path.join(
os.path.dirname(os.path.abspath(__file__)),"plugins")])
# load the plugins that may be found
spm.collectPlugins()
# check that the getCategories works
self.assertEqual(len(spm.getCategories()),1)
示例8: testDisablingRecursivePluginLocationAllowsFindingTopLevelPlugins
# 需要导入模块: from yapsy.PluginManager import PluginManager [as 别名]
# 或者: from yapsy.PluginManager.PluginManager import getCategories [as 别名]
def testDisablingRecursivePluginLocationAllowsFindingTopLevelPlugins(self):
"""
Test detection of plugins when the detection is non
recursive. Here we test that if we give test/plugin as the
directory to scan it can find the plugin.
"""
pluginLocator = PluginFileLocator()
pluginLocator.setPluginPlaces([
os.path.join(
os.path.dirname(os.path.abspath(__file__)),"plugins")])
pluginLocator.disableRecursiveScan()
spm = PluginManager()
spm.setPluginLocator(pluginLocator)
# load the plugins that may be found
spm.collectPlugins()
# check that the getCategories works
self.assertEqual(len(spm.getCategories()),1)
sole_category = spm.getCategories()[0]
# check the getPluginsOfCategory
self.assertEqual(len(spm.getPluginsOfCategory(sole_category)),1)
示例9: testCategoryManipulation
# 需要导入模块: from yapsy.PluginManager import PluginManager [as 别名]
# 或者: from yapsy.PluginManager.PluginManager import getCategories [as 别名]
def testCategoryManipulation(self):
"""
Test querying, removing and adding plugins from/to a category.
"""
spm = PluginManager(directories_list=[
os.path.join(
os.path.dirname(os.path.abspath(__file__)),"plugins")])
# load the plugins that may be found
spm.collectPlugins()
# check that the getCategories works
self.assertEqual(len(spm.getCategories()),1)
sole_category = spm.getCategories()[0]
# check the getPluginsOfCategory
self.assertEqual(len(spm.getPluginsOfCategory(sole_category)),1)
plugin_info = spm.getPluginsOfCategory(sole_category)[0]
# try to remove it and check that is worked
spm.removePluginFromCategory(plugin_info,sole_category)
self.assertEqual(len(spm.getPluginsOfCategory(sole_category)),0)
# now re-add this plugin the to same category
spm.appendPluginToCategory(plugin_info,sole_category)
self.assertEqual(len(spm.getPluginsOfCategory(sole_category)),1)
示例10: testChangingCategoriesFilter
# 需要导入模块: from yapsy.PluginManager import PluginManager [as 别名]
# 或者: from yapsy.PluginManager.PluginManager import getCategories [as 别名]
def testChangingCategoriesFilter(self):
"""
Test the effect of setting a new category filer.
"""
spm = PluginManager(directories_list=[
os.path.join(
os.path.dirname(os.path.abspath(__file__)),"plugins")])
# load the plugins that may be found
spm.collectPlugins()
newCategory = "Mouf"
# Pre-requisite for the test
previousCategories = spm.getCategories()
self.assertTrue(len(previousCategories) >= 1)
self.assertTrue(newCategory not in previousCategories)
# change the category and see what's happening
spm.setCategoriesFilter({newCategory: IPlugin})
spm.collectPlugins()
for categoryName in previousCategories:
self.assertRaises(KeyError, spm.getPluginsOfCategory, categoryName)
self.assertTrue(len(spm.getPluginsOfCategory(newCategory)) >= 1)
示例11: Config
# 需要导入模块: from yapsy.PluginManager import PluginManager [as 别名]
# 或者: from yapsy.PluginManager.PluginManager import getCategories [as 别名]
#.........这里部分代码省略.........
config_settings.update(settings)
assert config_settings is not None
new_config = Config(config_settings, name)
for index, config in enumerate(cls._configs):
if config.name == name:
logger.warn('Recreating Config named %s', name)
cls._configs[index] = new_config
break
else:
cls._configs.append(new_config)
return new_config
@classmethod
def make_from_file(cls, filename, name=""):
"""
Loads the settings dict from a file and passes it to Config.make.
Args:
filename (str): name of the file to load
name (str, optional): the name of the config
Returns:
Config: the created config obj
"""
settings = anyconfig.load(filename, safe=True)
return cls.make(settings=settings, name=name)
@classmethod
def get(cls, name=""):
"""
Use this to access your desired Config.
Args:
name (str, optional): the unique name of the config you
want returned.
Returns: the config obj
Raises:
KeyError: if a config by that name does't exist.
"""
logger.debug('Retrieving Config named "%s"', name)
for config in cls._configs:
if config.name == name:
return config
else:
raise KeyError('No config with the name {} exists'.format(name))
def get_plugins(self, category_name=None, plugin_name=None):
"""
get_plugins returns a deepcopy of all the plugins fitting
the search criteria. While this isn't very memory efficient
our plugins should be small and few between enough that it'll be
worth getting independent copies of them. For example we will likely
want to work with multiple copies of the Same Resource plugin.
Args:
category_name (str, optional): a category to search for plugins in.
plugin_name (str, optional): the name of the plugin to look for.
Returns:
list: of the plugins that match the criteria.
"""
results = []
if category_name and plugin_name:
plugin_info = self._plugins.getPluginByName(
plugin_name,
category=category_name
)
if plugin_info:
results.append(plugin_info.plugin_object.__class__())
elif category_name and not plugin_name:
plugin_infos = self._plugins.getPluginsOfCategory(category_name)
for plugin_info in plugin_infos:
results.append(plugin_info.plugin_object.__class__())
elif plugin_name and not category_name:
for category in self._plugins.getCategories():
plugin_info = self._plugins.getPluginByName(
plugin_name,
category=category
)
if plugin_info:
results.append(plugin_info.plugin_object.__class__())
elif not category_name and not plugin_name:
plugin_infos = self._plugins.getAllPlugins()
for plugin_info in plugin_infos:
results.append(plugin_info.plugin_object.__class__())
return results
示例12: test_init_with_plugin_locator
# 需要导入模块: from yapsy.PluginManager import PluginManager [as 别名]
# 或者: from yapsy.PluginManager.PluginManager import getCategories [as 别名]
def test_init_with_plugin_locator(self):
class SpecificLocator(IPluginLocator):
pass
pm = PluginManager(plugin_locator=SpecificLocator())
self.assertEqual(["Default"],pm.getCategories())
self.assertTrue(isinstance(pm.getPluginLocator(),SpecificLocator))
示例13: test_default_init
# 需要导入模块: from yapsy.PluginManager import PluginManager [as 别名]
# 或者: from yapsy.PluginManager.PluginManager import getCategories [as 别名]
def test_default_init(self):
pm = PluginManager()
self.assertEqual(["Default"],pm.getCategories())
self.assertTrue(isinstance(pm.getPluginLocator(),PluginFileLocator))
示例14: test_init_with_category_filter
# 需要导入模块: from yapsy.PluginManager import PluginManager [as 别名]
# 或者: from yapsy.PluginManager.PluginManager import getCategories [as 别名]
def test_init_with_category_filter(self):
pm = PluginManager(categories_filter={"Mouf": IPlugin})
self.assertEqual(["Mouf"],pm.getCategories())
self.assertTrue(isinstance(pm.getPluginLocator(),PluginFileLocator))
示例15: test_init_with_plugin_info_ext
# 需要导入模块: from yapsy.PluginManager import PluginManager [as 别名]
# 或者: from yapsy.PluginManager.PluginManager import getCategories [as 别名]
def test_init_with_plugin_info_ext(self):
pm = PluginManager(plugin_info_ext="bla")
self.assertEqual(["Default"],pm.getCategories())
self.assertTrue(isinstance(pm.getPluginLocator(),PluginFileLocator))