4.4. User Configuartion

A plugin may require some special configuration. There are two possible ways:

4.4.1. Adding parameter to the constructor

A plugin may add more than the self to the __init__ function. The user has to add the values when the plugin is loaded. This makes it possible to load a plugin more than once with different settings.

The following example adds two parameter. The first one has no default value and has to be added when activating the plugin. The second is optional.

import plugin

class PluginInterface(plugin.Plugin):
    def __init__(self, arg1, arg2='foo'):
        plugin.Plugin.__init__(self)


plugin.activate('foo', args=('1',))
plugin.activate('foo', args=('1', 'bar'))

	  

4.4.2. Using local_conf.py

The second way is to use the local_conf.py to let the user set the variables. Since a plugin should be self contained, it should not add something to freevo_config.py. A better way is to use the member function config to return a list of variables for this plugin. If the user doesn't define the variable the default values will be added to the config module. Warning: the config function will be called in the __init__ function of the base plugin class, do not try to use the variables before that.

Example: the plugin needs FOO_NAME and FOO_FUNCTION to be set. It defines the default values and a small description (not used at the moment)

import plugin

class PluginInterface(plugin.Plugin):
    def config(self):
        return [ ('FOO_NAME', 'the default', 'some description'),
                 ('FOO_FUNCTION', foo, 'this is a function') ]