Base—The centerpiece of DNF¶
dnf.Baseare the central point of functionality supplied by DNF. An application will typically create a single instance of this class which it will keep for the runtime needed to accomplish its packaging tasks. Plugins are managed by DNF and get a reference to
dnf.Baseobject when they run.
Baseinstances are stateful objects holding references to various data sources and data sinks. To properly finalize and close off any handles the object may hold, client code should either call
Base.close()when it has finished operations with the instance, or use the instance as a context manager. After the object has left the context, or its
Base.close()has been called explicitly, it must not be used.
Base.close()will delete all downloaded packages upon successful transaction.
dnf.repodict.RepoDictinstance, this member object contains all the repositories available.
A resolved transaction object, a
Noneif no transaction has been prepared yet.
Init an instance with a reasonable default configuration. The constructor takes no arguments.
Add RPM files at list path_list to the
sackand return the list of respective
dnf.package.Packageinstances. Does the download to a temporary files for each path if path is a remote URL. Raises
IOErrorif there are problems obtaining during reading files and strict=True.
Close all external handles the object holds. This is called automatically via context manager mechanism if the instance is handled using the
Initialize plugins. If you want to disable some plugins pass the list of their name patterns to disabled_glob. When run from interactive script then also pass your
Configure plugins by running their configure() method.
Setup the package sack. If load_system_repo is
True, load information about packages in the local RPMDB into the sack. Else no package is considered installed during dependency solving. If load_available_repos is
True, load information about packages from the available repositories into the sack.
This operation will call
load()for repos as necessary and can take a long time. Adding repositories or changing repositories’ configuration does not affect the information within the sack until
fill_sack()has been called.
Before this method is invoked, the client application should setup any explicit configuration relevant to the operation. This will often be at least
conf.cachedirand the substitutions used in repository URLs. See
Throws IOError exception in case cached metadata could not be opened.
base = dnf.Base() conf = base.conf conf.cachedir = CACHEDIR conf.substitutions['releasever'] = 22 base.repos.add_new_repo('my-repo', conf, baseurl=[MY_REPO_URL]) base.fill_sack()
Perform the resolved transaction. Use the optional display object(s) to report the progress. display can be either an instance of a subclass of
dnf.callback.TransactionProgressor a sequence of such instances. Raise
Download packages in pkglist from remote repositories. Packages from local repositories or from the command line are not downloaded. progress, if given, should be a
DownloadProgressand can be used by the caller to monitor the progress of the download. Raises
DownloadErrorif some packages failed to download.
group_install(group_id, pkg_types, exclude=None)¶
Mark group with corresponding group_id installed and mark the packages in the group for installation. Return the number of packages that the operation has marked for installation. pkg_types is a sequence of strings determining the kinds of packages to be installed, where the respective groups can be selected by including
"optional"in it. If exclude is given, it has to be an iterable of package name glob patterns:
group_install()will then not mark the respective packages for installation whenever possible.
Mark group with corresponding group_id not installed. All the packages marked as belonging to this group will be marked for removal. Return the number of packages marked for removal in this call.
Upgrade group with corresponding group_id. If there has been packages added to the group’s comps information since installing on the system, they will be marked for installation. Similarly, removed packages get marked for removal. The remaining packages in the group are marked for an upgrade. The operation respects the package types from the original installation of the group.
Read repository configuration from the main configuration file specified by
dnf.conf.Conf.reposdir. All the repositories found this way are added to
Read comps data from all the enabled repositories and initialize the
compsobject. If arch_filter is set to
True, the result is limited to system basearch.
Reset the state of different
Baseattributes. Selecting attributes to reset is controlled by passing the method keyword arguments set to
True. When called with no arguments the method has no effect.
argument passed effect goal=True drop all the current packaging requests repos=True drop the current repositries (see
repos). This won’t affect the package data already loaded into the
sack=True drop the current sack (see
Resolve the marked requirements and store the resulting
dnf.exceptions.DepsolveErroron a depsolving error. Return
Trueif the resolved transaction is non-empty.
Enabling allow_erasing lets the solver remove other packages while looking to fulfill the current packaging requests. For instance, this is used to allow the solver to remove dependants of a package being removed.
The exact operation of the solver further depends on the
Downloads and caches in binary format metadata for all known repos. Tries to avoid downloading whenever possible (e.g. when the local metadata hasn’t expired yet or when the metadata timestamp hasn’t changed).
If ‘timer’ equals ‘True’, DNF becomes more resource-aware, meaning DNF will not do anything if running on battery power and will terminate immediately if it’s too soon after the last successful update_cache operation7.
Baseclass provides a number of methods to make packaging requests that can later be resolved and turned into a transaction. The pkg_spec argument some of them take must be a package specification recognized by
dnf.subject.Subject. If these methods fail to find suitable packages for the operation they raise a
MarkingError. Note that successful completion of these methods does not necessarily imply that the desired transaction can be carried out (e.g. for dependency reasons).
Mark packages matching pkg_spec for downgrade.
Mark packages matching pkg_spec for installation.
If pkg is a
dnf.package.Packagein an available repository, mark the matching installed package for downgrade to pkg. If strict=False it ignores problems with dep-solving.
Mark pkg (a
dnf.package.Packageinstance) for installation. Ignores package that is already installed.
If pkg is a
dnf.package.Packagein an available repository, mark the matching installed package for upgrade to pkg.
Removes all ‘leaf’ packages from the system that were originally installed as dependencies of user-installed packages but which are no longer required by any such package.
Mark packages matching pkg_spec for removal.
Mark packages matching pkg_spec for upgrade.
Mark all installed packages for an upgrade.
urlopen(url, repo=None, mode='w+b', **kwargs):
Open the specified absolute url and return a file object which respects proxy setting even for non-repo downloads