ctl.plugins
Base classes for ctl plugins
Classes
ConfuArgparseRouter
ConfuArgparseRouter(builtins.object)
An instance of this will be passed to plugin's add_arguments
class method and can be used to route cli parameters
generated by confu to sub-parsers
This is useful in cases where you dont want to just attach all confu generated cli parameters to the main argparse parser which is the default behavior
Methods
__init__
def __init__(self, parser, schema, defaults)
Initialize self. See help(type(self)) for accurate signature.
add
def add(self, parser, *attributes)
Add cli enabled arguments from the confu schema in self.schema
to an argparser.ArgumentParser instance.
Arguments
- parser (
argparse.ArgumentParser
): parser instance to add arguments to - any other arguments specified should be attribute names from the schema
if no attribute names are supplied, ALL cli enabled attributes from the schema will be added to the parser
In order to add nested attributes use the "__" delimiter in the attribute name to delimit between parent and child attributes.
ExecutablePlugin
ExecutablePlugin(ctl.plugins.PluginBase)
Base plugin class for CLI executable plugins
Methods
execute
def execute(self, **kwargs)
Execute the plugin's main action
Will automatically call prepare
Keyword Arguments
Any keyword arguments passed to this function will
be stored in the plugin's kwargs
attribute
get_config
def get_config(self, name)
Retrieve configuration properties from cli parameters and plugin config.
For a property that exist as both a cli argument and a config property the cli argument takes priority, but it's default value will be informed by the configuration property - so you get to have your cake, and eat it too.
Argument(s):
- name(str): config key
Returns:
- config / cli parameter property
prepare
def prepare(self, **kwargs)
prepare plugin for execution
override this to set instance properties and prepare for execution
PluginBase
PluginBase(pluginmgr.config.PluginBase)
Base plugin class
Extend other plugins from this class.
CLI Executable Plugins
If your intention is a cli executable plugin please have a look at the ExecutablePlugin class.
Class Attributes
- ConfigSchema (
PluginConfigSchema Class
): Base plugin config schema
Instanced Attributes
These attributes / properties will be available on instances of the class
- args (
list
): args passed during__init__
- config (
dict
): plugin config - ctl (
Ctl
): ctl context - kwargs (
dict
): kwargs passed during__init__
- log (
@property
): logger instance for the plugin - plugin_name (
@property
): name of the plugin instance
Class Methods
add_arguments
def add_arguments(cls, parser, plugin_config, confu_cli_args)
override this to add custom cli arguments to your plugin
Methods
__init__
def __init__(self, plugin_config, ctx, *args, **kwargs)
Argument(s):
- plugin_config (
dict
) - ctx: ctl context (
Ctl
)
Any unknown arguments will be kept in self.args
Keyword Argument(s):
Any keyword arguments will be kept in self.kwargs
attach_event
def attach_event(self, name, config)
Attaches the plugin instance to an event, allowing to execute an action on the plugin when the event triggers.
Argument(s)
- name(str): event name
- config(dict): event config
attach_events
def attach_events(self, events)
attach plugin events
init
def init(self)
called after the plugin is initialized, plugin may define this for any other initialization code
other_plugin
def other_plugin(self, name)
return plugin instance by name convenience function as plugins often reference other plugins
PluginConfigSchema
PluginConfigSchema(confu.schema.core.Schema)
Configuration Schema for PluginBase
When creating new configuration schemas for extended plugins extend this.
Class Attributes
- config (
Schema
): plugin specific config - description (
Str
): description of plugin - name (
Str
): Plugin name - type (
Str
): Plugin type