当前位置: 首页>>代码示例>>Python>>正文


Python PluginContainer.iteritems方法代码示例

本文整理汇总了Python中invenio.pluginutils.PluginContainer.iteritems方法的典型用法代码示例。如果您正苦于以下问题:Python PluginContainer.iteritems方法的具体用法?Python PluginContainer.iteritems怎么用?Python PluginContainer.iteritems使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在invenio.pluginutils.PluginContainer的用法示例。


在下文中一共展示了PluginContainer.iteritems方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: write_metadata

# 需要导入模块: from invenio.pluginutils import PluginContainer [as 别名]
# 或者: from invenio.pluginutils.PluginContainer import iteritems [as 别名]
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'
开发者ID:aw-bib,项目名称:tind-invenio,代码行数:53,代码来源:websubmit_file_metadata.py

示例2: metadata_info

# 需要导入模块: from invenio.pluginutils import PluginContainer [as 别名]
# 或者: from invenio.pluginutils.PluginContainer import iteritems [as 别名]
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])
开发者ID:aw-bib,项目名称:tind-invenio,代码行数:38,代码来源:websubmit_file_metadata.py

示例3: read_metadata

# 需要导入模块: from invenio.pluginutils import PluginContainer [as 别名]
# 或者: from invenio.pluginutils.PluginContainer import iteritems [as 别名]
def read_metadata(inputfile, force=None, remote=False,
                  loginpw=None, verbose=0):
    """
    Returns metadata extracted from given file as dictionary.

    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 verbose: verbosity
    @type verbose: int
    @param force: name of plugin to use, to skip plugin auto-discovery
    @type force: string
    @param remote: if the file is accessed remotely or not
    @type remote: boolean
    @param loginpw: credentials to access secure servers (username:password)
    @type loginpw: string
    @return: dictionary of metadata tags as keys, and (interpreted)
             value as value
    @rtype: dict
    @raise TypeError: if file format is not supported.
    @raise RuntimeError: if required library to process file is missing.
    @raise InvenioWebSubmitFileMetadataRuntimeError: when metadata cannot be read.
    """
    metadata = None
    # Check file type (0 base, 1 name, 2 ext)
    ext = decompose_file(inputfile)[2]
    if verbose > 5:
        print ext.lower(), 'extension to extract from'

    # Load 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 for given file
    for plugin_name, plugin in metadata_extractor_plugins.iteritems():
        # Local file
        if plugin.has_key('can_read_local') and \
            plugin['can_read_local'](inputfile) and not remote and \
            (not force or plugin_name == force):
            if verbose > 5:
                print 'Using ' + plugin_name
            fetched_metadata = plugin['read_metadata_local'](inputfile,
                                                             verbose)
            if not metadata:
                metadata = fetched_metadata
            else:
                metadata.update(fetched_metadata)

        # Remote file
        elif remote and plugin.has_key('can_read_remote') and \
            plugin['can_read_remote'](inputfile) and \
            (not force or plugin_name == force):
            if verbose > 5:
                print 'Using ' + plugin_name
            fetched_metadata = plugin['read_metadata_remote'](inputfile,
                                                              loginpw,
                                                              verbose)
            if not metadata:
                metadata = fetched_metadata
            else:
                metadata.update(fetched_metadata)

    # Return in case we have something
    if metadata is not None:
        return metadata

    # Case of no plugin found, raise
    raise TypeError, 'Unsupported file type'
开发者ID:aw-bib,项目名称:tind-invenio,代码行数:75,代码来源:websubmit_file_metadata.py


注:本文中的invenio.pluginutils.PluginContainer.iteritems方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。