1. Changes in setting up the Base
Both DNF4 and DNF5 have a class Base, which is the central point of functionality.
In DNF5, a libdnf5::Base::setup method must be called after configuration and variables are updated, but before loading repositories and it cannot be called multiple times. It loads libdnf plugins, resolves configuration of protected packages and also loads variables, so it replaces also the dnf.conf.substitutions.Substitutions.update_from_etc method.
DNF4 Python:
1import dnf
2
3# Create a new Base object.
4base = dnf.Base()
5
6# Optionally, load configuration from the file defined in the current
7# configuration.
8base.conf.read()
9
10# Optionally, load variables.
11base.conf.substitutions.update_from_etc("/")
DNF5 Python:
1import libdnf5
2
3# Create a new Base object.
4base = libdnf5.base.Base()
5
6# Optionally, load configuration from the file defined in the current
7# configuration and files in the drop-in directories.
8base.load_config()
9
10# Load variables and do other initialization based on the configuration.
11base.setup()
DNF5 C++:
1#include <libdnf5/base/base.hpp>
2
3// Create a new Base object.
4libdnf5::Base base;
5
6// Optionally, load configuration from the file defined in the current
7// configuration and files in the drop-in directories.
8base.load_config();
9
10// Load variables and do other initialization based on the configuration.
11base.setup();
Setting of configuration and variables should be done before calling the libdnf5::Base::setup in DNF5.
In Python, there are shortcuts for getting or setting the configuration options using the configuration class attributes (e.g. instead of get_skip_unavailable_option().get_value() and get_skip_unavailable_option().set() there is a property skip_unavailable. To access all methods from the option, use standard getters as in C++ API.
DNF5 Python:
1# Get or set configuration options.
2config = base.get_config()
3config.skip_unavailable = True
4print(config.skip_unavailable)
5
6# Get or set values of variables.
7vars = base.get_vars()
8vars.set("releasever", "42")
9print(vars.get_value("releasever"))
DNF5 C++:
1// Get or set configuration options.
2auto & config = base.get_config();
3config.get_skip_unavailable_option().set(true);
4std::cout << config.get_skip_unavailable_option().get_value() << std::endl;
5
6// Get or set a value of a variable, e.g.:
7auto vars = base.get_vars();
8vars->set("releasever", "42");
9std::cout << vars->get_value("releasever") << std::endl;