本文整理汇总了Python中invenio.pluginutils.PluginContainer类的典型用法代码示例。如果您正苦于以下问题:Python PluginContainer类的具体用法?Python PluginContainer怎么用?Python PluginContainer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PluginContainer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_ticket_plugins
def load_ticket_plugins():
"""
Will load all the ticket plugins found under CFG_BIBCATALOG_PLUGIN_DIR.
Returns a tuple of plugin_object, list of errors.
"""
# TODO add to configfile
CFG_BIBCATALOG_PLUGIN_DIR = os.path.join(CFG_PYLIBDIR,
"invenio",
"bibcatalog_ticket_templates",
"*.py")
# Load plugins
plugins = PluginContainer(CFG_BIBCATALOG_PLUGIN_DIR,
plugin_builder=_bibcatalog_plugin_builder)
# Remove __init__ if applicable
try:
plugins.disable_plugin("__init__")
except KeyError:
pass
error_messages = []
# Check for broken plug-ins
broken = plugins.get_broken_plugins()
if broken:
error_messages = []
for plugin, info in broken.items():
error_messages.append("Failed to load %s:\n"
" %s" % (plugin, "".join(traceback.format_exception(*info))))
return plugins, error_messages
示例2: build_and_run_web_test_suite
def build_and_run_web_test_suite():
"""Build and run the web tests.
Detect all Invenio modules with names ending by
'*_web_tests.py', build a complete test suite of them, and
run it. Called by 'inveniocfg --run-web-tests'.
"""
from invenio.config import CFG_PYLIBDIR
from invenio.pluginutils import PluginContainer
test_modules_map = PluginContainer(
os.path.join(CFG_PYLIBDIR, 'invenio', '*_web_tests.py'),
lambda plugin_name, plugin_code: getattr(plugin_code, "TEST_SUITE"))
test_modules = test_modules_map.values()
broken_tests = test_modules_map.get_broken_plugins()
broken_web_tests = ['%s (reason: %s)' % (name, broken_tests[name][1])
for name in broken_tests]
if broken_web_tests:
warn("Broken web tests suites found: %s" % ', '.join(broken_web_tests))
warn_user_about_tests()
complete_suite = unittest.TestSuite(test_modules)
runner = unittest.TextTestRunner(descriptions=False, verbosity=2)
return runner.run(complete_suite).wasSuccessful()
示例3: setUp
def setUp(self):
"""Load plugin."""
search_service_plugins = PluginContainer(
os.path.join(CFG_SEARCH_SERVICES_PATH, '*Service.py'),
api_version=__required_plugin_API_version__,
plugin_signature=SearchService
)
self.plugin = search_service_plugins.get('JournalHintService')()
示例4: test_plugin_container_module_reloading
def test_plugin_container_module_reloading(self):
"""pluginutils - plugin reloading"""
websubmit_functions = PluginContainer(os.path.join(CFG_PYLIBDIR, 'invenio', 'websubmit_functions', '*.py'))
self.assertNotEqual(websubmit_functions['Is_Referee'].__doc__, "test_reloading")
websubmit_functions['Is_Referee'].__doc__ = "test_reloading"
self.assertEqual(websubmit_functions['Is_Referee'].__doc__, "test_reloading")
websubmit_functions.reload_plugins(reload=True)
self.assertNotEqual(websubmit_functions['Is_Referee'].__doc__, "test_reloading")
示例5: test_plugin_container_module_caching
def test_plugin_container_module_caching(self):
"""pluginutils - plugin caching"""
websubmit_functions = PluginContainer(os.path.join(CFG_PYLIBDIR, "invenio", "websubmit_functions", "*.py"))
self.assertNotEqual(websubmit_functions["Is_Referee"].__doc__, "test_caching")
websubmit_functions["Is_Referee"].__doc__ = "test_caching"
self.assertEqual(websubmit_functions["Is_Referee"].__doc__, "test_caching")
websubmit_functions.reload_plugins()
websubmit_functions_new = PluginContainer(os.path.join(CFG_PYLIBDIR, "invenio", "websubmit_functions", "*.py"))
self.assertEqual(websubmit_functions_new["Is_Referee"].__doc__, "test_caching")
示例6: load_facet_builders
def load_facet_builders():
## Let's load all facets.
_FACETS = PluginContainer(
os.path.join(CFG_PYLIBDIR, 'invenio', 'websearch_facets', 'facet_*.py'),
plugin_builder=_invenio_facet_plugin_builder)
FACET_DICTS = dict((f.name, f) for f in _FACETS.values())
FACET_SORTED_LIST = sorted(FACET_DICTS.values(), key=lambda x: x.order)
current_app.config['FACET_DICTS'] = FACET_DICTS
current_app.config['FACET_SORTED_LIST'] = FACET_SORTED_LIST
示例7: load_bfe_elements
def load_bfe_elements():
BFE_ELEMENTS = PluginContainer(os.path.join(CFG_PYLIBDIR, 'invenio',
'bibformat_elements',
'bfe_*.py'),
plugin_builder=plugin_builder)
## Let's report about broken plugins
open(os.path.join(CFG_LOGDIR, 'broken-bibformat-elements.log'), 'w').write(
pformat(BFE_ELEMENTS.get_broken_plugins()))
current_app.config['BFE_ELEMENTS'] = BFE_ELEMENTS
示例8: test_plugin_container_wrapping_websubmit_functions
def test_plugin_container_wrapping_websubmit_functions(self):
"""pluginutils - wrapping websubmit functions"""
websubmit_functions = PluginContainer(os.path.join(CFG_PYLIBDIR, 'invenio', 'websubmit_functions', '*.py'))
self.failUnless(websubmit_functions['Is_Referee'])
self.failUnless(websubmit_functions['CaseEDS'])
self.failUnless(callable(websubmit_functions['CaseEDS']))
self.failUnless(len(websubmit_functions) >= 62)
## Retrieve_Data and Shared_Functions are not real plugins
self.failUnless(len(websubmit_functions.get_broken_plugins()) >= 2)
self.failIf(websubmit_functions.get('Shared_Functions'))
self.failUnless('Shared_Functions' in websubmit_functions.get_broken_plugins())
示例9: test_no_broken_search_services_
def test_no_broken_search_services_(self):
"""websearch - no broken search services"""
error_messages = []
search_service_plugins = PluginContainer(os.path.join(CFG_SEARCH_SERVICES_PATH, '*Service.py'),
api_version=__required_plugin_API_version__,
plugin_signature=SearchService)
for name, error in search_service_plugins.get_broken_plugins().iteritems():
error_messages.append("Service '%s' could not be loaded:\n%s" % \
(name, repr(error[0]) + " " + repr(error[1]) + "\n" + "\n".join(traceback.format_tb(error[2]))))
if error_messages:
self.fail(merge_error_messages(error_messages))
示例10: write_metadata
def write_metadata(inputfile, outputfile, metadata_dictionary,
force=None, verbose=0):
"""
Writes metadata to given file.
Availability depends on input file format and installed plugins
(return C{TypeError} if unsupported file format).
@param inputfile: path to a file
@type inputfile: string
@param outputfile: path to the resulting file.
@type outputfile: string
@param verbose: verbosity
@type verbose: int
@param metadata_dictionary: keys and values of metadata to update.
@type metadata_dictionary: dict
@param force: name of plugin to use, to skip plugin auto-discovery
@type force: string
@return: output of the plugin
@rtype: string
@raise TypeError: if file format is not supported.
@raise RuntimeError: if required library to process file is missing.
@raise InvenioWebSubmitFileMetadataRuntimeError: when metadata cannot be updated.
"""
# Check file type (0 base, 1 name, 2 ext)
ext = decompose_file(inputfile)[2]
if verbose > 5:
print ext.lower(), 'extension to write to'
# Plugins
metadata_extractor_plugins = PluginContainer(
os.path.join(CFG_PYLIBDIR,
'invenio', 'websubmit_file_metadata_plugins', 'wsm_*.py'),
plugin_builder=plugin_builder_function,
api_version=__required_plugin_API_version__
)
# Loop through the plugins to find a good one to ext
for plugin_name, plugin in metadata_extractor_plugins.iteritems():
if plugin.has_key('can_write_local') and \
plugin['can_write_local'](inputfile) and \
(not force or plugin_name == force):
if verbose > 5:
print 'Using ' + plugin_name
return plugin['write_metadata_local'](inputfile,
outputfile,
metadata_dictionary,
verbose)
# Case of no plugin found, raise
raise TypeError, 'Unsupported file type'
示例11: test_plugin_container_wrapping_websubmit_functions
def test_plugin_container_wrapping_websubmit_functions(self):
"""pluginutils - wrapping websubmit functions"""
websubmit_functions = PluginContainer(os.path.join(CFG_PYLIBDIR, "invenio", "websubmit_functions", "*.py"))
self.failUnless(websubmit_functions["Is_Referee"])
self.failUnless(websubmit_functions["CaseEDS"])
self.failUnless(callable(websubmit_functions["CaseEDS"]))
self.failUnless(
len(websubmit_functions) >= 62,
"There should exist at least 62 websubmit_functions. Found: %s" % len(websubmit_functions),
)
## Retrieve_Data and Shared_Functions are not real plugins
self.failUnless(len(websubmit_functions.get_broken_plugins()) >= 2)
self.failIf(websubmit_functions.get("Shared_Functions"))
self.failUnless("Shared_Functions" in websubmit_functions.get_broken_plugins())
示例12: test_plugin_container_wrapping_external_authentications
def test_plugin_container_wrapping_external_authentications(self):
"""pluginutils - wrapping external authentications"""
def plugin_builder(plugin_name, plugin_code):
for name in dir(plugin_code):
candidate = getattr(plugin_code, name)
try:
if issubclass(candidate, ExternalAuth):
return candidate
except TypeError:
pass
raise ValueError('%s is not a valid external authentication plugin' % plugin_name)
external_authentications = PluginContainer(os.path.join(CFG_PYLIBDIR, 'invenio', 'external_authentication_*.py'), plugin_signature=ExternalAuth, plugin_builder=plugin_builder)
self.failUnless(issubclass(external_authentications['external_authentication_sso'], ExternalAuth))
self.failIf(external_authentications.get('external_authentication_cern_wrapper'))
self.failUnless(len(external_authentications) >= 1)
self.failUnless(len(external_authentications.get_broken_plugins()) >= 2)
示例13: load_plugins
def load_plugins():
"""
Will load all the plugins found under the bibcheck_plugins folder.
Returns a list of plugin objects.
"""
plugin_dir = os.path.join(CFG_PYLIBDIR, "invenio/bibcheck_plugins/*.py")
# Load plugins
plugins = PluginContainer(plugin_dir,
plugin_builder=_bibcheck_plugin_builder)
# Check for broken plug-ins
broken = plugins.get_broken_plugins()
if broken:
for plugin, info in broken.items():
print "Failed to load %s:\n" % plugin
print "".join(traceback.format_exception(*info))
enabled = plugins.get_enabled_plugins()
enabled.pop("__init__", None)
return enabled
示例14: build_and_run_unit_test_suite
def build_and_run_unit_test_suite():
"""
Detect all Invenio modules with names ending by '*_unit_tests.py', build
a complete test suite of them, and run it.
Called by 'inveniocfg --run-unit-tests'.
"""
test_modules_map = PluginContainer(
os.path.join(CFG_PYLIBDIR, 'invenio', '*_unit_tests.py'),
lambda plugin_name, plugin_code: getattr(plugin_code, "TEST_SUITE"))
test_modules = [test_modules_map[name] for name in test_modules_map]
broken_tests = test_modules_map.get_broken_plugins()
broken_unit_tests = ['%s (reason: %s)' % (name, broken_tests[name][1]) for name in broken_tests]
if broken_unit_tests:
warn("Broken unit tests suites found: %s" % ', '.join(broken_unit_tests))
complete_suite = unittest.TestSuite(test_modules)
res = unittest.TextTestRunner(verbosity=2).run(complete_suite)
return res.wasSuccessful()
示例15: metadata_info
def metadata_info(verbose=0):
"""Shows information about the available plugins"""
print 'Plugin APIs version: %s' % str(__required_plugin_API_version__)
# Plugins
print 'Available plugins:'
metadata_extractor_plugins = PluginContainer(
os.path.join(CFG_PYLIBDIR,
'invenio', 'websubmit_file_metadata_plugins', 'wsm_*.py'),
plugin_builder=plugin_builder_function,
api_version=__required_plugin_API_version__
)
# Print each operation on each plugin
for plugin_name, plugin_funcs in metadata_extractor_plugins.iteritems():
if len(plugin_funcs) > 0:
print '-- Name: ' + plugin_name
print ' Supported operation%s: ' % \
(len(plugin_funcs) > 1 and 's' or '') + \
', '.join(plugin_funcs)
# Are there any unloaded plugins?
broken_plugins = metadata_extractor_plugins.get_broken_plugins()
if len(broken_plugins.keys()) > 0:
print 'Could not load the following plugin%s:' % \
(len(broken_plugins.keys()) > 1 and 's' or '')
for broken_plugin_name, broken_plugin_trace_info in broken_plugins.iteritems():
print '-- Name: ' + broken_plugin_name
if verbose > 5:
formatted_traceback = \
traceback.format_exception(broken_plugin_trace_info[0],
broken_plugin_trace_info[1],
broken_plugin_trace_info[2])
print ' ' + ''.join(formatted_traceback).replace('\n', '\n ')
elif verbose > 0:
print ' ' + str(broken_plugin_trace_info[1])