Core & Plugins¶
-
class
openpaperwork_core.
Core
(allow_unsatisfied=False)[source]¶ Manage plugins and their callbacks.
-
call_all
(callback_name, *args, **kwargs)[source]¶ Call all the methods of all the plugins that have callback_name as name. Arguments are passed as is. Returned values are dropped (use callbacks for return values if required)
-
call_one
(callback_name, *args, **kwargs)[source]¶ Look for a plugin method called callback_name and calls it. Raises an error if no such method exists. If many exists, raises a warning and call one at random. Returns the value return by the callback.
You’re advised to use call_all() or call_success instead whenever possible. This method is only provided as convenience for when you’re fairly sure there should be only one plugin with such callback (example: mainloop plugins).
-
call_success
(callback_name, *args, **kwargs)[source]¶ Call methods of all the plugins that have callback_name as name until one of them return a value that is not None. Arguments are passed as is. First value to be different from None is returned. If none of the callbacks returned a value different from None or if no callback has the specified name, this method will return None.
-
get_by_name
(module_name)[source]¶ Returns a Plugin instance based on the corresponding module name (assuming it has been loaded).
-
init
()[source]¶ - Make sure all the dependencies of all the plugins are satisfied.
- Call the method init() of each plugin following the dependency order (those without dependencies are called first).
BEWARE of dependency loops !
-
load
(module_name)[source]¶ - Load the specified module
- Instantiate the class ‘Plugin()’ of this module
- Register all the methods of this plugin object (except those starting by ‘_’ and those from the class PluginBase) as callbacks
BEWARE of dependency loops !
- Arguments:
- module_name: name of the Python module to load
-
-
class
openpaperwork_core.
PluginBase
[source]¶ Indicates all the methods that must be implemented by any plugin managed by OpenPaperwork core. Also provides default implementations for each method.
-
PRIORITY
= 0¶
-
USER_VISIBLE
= False¶
-
get_deps
()[source]¶ Return the dependencies required by this plugin.
Example:
[ { "interface": "some_interface_name", # required "defaults": ['plugin_a', 'plugin_b'], # required "expected_already_satisfied": False, # optional, default: True }, ]
-