|
Packit Service |
21c75c |
..
|
|
Packit Service |
21c75c |
Copyright (C) 2014-2018 Red Hat, Inc.
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
This copyrighted material is made available to anyone wishing to use,
|
|
Packit Service |
21c75c |
modify, copy, or redistribute it subject to the terms and conditions of
|
|
Packit Service |
21c75c |
the GNU General Public License v.2, or (at your option) any later version.
|
|
Packit Service |
21c75c |
This program is distributed in the hope that it will be useful, but WITHOUT
|
|
Packit Service |
21c75c |
ANY WARRANTY expressed or implied, including the implied warranties of
|
|
Packit Service |
21c75c |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
Packit Service |
21c75c |
Public License for more details. You should have received a copy of the
|
|
Packit Service |
21c75c |
GNU General Public License along with this program; if not, write to the
|
|
Packit Service |
21c75c |
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
Packit Service |
21c75c |
02110-1301, USA. Any Red Hat trademarks that are incorporated in the
|
|
Packit Service |
21c75c |
source code or documentation are not subject to the GNU General Public
|
|
Packit Service |
21c75c |
License and may only be used or replicated with the express permission of
|
|
Packit Service |
21c75c |
Red Hat, Inc.
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
==================
|
|
Packit Service |
21c75c |
Plugin Interface
|
|
Packit Service |
21c75c |
==================
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
DNF plugin can be any Python class fulfilling the following criteria:
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
1. it derives from :class:`dnf.Plugin`,
|
|
Packit Service |
21c75c |
2. it is made available in a Python module stored in one of the :attr:`.Conf.pluginpath`,
|
|
Packit Service |
21c75c |
3. provides its own :attr:`~.Plugin.name` and :meth:`~.Plugin.__init__`.
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
When DNF CLI runs it loads the plugins found in the paths during the CLI's initialization.
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
.. class:: dnf.Plugin
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
The base class all DNF plugins must derive from.
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
.. attribute:: name
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
The plugin must set this class variable to a string identifying the plugin. The string can only contain alphanumeric characters and underscores.
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
.. staticmethod:: read_config(conf)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
Read plugin's configuration into a `ConfigParser <http://docs.python.org/3/library/configparser.html>`_ compatible instance. `conf` is a :class:`.Conf` instance used to look up the plugin configuration directory.
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
.. method:: __init__(base, cli)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
The plugin must override this. Called immediately after all the plugins are loaded. `base` is an instance of :class:`dnf.Base`. `cli` is an instance of :class:`dnf.cli.Cli` but can also be ``None`` in case DNF is running without a CLI (e.g. from an extension).
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
.. method:: pre_config()
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
This hook is called before configuring the repos.
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
.. method:: config()
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
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.
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
.. method:: resolved()
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
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 :attr:`Base.transaction`.
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
.. method:: sack()
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
This hook is called immediately after :attr:`.Base.sack` is initialized with data from all the enabled repos.
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
.. method:: pre_transaction()
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
This hook is called just before transaction execution. This means after a successful transaction test. RPMDB is locked during that time.
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
.. method:: transaction()
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
This hook is called immediately after a successful transaction.
|
|
Packit Service |
21c75c |
Plugins that were removed or obsoleted by the transaction will not run the transaction hook.
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
.. method:: register_command(command_class)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
A class decorator for automatic command registration.
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
Example of a plugin that provides a hello-world dnf command (the file must be placed in one of the :ref:`pluginpath <pluginpath-label>` directories::
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
import dnf
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
@dnf.plugin.register_command
|
|
Packit Service |
21c75c |
class HelloWorldCommand(dnf.cli.Command):
|
|
Packit Service |
21c75c |
aliases = ('hello-world',)
|
|
Packit Service |
21c75c |
summary = 'The example command'
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
def run(self):
|
|
Packit Service |
21c75c |
print('Hello world!')
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
To run the command::
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
$ dnf hello-world
|
|
Packit Service |
21c75c |
Hello world!
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
You may want to see the comparison with `yum plugin hook API`_.
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
.. _yum plugin hook API: http://dnf.readthedocs.org/en/latest/api_vs_yum.html
|