ConfigurablePluginManager

Role

Defines plugin managers that can handle configuration files similar to the ini files manipulated by Python’s ConfigParser module.

API

class yapsy.ConfigurablePluginManager.ConfigurablePluginManager(configparser_instance=None, config_change_trigger=<function ConfigurablePluginManager.<lambda>>, decorated_manager=None, categories_filter=None, directories_list=None, plugin_info_ext='yapsy-plugin')

A plugin manager that also manages a configuration file.

The configuration file will be accessed through a ConfigParser derivated object. The file can be used for other purpose by the application using this plugin manager as it will only add a new specific section [Plugin Management] for itself and also new sections for some plugins that will start with [Plugin:...] (only the plugins that explicitly requires to save configuration options will have this kind of section).

Warning

when giving/building the list of plugins to activate by default, there must not be any space in the list (neither in the names nor in between)

The config_change_trigger argument can be used to set a specific method to call when the configuration is altered. This will let the client application manage the way they want the configuration to be updated (e.g. write on file at each change or at precise time intervalls or whatever….)

Warning

when no config_change_trigger is given and if the provided configparser_instance doesn’t handle it implicitely, recording the changes persistently (ie writing on the config file) won’t happen.

CONFIG_SECTION_NAME = 'Plugin Management'
activatePluginByName(plugin_name, category_name='Default', save_state=True)

Activate a plugin, , and remember it (in the config file).

If you want the plugin to benefit from the configuration utility defined by this manager, it is crucial to use this method to activate a plugin and not call the plugin object’s activate method. In fact, this method will also “decorate” the plugin object so that it can use this class’s methods to register its own options.

By default, the plugin’s activation is registered in the config file but if you d’ont want this set the ‘save_state’ argument to False.

deactivatePluginByName(plugin_name, category_name='Default', save_state=True)

Deactivate a plugin, and remember it (in the config file).

By default, the plugin’s deactivation is registered in the config file but if you d’ont want this set the save_state argument to False.

hasOptionFromPlugin(category_name, plugin_name, option_name)

To be called from a plugin object, return True if the option has already been registered.

loadPlugins(callback=None, callback_after=None)

Walk through the plugins’ places and look for plugins. Then for each plugin candidate look for its category, load it and stores it in the appropriate slot of the category_mapping.

readOptionFromPlugin(category_name, plugin_name, option_name)

To be called from a plugin object, read a given option in the name of a given plugin.

registerOptionFromPlugin(category_name, plugin_name, option_name, option_value)

To be called from a plugin object, register a given option in the name of a given plugin.

setConfigParser(configparser_instance, config_change_trigger)

Set the ConfigParser instance.