plugin – Plugin loaders

The plugin module provides several helper functions that wrap twisted.plugin. plugin makes loading plugins simpler.

bravo.plugin.add_plugin_edges(d)[source]

Mirror edges to all plugins in a dictionary.

bravo.plugin.expand_names(plugins, names)[source]

Given a list of names, expand wildcards and discard disabled names.

Used to implement * and - options in plugin lists.

Parameters:
  • plugins (dict) – plugins to use for expansion
  • names (list) – names to examine
Returns:

a list of filtered plugin names

bravo.plugin.get_plugins(interface, package, parameters=None)[source]

Lazily find objects in a package which implement a given interface.

The objects must also implement twisted.plugin.IPlugin.

If the optional dictionary of parameters is provided, it will be passed into each plugin module as the “bravo.parameters” module. An example access from inside the plugin:

>>> from bravo.parameters import foo, bar

Since the parameters are available as a real module, the parameters may be imported and used like any other module:

>>> from bravo import parameters as params

This is a rewrite of Twisted’s twisted.plugin.getPlugins which uses Exocet instead of Twisted to find the plugins.

Parameters:
  • interface (interface) – the interface to match against
  • package (str) – the name of the package to search
  • parameters (dict) – parameters to pass into the plugins
bravo.plugin.retrieve_named_plugins(interface, names, parameters=None)[source]

Look up a list of plugins by name.

Plugins are returned in the same order as their names.

Parameters:
  • interface (interface) – the interface to use
  • names (list) – plugins to find
  • parameters (dict) – parameters to pass into the plugins
Returns:

a list of plugins

Raises PluginException:
 

no plugins could be found for the given interface

bravo.plugin.retrieve_plugins(interface, parameters=None)[source]

Look up all plugins for a certain interface.

If the plugin cache is enabled, this function will not attempt to reload plugins from disk or discover new plugins.

Parameters:
  • interface (interface) – the interface to use
  • parameters (dict) – parameters to pass into the plugins
Returns:

a dict of plugins, keyed by name

Raises PluginException:
 

no plugins could be found for the given interface

bravo.plugin.retrieve_sorted_plugins(interface, names, parameters=None)[source]

Look up a list of plugins, sorted by interdependencies.

Parameters:parameters (dict) – parameters to pass into the plugins
bravo.plugin.sort_plugins(plugins)[source]

Make a sorted list of plugins by dependency.

If the list cannot be arranged into a DAG, an error will be raised. This usually means that a cyclic dependency was found.

Raises PluginException:
 cyclic dependency detected
bravo.plugin.synthesize_parameters(parameters)[source]

Create a faked module which has the given parameters in it.

This should work everywhere. If it doesn’t, let me know.

bravo.plugin.verify_plugin(interface, plugin)[source]

Plugin interface verification.

This function will call verifyObject() and validateInvariants() on the plugins passed to it.

The primary purpose of this wrapper is to do logging, but it also permits code to be slightly cleaner, easier to test, and callable from other modules.

Project Versions

Previous topic

packets – Packet serializers

Next topic

protocols – Twisted protocols

This Page