Repository Configuration

class dnf.repodict.RepoDict

Dictionary mapping repository IDs to the respective dnf.repo.Repo objects. Derived from the standard dict.

add(repo)

Add a Repo to the repodict.

add_new_repo(repoid, conf, baseurl=(), \*\*kwargs)

Initialize new Repo object and add it to the repodict. It requires repoid (string), and dnf.conf.Conf object. Optionally it can be specified baseurl (list), and additionally key/value pairs from kwargs to set additional attribute of the Repo object. Variables in provided values (baseurl or kwargs) will be automatically substituted using conf.substitutions (like $releasever, …). It returns the Repo object.

all()

Return a list of all contained repositories.

See the note at get_matching() for special semantics of the returned object.

enable_debug_repos()

Enable debug repos corresponding to already enabled binary repos.

enable_source_repos()

Enable source repos corresponding to already enabled binary repos.

get_matching(key)

Return a list of repositories which ID matches (possibly globbed) key or an empty list if no matching repository is found.

The returned list acts as a composite, transparently forwarding all method calls on itself to the contained repositories. The following thus disables all matching repos:

#!/usr/bin/python3
import dnf

base = dnf.Base()
base.read_all_repos()
base.fill_sack()

repos = base.repos.get_matching('*-debuginfo')
repos.disable()
iter_enabled()

Return an iterator over all enabled repos from the dict.

dnf.repo.repo_id_invalid(repo_id)

Return index of the first invalid character in the repo_id or None if all characters are valid. This function is used to validate the section names in .repo files.

class dnf.repo.Metadata

Represents the metadata files.

fresh

Boolean. True if the metadata was loaded from the origin, False if it was loaded from the cache.

class dnf.repo.Repo

Repository object used for metadata download. To configure it properly one has to give it either metalink, mirrorlist or baseurl parameter. This object has attributes corresponding to all configuration options from both “Repo Options” and “Options for both [main] and Repo” sections.

Important

Some Repo attributes have non-native Python types. Duck typing works (objects have identical behavior), but isinstance() and type() doesn’t work as expected because of different types. For example excludepkgs and includepkgs return a VectorString, which is s SWIG wrapper on top of underlying libdnf C++ code.

id

ID of this repo. This attribute is read-only.

metadata

If load() has been called and succeeded, this contains the relevant Metadata instance.

pkgdir

Directory where packages of a remote repo will be downloaded to. By default it is derived from cachedir in __init__() but can be overridden by assigning to this attribute.

repofile

The path to configuration file of the class.

__init__(name=None, parent_conf=None)

Init repository with ID name and the parent_conf which an instance of dnf.conf.Conf holding main dnf configuration. Repository ID must be a string that can contain ASCII letters, digits, and -_.: characters.

add_metadata_type_to_download(metadata_type)

Ask for additional repository metadata type to download. Given metadata_type is appended to the default metadata set when repository is downloaded.

disable()

Disable the repository. Repositories are enabled by default.

dump()

Print repository configuration, including inherited values.

enable()

Enable the repository (the default).

get_http_headers()

Return user defined http headers. Return tuple of strings.

get_metadata_content(metadata_type)

Return contents of the repository’s metadata file of the given metadata type. Contents of compressed files are returned uncompressed.

get_metadata_path(metadata_type)

Return path to the file with downloaded repository metadata of given type.

load()

Load the metadata of this repository. Will try to use local cache if possible and initiate and finish download if not. Returns True if fresh metadata has been downloaded and False if cache was used. Raises dnf.exceptions.RepoError if the repo metadata could not be obtained.

set_http_headers(headers)

Set new user headers and rewrite existing ones. headers must be an instance of tuple of strings or list of strings.

set_or_append_opt_value(name, value_string, priority=PRIO_RUNTIME).

For standard repository options, sets the value of the option if the priority is equal to or higher than the current priority. For “append” options, appends the values parsed from value_string to the current list of values. If the first parsed element of the list of values is empty and the priority is equal to or higher than the current priority, the current list is replaced with the new values. If the priority is higher than the current priority, the current priority is increased to the priority. Raises dnf.exceptions.ConfigError if the option with the given name does not exist or value_string contains an invalid value or not allowed value.

set_progress_bar(progress)

Set the download progress reporting object for this repo during load(). progress must be an instance of dnf.callback.DownloadProgress.