Plugin Interface¶
DNF plugin can be any Python class fulfilling the following criteria:
- it derives from
dnf.Plugin
, - it is made available in a Python module stored in one of the
Conf.pluginpath
, - provides its own
name
and__init__()
.
When DNF CLI runs it loads the plugins found in the paths during the CLI’s initialization.
-
class
dnf.
Plugin
¶ The base class all DNF plugins must derive from.
-
name
¶ The plugin must set this class variable to a string identifying the plugin. The string can only contain alphanumeric characters and underscores.
-
static
read_config
(conf)¶ Read plugin’s configuration into a ConfigParser compatible instance. conf is a
Conf
instance used to look up the plugin configuration directory.
-
__init__
(base, cli)¶ The plugin must override this. Called immediately after all the plugins are loaded. base is an instance of
dnf.Base
. cli is an instance ofdnf.cli.Cli
but can also beNone
in case DNF is running without a CLI (e.g. from an extension).
-
pre_config
()¶ This hook is called before configuring the repos.
-
config
()¶ This hook is called immediately after the CLI/extension is finished configuring DNF. The plugin can use this to tweak the global configuration or the repository configuration.
-
resolved
()¶ This hook is called immediately after the CLI has finished resolving a transaction. The plugin can use this to inspect the resolved but not yet executed
Base.transaction
.
-
sack
()¶ This hook is called immediately after
Base.sack
is initialized with data from all the enabled repos.
-
pre_transaction
()¶ This hook is called just before transaction execution. This means after a successful transaction test. RPMDB is locked during that time.
-
transaction
()¶ This hook is called immediately after a successful transaction. Plugins that were removed or obsoleted by the transaction will not run the transaction hook.
-
-
register_command
(command_class)¶ A class decorator for automatic command registration.
Example of a plugin that provides a hello-world dnf command (the file must be placed in one of the pluginpath directories:
import dnf @dnf.plugin.register_command class HelloWorldCommand(dnf.cli.Command): aliases = ('hello-world',) summary = 'The example command' def run(self): print('Hello world!')
To run the command:
$ dnf hello-world Hello world!
You may want to see the comparison with yum plugin hook API.