2. Changes in loading repositories
The repositories are loaded in order to have information about installed and available packages, comps,@IF WITH_MODULEMD@ modules,@ENDIF@ and excludes.
In DNF5, the repositories must be loaded only after the libdnf5::base::Base::setup() call and they cannot be loaded repeatedly. If a new set of repositories is needed, a new Base object should be created.
DNF4 Python:
1# Optionally, read repositories from system configuration files.
2base.read_all_repos()
3
4# Optionally, create and configure a new repository.
5repo = dnf.repo.Repo("my_new_repo_id", base.conf)
6repo.baseurl = [baseurl]
7base.repos.add(repo)
8
9# Load repositories. To limit which repositories are loaded, pass
10# load_system_repo=False or load_available_repos=False.
11base.fill_sack()
DNF5 Python:
1repo_sack = base.get_repo_sack()
2
3# Optionally, read repositories from system configuration files.
4repo_sack.create_repos_from_system_configuration()
5
6# Optionally, create and configure a new repository.
7repo = repo_sack.create_repo("my_new_repo_id")
8repo.get_config().baseurl = baseurl
9
10# Load repositories. To limit which repositories are loaded, pass
11# a repository type (e.g. libdnf5.repo.Repo.Type_SYSTEM).
12repo_sack.load_repos()
DNF5 C++:
1auto repo_sack = base.get_repo_sack();
2
3// Optionally, read repositories from system configuration files.
4repo_sack->create_repos_from_system_configuration();
5
6// Optionally, create and configure a new repository.
7auto repo = repo_sack->create_repo("my_new_repo_id");
8repo->get_config().get_baseurl_option().set(baseurl);
9
10// Load repositores. To limit which repositories are loaded, pass
11// a repository type (e.g. libdnf5.repo.Repo.Type_SYSTEM).
12repo_sack->load_repos();