toolbox package¶
Subpackages¶
Submodules¶
toolbox.config module¶
-
class
toolbox.config.
ConfigManager
[source]¶ Bases:
object
The config manager has the responsibility of persisting plugin configs. On initialisation it creates a default file structure in the user’s home directory
-
FILE_EXT
= '.json'¶
-
load_plugin
(name)[source]¶ Load the plugin config file by name and return an py:class:toolbox.config.PluginConfig
Parameters: name (str) – Returns: an instance of PluginConfig for given plugin name Return type: toolbox.config.PluginConfig
-
-
class
toolbox.config.
PluginConfig
[source]¶ Bases:
object
Config container for plugin configs. Acts like a dictionary with some extra convenience methods. The config has a special key for global configs which can be accessed with the ‘get_global_config’ method
-
GLOBAL_KEY
= '__GLOBAL__'¶
-
toolbox.core module¶
-
class
toolbox.core.
Toolbox
(external=True, local=True)[source]¶ Bases:
object
Initialize the toolbox, sets up the main argument parser and Tool registry Core tools in de contrib package are always loaded
The local and external flags can be used to limit the loaded modules
Parameters: - external (bool) –
- local (bool) –
Returns: -
execute
(args)[source]¶ - This is the Toolbox’s main function which parses the arguments, which should yield:
- a Tool
- an Executable
- and some optional arguments
- The Tool gets fetched from the registry where it will be fully loaded
- and the exectuble is executed with the remaining args
Parameters: args (list) – List of arguments Returns:
toolbox.defaults module¶
toolbox.mixins module¶
-
class
toolbox.mixins.
ConfigMixin
[source]¶ Bases:
object
The ConfigMixin provides the plugin with an persisted py:class:toolbox.config.PluginConfig which is basically an expanded python dictionary which contains the plugin config as well as an global config.
toolbox.plugin module¶
-
class
toolbox.plugin.
BasePlugin
(name, description=None, prepare_parser_func=None, execute_func=None)[source]¶ Bases:
toolbox.plugin.ToolboxPlugin
An easy to use Plugin wrapper that sets all the necessary parts of a ToolboxPlugin
Parameters: - name – The name of the plugin
- description – short description of the plugin (used to index and search plugins)
- prepare_parser_func – The function that prepares the Toolbox main parser
- execute_func – the main function of the plugin, accecpts
argparse.Namespace
Returns:
-
class
toolbox.plugin.
ExecutablePlugin
[source]¶ Bases:
toolbox.plugin.ToolboxPlugin
The ExecutablePlugin is a basic plugin to register shell scripts and the like. Just subclass it and provide the following attributes:
- name
- description (optional)
- executable (the main executable)
- args (a list of default arguments)
optionally the prepare_parser and execute methods can be overridden to add exta functionality
-
args
= []¶
-
description
= None¶
-
executable
= None¶
-
name
= None¶
toolbox.registry module¶
-
class
toolbox.registry.
Registry
[source]¶ Bases:
object
Registry of all available plugins Setup the config manager and creates two empty dicts to track the tools
Variables: - config_manager (toolbox.config.ConfigManager) – Instance of the config manager
- _registered_plugins (dict) – dictionary containing all registered plugins
- _loaded_plugins (dict) – dictionary containing all fully loaded plugins
-
add_plugin
(plugin)[source]¶ - Add a
toolbox.plugin.ToolboxPlugin
to the registry, but don’t load it yet - Checks whether the provided plugin is an instance of
toolbox.plugin.ToolboxPlugin
Parameters: plugin ( toolbox.plugin.ToolboxPlugin
) – A plugin to add to the registryRaises: AtttibuteError
,toolbox.registry.NoPluginException
Returns: - Add a
-
get_plugin
(name)[source]¶ fetch a plugin from the registry and load it if it is not loaded already.
Parameters: name (str) – Name of the registered plugin Returns: An loaded plugin Return type: toolbox.plugin.ToolboxPlugin
Raise: ValueError
-
populate
(modules)[source]¶ Given a list of ‘importable’ modules populate the registry First import the module, check whether it has a ‘Plugin’ attribute in the namespace and add the plugin to the registry
Also accepts an module where there is a class definition suffixed by ‘Plugin’ like ‘TestPlugin’
Parameters: modules (list) – Returns:
toolbox.scanner module¶
-
toolbox.scanner.
find_contrib_modules
()[source]¶ Find all core modules in the contrib package and return a list of importable packages :return: A list of importable packages :rtype: list