Command Line Interface Hooks¶
dnf.cli
is a part of DNF that contains code handling the command line tasks for DNF, like for instance dnf install emacs
, and outputs the results to the terminal. It is usually of no interest for DNF extension applications, but some parts of it described here can be used by the Plugin Interface to hook up custom commands.
When packaging your custom command, we recommend you to define a virtual provide in the form of Provides: dnf-command(<alias>)
in the spec file. See the virtual provides usage for the details.
-
exception
dnf.cli.
CliError
¶ Signals a CLI-specific problem (reading configuration, parsing user input, etc.). Derives from
dnf.exceptions.Error
.
-
class
dnf.cli.demand.
DemandSheet
¶ Instances are used to track requests of commands and plugins about how CLI should set up/handle other parts of CLI processing that are not under the command’s/plugin’s direct control. The boolean attributes of the sheet can not be reset once explicitly set, doing so raises an
AttributeError
.-
allow_erasing
¶ If
True
, the dependency solver is allowed to look for solutions that include removing other packages while looking to fulfill the current packaging requests. Defaults toFalse
. Also seednf.Base.resolve()
.
-
available_repos
¶ If
True
, during sack creation (sack_activation
), download and load into the sack the available repositories. Defaults toFalse
.
-
resolving
¶ If
True
, at a place where the CLI would otherwise successfully exit, resolve the transaction for any outstanding packaging requests before exiting. Defaults toFalse
.
-
root_user
¶ True
informs the CLI that the command can only succeed if the process’s effective user id is0
, i.e. root. Defaults toFalse
.
-
sack_activation
¶ If
True
, demand that the CLI sets up theSack
before the command’srun()
method is executed. Defaults toFalse
.Depending on other demands and the user’s configuration, this might or might not correctly trigger metadata download for the available repositories.
-
load_system_repo
¶ If
True
, DNF will load information about installed packages from the local RPMDB into the sack duringdnf.Base.fill_sack()
. Defaults toTrue
.
-
cacheonly
¶ When
True
, DNF will run entirely from the system cache (equivalent of-C
command line option). Defaults toFalse
.
-
fresh_metadata
¶ False
means that (even expired) cached repository metadata will be used. WhenTrue
, the expired repository metadata caches are synchronized with server. Defaults toTrue
.
-
freshest_metadata
¶ If
True
, metadata caches for all enabled repositories are forcibly expired before the sack is activated. Defaults toFalse
.
-
changelogs
¶ If
True
, also the repository metadata containing changelogs for packages will be downloaded. Defaults toFalse
.
-
success_exit_status
¶ The return status of the DNF command on success. Defaults to
0
.
-
transaction_display
¶ An additional instance of a subclass of
dnf.callback.TransactionProgress
used to report information about an ongoing transaction. Defaults toNone
.
-
-
class
dnf.cli.
Command
¶ Base class of every DNF command.
-
aliases
¶ Sequence of strings naming the command from the command line. Must be a class variable. The list has to contain at least one string, the first string in the list is considered the canonical name. A command name can be contain only letters and dashes providing the name doesn’t start with a dash.
-
cli
¶ The
dnf.cli.Cli
instance to use with this command.
-
summary
¶ One line summary for the command as displayed by the CLI help.
-
__init__
(cli)¶ Command constructor which can be overridden. The constructor is called during CLI configure phase when one of the command’s aliases is parsed from dnf commandline. cli is an instance of
dnf.cli.Cli
.
-
pre_configure
()¶ Perform any pre-configuration on the command itself and on the CLI. Typically, the command implements this call to set up releasever or enable/disable repository. This method is called before configuration of repos.
-
configure
()¶ Perform any configuration on the command itself and on the CLI. Typically, the command implements this call to set up any
demands
, tweak the global configuration or the repository configuration. This method is called immediately after the CLI/extension is finished configuring DNF.
-
run
()¶ Run the command. This method is invoked by the CLI when this command is executed. Should raise
dnf.exceptions.Error
with a proper message if the command fails. Otherwise should returnNone
. Custom commands typically override this method and put their main work code here.
-
-
class
dnf.cli.
Cli
¶ Manages the CLI, including reading configuration, parsing the command line and running commands.
-
demands
¶ An instance of
DemandSheet
, exposed to allow custom commands and plugins influence how the CLI will operate.
-
register_command(command_cls):
Register new command. command_cls is a subclass of
Command
.
-
redirect_logger(self, stdout=None, stderr=None):
Change minimal logger level for terminal output to stdout and stderr according to specific command requirements. For stdout and stderr use logging.INFO, logging.WARNING, etc.
-