### Actions File Configuration Example Source: https://github.com/rpm-software-management/dnf5/blob/main/doc/libdnf5_plugins/actions.8.rst An example configuration file for dnf5 actions, demonstrating setup for various stages like pre-base setup, repository configuration, and transaction handling. ```sh # Prints header with process id pre_base_setup::::/usr/bin/sh -c echo\ -------------------------------------\ >>/tmp/actions-trans.log pre_base_setup::::/usr/bin/sh -c date\ >>/tmp/actions-trans.log pre_base_setup::::/usr/bin/sh -c echo\ libdnf5\ pre_base_setup\ was\ called.\ Process\ ID\ =\ '${pid}'.\ >>/tmp/actions-trans.log pre_base_setup:::enabled=installroot-only:/usr/bin/sh -c echo\ run\ in\ alternative\ "installroot":\ installroot\ =\ '${conf.installroot}'\ >>/tmp/actions-trans.log ``` ```sh # Prints the value of the configuration option "defaultyes". pre_base_setup::::/usr/bin/sh -c echo\ pre_base_setup:\ conf.defaultyes=${conf.defaultyes}\ >>/tmp/actions.log ``` ```sh # Prints a message that the "post_base_setup" callback was called. post_base_setup::::/usr/bin/sh -c echo\ libdnf5\ post_base_setup\ was\ called.\ >>/tmp/actions-trans.log ``` ```sh # Executes the "add_new_repo" application with json communication. # This application, for instance, can add new repository configurations. repos_configured:::mode=json:/usr/local/bin/add_new_repo ``` ```sh # Prints a list of configured repositories with their enable state. repos_configured::::/usr/bin/sh -c echo\ Repositories:\ ${conf.*.enabled}\ >>/tmp/repos.log ``` ```sh # Prints a list of repositories that use the http protocol in baseurl. repos_configured::::/usr/bin/sh -c echo\ "${conf.*.baseurl=*http://*}"\ >>/tmp/baseurl_http.log ``` ```sh # Disables all repositories whose id starts with "rpmfusion". repos_configured::::/usr/bin/sh -c echo\ conf.rpmfusion*.enabled=0 ``` ```sh # Executes the "check_transaction" application with json communication, terminating if the application encounters an error. # This application, for instance, can check for forbidden packages within a transaction and send a stop message. pre_transaction:::mode=json raise_error=1:/usr/local/bin/check_transaction ``` ```sh # Prints the information about the start of the transaction. # Since package_filter is empty, it executes the commands once. pre_transaction::::/usr/bin/sh -c echo\ Transaction\ start.\ Packages\ in\ transaction:\ >>/tmp/actions-trans.log ``` ```sh # Logs all packages (package action, full_nevra, repo id) in transaction into a file. # Uses the shell command "echo" and redirection to a file. pre_transaction:*:::/usr/bin/sh -c echo\ '${pkg.action}'\ '${pkg.full_nevra}'\ '${pkg.repo_id}'\ >>/tmp/actions-trans.log ``` ```sh # Prints the date and time and information about the end of the transaction. # Since package_filter is empty, it executes the commands once. post_transaction::::/usr/bin/sh -c date\ >>/tmp/actions-trans.log post_transaction::::/usr/bin/sh -c echo\ Transaction\ end.\ Repositories\ used\ in\ the\ transaction:\ >>/tmp/actions-trans.log ``` -------------------------------- ### Get Configuration Example Source: https://github.com/rpm-software-management/dnf5/blob/main/doc/libdnf5_plugins/actions.8.rst Demonstrates a request to get the 'countme' configuration value and its successful response. Also shows retrieving all enabled repository configurations. ```json {"op":"get", "domain":"conf", "args":{"key":"countme"}} {"op":"reply", "requested_op":"get", "domain":"conf", "status":"OK", "return":{"keys_val":[{"key":"countme", "value":"0"}]}} ``` ```json {"op": "get", "domain": "conf", "args": {"key": "*.enabled"}} {"op": "reply", "requested_op": "get", "domain": "conf", "status": "OK", "return": { "keys_val": [{"key": "dnf-ci-fedora.enabled", "value": "1"}, {"key": "dnf-ci-fedora-updates.enabled", "value": "1"}, {"key": "dnf-ci-thirdparty.enabled", "value": "0"}, {"key": "test-repo.enabled", "value": "0"}]}} ``` -------------------------------- ### Install libdnf5 Plugin and Configuration Source: https://github.com/rpm-software-management/dnf5/blob/main/test/tutorial-templates/libdnf5-plugin/CMakeLists.txt These commented-out lines show how to install the built plugin and its configuration file to their respective locations. Uncomment and adjust paths as needed for your installation. ```cmake install(TARGETS template_plugin LIBRARY DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/libdnf5/plugins/") install(FILES "template.conf" DESTINATION "${CMAKE_INSTALL_FULL_SYSCONFDIR}/dnf/libdnf5-plugins") ``` -------------------------------- ### DNF5 'repository-packages install' all equivalent Source: https://github.com/rpm-software-management/dnf5/blob/main/doc/changes_from_dnf4.7.rst To install all packages from a repository, use 'dnf5 install --from-repo= "."' instead of 'dnf repository-packages install'. ```bash dnf repository-packages install ``` ```bash dnf5 install --from-repo= '*' ``` -------------------------------- ### Create and Install .pc File Source: https://github.com/rpm-software-management/dnf5/blob/main/libdnf5/CMakeLists.txt Generates the libdnf5.pc file from a template and installs it to the pkgconfig directory. ```cmake configure_file("libdnf5.pc.in" ${CMAKE_CURRENT_BINARY_DIR}/libdnf5.pc @ONLY) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libdnf5.pc DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}/pkgconfig) ``` -------------------------------- ### DNF5 'repository-packages install ...' equivalent Source: https://github.com/rpm-software-management/dnf5/blob/main/doc/changes_from_dnf4.7.rst The 'dnf repository-packages install ...' command is now 'dnf5 install --from-repo= ...'. ```bash dnf repository-packages install ... ``` ```bash dnf5 install --from-repo= ... ``` -------------------------------- ### Install a Package Source: https://github.com/rpm-software-management/dnf5/blob/main/doc/commands/install.8.rst Use this command to install a specific package by its name. DNF5 will resolve and install all necessary dependencies. ```bash dnf5 install tito ``` -------------------------------- ### Install D-Bus Interface XML Files Source: https://github.com/rpm-software-management/dnf5/blob/main/dnf5daemon-server/dbus/CMakeLists.txt Installs D-Bus interface XML files from the interfaces directory, matching files starting with 'org.rpm.dnf.v0.'. ```cmake install( DIRECTORY interfaces/ DESTINATION ${DBUS_SHARE_DIR}/interfaces FILES_MATCHING PATTERN "org.rpm.dnf.v0.*.xml" ) ``` -------------------------------- ### Install D-Bus Configuration File Source: https://github.com/rpm-software-management/dnf5/blob/main/dnf5daemon-server/dbus/CMakeLists.txt Installs the main D-Bus configuration file for the dnf5daemon-server. ```cmake install ( FILES "org.rpm.dnf.v0.conf" DESTINATION ${DBUS_CONFIG_DIR} ) ``` -------------------------------- ### Get Package Paths Example with GLOB Filter Source: https://github.com/rpm-software-management/dnf5/blob/main/doc/libdnf5_plugins/actions.8.rst An example request to retrieve package paths that match a glob pattern, and its corresponding successful response. ```json {"op":"get", "domain":"cmdline_packages_paths", "args":{"filters":[{"key":"path", "value":"/local/*", "operator":"GLOB"}]}} ``` ```json {"op":"reply", "requested_op":"get", "domain":"cmdline_packages_paths", "status":"OK", "return":{"cmdline_packages_paths":["/local/packageB.rpm", "/local/packageC.rpm"]}} ``` -------------------------------- ### List Installed and Available Packages Source: https://github.com/rpm-software-management/dnf5/blob/main/doc/commands/list.8.rst Use this command to see all installed packages and all packages available in enabled repositories. ```bash dnf5 list ``` -------------------------------- ### Install Systemd and D-Bus Service Files Source: https://github.com/rpm-software-management/dnf5/blob/main/dnf5daemon-server/dbus/CMakeLists.txt Installs the dnf5daemon-server systemd service file and the D-Bus service file when WITH_SYSTEMD is enabled. ```cmake if (WITH_SYSTEMD) install ( FILES "dnf5daemon-server.service" DESTINATION ${SYSTEMD_UNIT_DIR} ) install ( FILES "org.rpm.dnf.v0.service" DESTINATION ${DBUS_SHARE_DIR}/system-services ) endif() ``` -------------------------------- ### Install reposync command plugin Source: https://github.com/rpm-software-management/dnf5/blob/main/dnf5-plugins/reposync_plugin/CMakeLists.txt Installs the compiled reposync command plugin library to the appropriate directory for dnf5 plugins and installs its configuration files. ```cmake install(TARGETS reposync_cmd_plugin LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}/dnf5/plugins/) install(DIRECTORY "config/usr/" DESTINATION "${CMAKE_INSTALL_PREFIX}") ``` -------------------------------- ### Get Variable Example Source: https://github.com/rpm-software-management/dnf5/blob/main/doc/libdnf5_plugins/actions.8.rst Example demonstrating a request to retrieve variables matching 'test_var*' and its successful response, showing a single matching variable. ```json {"op":"get", "domain":"vars", "args":{"name":"test_var*"}} {"op":"reply", "requested_op":"get", "domain":"vars", "status":"OK", "return":{"vars":[{"name":"test_var1", "value":"value1"}]}} ``` -------------------------------- ### Install Debuginfo Packages Source: https://github.com/rpm-software-management/dnf5/blob/main/doc/commands/debuginfo-install.8.rst Use this command to install the debuginfo packages for a specific package like 'foobar'. ```bash dnf debuginfo-install foobar ``` -------------------------------- ### Install Plugin Source: https://github.com/rpm-software-management/dnf5/blob/main/dnf5-plugins/needs_restarting_plugin/CMakeLists.txt Installs the built plugin to the dnf5 plugins directory. ```cmake install(TARGETS needs_restarting_cmd_plugin LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}/dnf5/plugins/) ``` -------------------------------- ### Install build requirements from a spec file Source: https://github.com/rpm-software-management/dnf5/blob/main/doc/dnf5_plugins/builddep.8.rst Use this command to install the necessary build requirements defined within a specified .spec file. ```bash dnf builddep foobar.spec ``` -------------------------------- ### Set Configuration Value Example Source: https://github.com/rpm-software-management/dnf5/blob/main/doc/libdnf5_plugins/actions.8.rst An example of setting a global configuration option 'countme' to '1' and its successful response. ```json {"op":"set", "domain":"conf", "args":{"key":"countme", "value":"1"}} {"op":"reply", "requested_op":"set", "domain":"conf", "status":"OK", "return":{"keys_val":[{"key":"countme", "value":"1"}]}} ``` -------------------------------- ### List Packages Matching a Pattern Source: https://github.com/rpm-software-management/dnf5/blob/main/doc/commands/list.8.rst Use this command to list installed and available packages whose names match a specified pattern, such as starting with 'kernel'. ```bash dnf5 list kernel* ``` -------------------------------- ### Get Configuration Value Request Source: https://github.com/rpm-software-management/dnf5/blob/main/doc/libdnf5_plugins/actions.8.rst Example request to retrieve a global configuration option. Use a repository ID to fetch a specific repository's configuration. ```json {"op":"get", "domain":"conf", "args":{"key":""}} ``` ```json {"op":"get", "domain":"conf", "args":{"key":"."}} ``` -------------------------------- ### Install Builddep Command Plugin Source: https://github.com/rpm-software-management/dnf5/blob/main/dnf5-plugins/builddep_plugin/CMakeLists.txt Installs the builddep_cmd_plugin library to the dnf5 plugins directory. ```cmake install(TARGETS builddep_cmd_plugin LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}/dnf5/plugins/) ``` -------------------------------- ### Install Plugin Library Source: https://github.com/rpm-software-management/dnf5/blob/main/test/tutorial-templates/dnf5-plugin/CMakeLists.txt Installs the compiled plugin library to the DNF5 plugins directory. ```cmake install(TARGETS template_dnf5_cmd_plugin LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}/dnf5/plugins/) ``` -------------------------------- ### Install DNF5 Configuration Directory Source: https://github.com/rpm-software-management/dnf5/blob/main/libdnf5/CMakeLists.txt Installs an empty directory intended for libdnf5 distribution drop-in configuration files. ```cmake install(DIRECTORY DESTINATION "${CMAKE_INSTALL_PREFIX}/share/dnf5/libdnf.conf.d") ``` -------------------------------- ### Install Automatic Plugin Source: https://github.com/rpm-software-management/dnf5/blob/main/dnf5-plugins/automatic_plugin/CMakeLists.txt Installs the compiled automatic_cmd_plugin library to the dnf5 plugins directory. Also installs configuration files. ```cmake install(TARGETS automatic_cmd_plugin LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}/dnf5/plugins/) install(DIRECTORY "config/usr/share" DESTINATION "${CMAKE_INSTALL_PREFIX}") if (WITH_SYSTEMD) install(DIRECTORY "config/usr/lib" DESTINATION "${CMAKE_INSTALL_PREFIX}") endif() install(PROGRAMS bin/dnf-automatic TYPE BIN) ``` -------------------------------- ### Install Local RPM File Source: https://github.com/rpm-software-management/dnf5/blob/main/doc/commands/install.8.rst Install a package directly from a local RPM file. Provide the full path to the file. ```bash dnf5 install ~/Downloads/tito-0.6.21-1.fc36.noarch.rpm ``` -------------------------------- ### Python 3 Query Example Source: https://github.com/rpm-software-management/dnf5/blob/main/doc/tutorial/bindings/python3/queries.rst This snippet shows a complete example of how to perform queries using the DNF5 Python 3 bindings. It includes session creation, repository loading, and various query operations. ```python from dnf5_python import Dnf5 def query_packages(): dnf5 = Dnf5() # Load repositories (optional, but recommended for actual package queries) # dnf5.load_repositories() # Example: Query for a specific package print("\n--- Querying for 'bash' ---") query = dnf5.query results = query.name('bash').run() for pkg in results: print(f"Found package: {pkg.name} (Version: {pkg.version})") # Example: Query for packages with a specific name pattern print("\n--- Querying for packages starting with 'lib' ---") results = query.name('lib*').run() print(f"Found {len(results)} packages starting with 'lib'.") # Example: Query for packages providing a capability print("\n--- Querying for packages providing 'sh' ---") results = query.provides('sh').run() for pkg in results: print(f"Package '{pkg.name}' provides 'sh'.") # Example: Query for installed packages print("\n--- Querying for installed packages ---") results = query.installed().run() print(f"Found {len(results)} installed packages.") # Example: Query for packages in a specific repository # Note: This requires repositories to be loaded and available. # print("\n--- Querying for packages in 'fedora' repository ---") # results = query.repo('fedora').run() # print(f"Found {len(results)} packages in the 'fedora' repository.") # Example: Combining queries (e.g., installed and name pattern) print("\n--- Querying for installed packages starting with 'python3-' ---") results = query.installed().name('python3-*').run() print(f"Found {len(results)} installed packages starting with 'python3-'.") if __name__ == "__main__": query_packages() ``` -------------------------------- ### Install repoclosure command plugin Source: https://github.com/rpm-software-management/dnf5/blob/main/dnf5-plugins/repoclosure_plugin/CMakeLists.txt Installs the compiled plugin library to the dnf5 plugins directory. ```cmake install(TARGETS repoclosure_cmd_plugin LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}/dnf5/plugins/) ``` -------------------------------- ### DNF5 'repository-packages info --installed' equivalent Source: https://github.com/rpm-software-management/dnf5/blob/main/doc/changes_from_dnf4.7.rst The 'dnf repository-packages info --installed [...]' command is now 'dnf5 info --installed-from-repo= [...]'. ```bash dnf repository-packages info --installed [...] ``` ```bash dnf5 info --installed-from-repo= [...] ``` -------------------------------- ### DNF5 'repository-packages list --installed' equivalent Source: https://github.com/rpm-software-management/dnf5/blob/main/doc/changes_from_dnf4.7.rst The 'dnf repository-packages list --installed [...]' command is now 'dnf5 list --installed-from-repo= [...]'. ```bash dnf repository-packages list --installed [...] ``` ```bash dnf5 list --installed-from-repo= [...] ``` -------------------------------- ### Install build requirements for a package from repositories Source: https://github.com/rpm-software-management/dnf5/blob/main/doc/dnf5_plugins/builddep.8.rst This command looks up a package in enabled repositories and installs the build requirements for its corresponding source RPM. ```bash dnf builddep foobar-1.0-1 ``` -------------------------------- ### Install Distribution-Supplied Plugin Configuration Directory Source: https://github.com/rpm-software-management/dnf5/blob/main/libdnf5/CMakeLists.txt Creates an empty directory for distribution-supplied plugin configuration files. This directory is installed in the package's share directory. ```cmake install(DIRECTORY DESTINATION "${CMAKE_INSTALL_PREFIX}/share/dnf5/libdnf.plugins.conf.d") ``` -------------------------------- ### Install libdnf5-plugins Configuration Directory Source: https://github.com/rpm-software-management/dnf5/blob/main/libdnf5/CMakeLists.txt Makes an empty directory for libdnf5-plugins configuration files. This directory is installed within the system's configuration path. ```cmake install(DIRECTORY DESTINATION "${CMAKE_INSTALL_FULL_SYSCONFDIR}/dnf/libdnf5-plugins") ``` -------------------------------- ### Install build requirements from a source RPM file Source: https://github.com/rpm-software-management/dnf5/blob/main/doc/dnf5_plugins/builddep.8.rst This command installs the build requirements for a package by referencing its source RPM file. ```bash dnf builddep foobar-1.0-1.src.rpm ``` -------------------------------- ### Python 3 Transaction Example Source: https://github.com/rpm-software-management/dnf5/blob/main/doc/tutorial/bindings/python3/transaction.rst This example demonstrates resolving dependencies and executing a transaction using Python 3 bindings. Ensure you have a DNF session configured and repositories loaded before running. ```python from dnf5_py import * def main(): session = Session() # Load repositories (example) # session.add_repo_file("/etc/dnf/dnf.conf") # session.add_repo_file("/etc/yum.repos.d/fedora.repo") # Example: Install a package transaction = session.create_transaction() transaction.add("example-package") transaction.run() # Example: Remove a package # transaction = session.create_transaction() # transaction.remove("another-package") # transaction.run() # Example: Update all packages # transaction = session.create_transaction() # transaction.update() # transaction.run() if __name__ == "__main__": main() ``` -------------------------------- ### Download Package with Dependencies Source: https://github.com/rpm-software-management/dnf5/blob/main/doc/commands/download.8.rst Download a package and all of its dependencies, including those that are already installed. ```bash dnf5 download maven-compiler-plugin --resolve --alldeps ``` -------------------------------- ### Install Package for Specific Architecture Source: https://github.com/rpm-software-management/dnf5/blob/main/doc/misc/forcearch.7.rst Use this command to install a package for a specified architecture, regardless of your host system's architecture. Ensure the target architecture is supported or emulated. ```bash dnf5 install --forcearch=aarch64 my-example-package ``` -------------------------------- ### Default User Agent String Example Source: https://github.com/rpm-software-management/dnf5/blob/main/doc/dnf5.conf.5.rst This example shows the default User-Agent string format used by DNF5, which includes OS identifiers. The components NAME, VERSION_ID, VARIANT_ID, OS, and BASEARCH are dynamically read from the system's os-release file. ```text libdnf (NAME VERSION_ID; VARIANT_ID; OS.BASEARCH) ``` ```text libdnf (Fedora 39; server; Linux.x86_64) ``` -------------------------------- ### Add a repository from a file Source: https://github.com/rpm-software-management/dnf5/blob/main/doc/dnf5_plugins/config-manager.8.rst Download a repository configuration file and place it in the repository configuration directory. This command tests the file before adding it. ```bash dnf5 config-manager addrepo --from-repofile=http://example.com/some/additional.repo ``` -------------------------------- ### DNF4 Python: Loading Repositories Source: https://github.com/rpm-software-management/dnf5/blob/main/doc/tutorial/api-changes/repos.rst Demonstrates how to read system repositories, create and add a new repository, and then load all repositories in DNF4. ```python # Optionally, read repositories from system configuration files. base.read_all_repos() # Optionally, create and configure a new repository. repo = dnf.repo.Repo("my_new_repo_id", base.conf) repo.baseurl = [baseurl] base.repos.add(repo) # Load repositories. To limit which repositories are loaded, pass # load_system_repo=False or load_available_repos=False. base.fill_sack() ``` -------------------------------- ### Getting packages information Source: https://github.com/rpm-software-management/dnf5/blob/main/doc/libdnf5_plugins/actions.8.rst Retrieve information about available, installed, or transaction packages. ```APIDOC ## Getting packages information ### Description Retrieve information about available, installed, or transaction packages using the 'packages' or 'trans_packages' domains. ### Request Format ```json { "op": "get", "domain": "packages", "args": {"output": [""]} } ``` ```json { "op": "get", "domain": "packages", "args": {"output": [""], "params": [{"key": ""}]} } ``` ```json { "op": "get", "domain": "packages", "args": {"output": [""], "filters": [{"key": "", "value": "", "operator": ""}]} } ``` ```json { "op": "get", "domain": "packages", "args": {"output": [""], "params": [{"key": ""}], "filters": [{"key": "", "value": "", "operator": ""}]} } ``` ```json { "op": "get", "domain": "trans_packages", "args": {"output": [""]} } ``` ```json { "op": "get", "domain": "trans_packages", "args": {"output": [""], "params": [{"key": ""}]} } ``` ```json { "op": "get", "domain": "trans_packages", "args": {"output": [""], "filters": [{"key": "", "value": "", "operator": ""}]} } ``` ```json { "op": "get", "domain": "trans_packages", "args": {"output": [""], "params": [{"key": ""}], "filters": [{"key": "", "value": "", "operator": ""}]} } ``` ### Response Format ```json { "op": "reply", "requested_op": "get", "domain": "packages", "status": "OK", "return": {"packages": [{"": ""}]} } ``` ```json { "op": "reply", "requested_op": "get", "domain": "trans_packages", "status": "OK", "return": {"trans_packages": [{"": ""}]} } ``` ```json { "op": "reply", "requested_op": "get", "domain": "packages", "status": "ERROR", "message": "" } ``` ```json { "op": "reply", "requested_op": "get", "domain": "trans_packages", "status": "ERROR", "message": "" } ``` ### Parameters * `` - Package attribute to return (e.g., 'name'). * `` - Name of the parameter. * `` - Name of the filter. * `` - Value for the filter. * `` - Comparison operator for the filter. ### Notes The `trans_packages` domain is restricted to `goal_resolved`, `pre_transaction`, and `post_transaction` callbacks. ``` -------------------------------- ### DNF5 'repository-packages info --all' equivalent Source: https://github.com/rpm-software-management/dnf5/blob/main/doc/changes_from_dnf4.7.rst The 'dnf repository-packages info [--all] [...]' command's behavior is approximated in DNF5 by 'dnf5 info --installed-from-repo= [...]' for installed packages and 'dnf5 --repo= info --available [...]' for available packages. DNF5 includes installed packages in the available list, color-coded for reinstallation. ```bash dnf repository-packages info [--all] [...] ``` ```bash dnf5 info --installed-from-repo= [...] ``` ```bash dnf5 --repo= info --available [...] ``` -------------------------------- ### Example LIBDNF5 Passive Plugin Implementation Source: https://github.com/rpm-software-management/dnf5/blob/main/doc/tutorial/plugins/libdnf5-plugins.rst Implement the libdnf5::plugin::IPlugin interface and override hooks to alter DNF5's logic at specific breakpoints. This example shows logic insertion after base object preparation and before transaction start. ```c++ #include #include #include namespace dnf5 { namespace plugin { class TemplatePlugin : public IPlugin { public: TemplatePlugin(Base& base) : base_(base) {} void postBaseInit() override { // Logic after preparing the libdnf5::Base object base_.debug("TemplatePlugin: postBaseInit called"); } void preTransaction() override { // Logic before the start of the transaction base_.debug("TemplatePlugin: preTransaction called"); } private: Base& base_; }; extern "C" { std::unique_ptr create(Base& base) { return std::make_unique(base); } } } } ``` -------------------------------- ### Get Package Information Source: https://github.com/rpm-software-management/dnf5/blob/main/doc/libdnf5_plugins/actions.8.rst Retrieve information about available, installed, or transaction packages. The 'trans_packages' domain is restricted to specific callback phases. ```json {"op":"get", "domain":"packages", "args":{"output":[""]}} ``` ```json {"op":"get", "domain":"packages", "args":{"output":[""], "params":[{"key":""}]}} ``` ```json {"op":"get", "domain":"packages", "args":{"output":[""], "filters":[{"key":"", "value":"", "operator":""}]}} ``` ```json {"op":"get", "domain":"packages", "args":{"output":[""], "params":[{"key":""}], "filters":[{"key":"", "value":"", "operator":""}]}} ``` ```json {"op":"get", "domain":"trans_packages", "args":{"output":[""]}} ``` ```json {"op":"get", "domain":"trans_packages", "args":{"output":[""], "params":[{"key":""}]}} ``` ```json {"op":"get", "domain":"trans_packages", "args":{"output":[""], "filters":[{"key":"", "value":"", "operator":""}]}} ``` ```json {"op":"get", "domain":"trans_packages", "args":{"output":[""], "params":[{"key":""}], "filters":[{"key":"", "value":"", "operator":""}]}} ``` ```json {"op":"reply", "requested_op":"get", "domain":"packages", "status":"OK", "return":{"packages":[{"":""}]}} ``` ```json {"op":"reply", "requested_op":"get", "domain":"trans_packages", "status":"OK", "return":{"trans_packages":[{"":""}]}} ``` ```json {"op":"reply", "requested_op":"get", "domain":"packages", "status":"ERROR", "message":""} ``` ```json {"op":"reply", "requested_op":"get", "domain":"trans_packages", "status":"ERROR", "message":""} ``` -------------------------------- ### DNF5 'repository-packages list [--all]' equivalent Source: https://github.com/rpm-software-management/dnf5/blob/main/doc/changes_from_dnf4.7.rst The 'dnf repository-packages list [--all] [...]' command's behavior is approximated in DNF5 by 'dnf5 list --installed-from-repo= [...]' for installed packages and 'dnf5 --repo= list --available [...]' for available packages. DNF5 includes installed packages in the available list, color-coded for reinstallation. ```bash dnf repository-packages list [--all] [...] ``` ```bash dnf5 list --installed-from-repo= [...] ``` ```bash dnf5 --repo= list --available [...] ``` -------------------------------- ### Install Specific Package Version Source: https://github.com/rpm-software-management/dnf5/blob/main/doc/commands/install.8.rst Install a package to a specific version. If the package is already installed, DNF5 will attempt to downgrade or upgrade to the specified version. ```bash dnf5 install tito-0.6.21-1.fc36 ``` -------------------------------- ### DNF5 'repository-packages info --extras' equivalent Source: https://github.com/rpm-software-management/dnf5/blob/main/doc/changes_from_dnf4.7.rst The 'dnf repository-packages info --extras [...]' command is replaced by 'dnf5 repoquery --info --installed-from-repo= --extras [...]'. DNF5's 'info' command does not support combining '--installed-from-repo' with '--extras', necessitating the use of 'repoquery'. ```bash dnf repository-packages info --extras [...] ``` ```bash dnf5 repoquery --info --installed-from-repo= --extras [...] ``` -------------------------------- ### Define Tutorial Executable Source: https://github.com/rpm-software-management/dnf5/blob/main/test/tutorial/CMakeLists.txt Creates an executable target named 'run_tests_tutorial' using the found C++ source files. This executable will be used to run the tutorial tests. ```cmake add_executable(run_tests_tutorial ${TEST_TUTORIAL_SOURCES}) ``` -------------------------------- ### Install libdnf5 Shared Library Source: https://github.com/rpm-software-management/dnf5/blob/main/libdnf5/CMakeLists.txt Specifies the installation directory for the libdnf5 shared library. ```cmake install(TARGETS libdnf5 LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}) ``` -------------------------------- ### Example Plugin Configuration File Source: https://github.com/rpm-software-management/dnf5/blob/main/doc/tutorial/plugins/libdnf5-plugins.rst Mandatory configuration file for a LIBDNF5 plugin, defining its name and enablement during runtime. Options include 'no', 'yes', 'host-only', and 'installroot-only'. ```cfg [template] name = template enabled = yes ``` -------------------------------- ### DNF5 'repository-packages list --extras' equivalent Source: https://github.com/rpm-software-management/dnf5/blob/main/doc/changes_from_dnf4.7.rst The 'dnf repository-packages list --extras [...]' command is replaced by 'dnf5 repoquery --installed-from-repo= --extras [...]'. DNF5's 'list' command does not support combining '--installed-from-repo' with '--extras', necessitating the use of 'repoquery'. ```bash dnf repository-packages list --extras [...] ``` ```bash dnf5 repoquery --installed-from-repo= --extras [...] ``` -------------------------------- ### Install config-manager plugin Source: https://github.com/rpm-software-management/dnf5/blob/main/dnf5-plugins/config-manager_plugin/CMakeLists.txt Installs the config-manager_cmd_plugin target as a shared library into the dnf5 plugins directory. ```cmake install(TARGETS config-manager_cmd_plugin LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}/dnf5/plugins/) ``` -------------------------------- ### Get All Repository Information Source: https://github.com/rpm-software-management/dnf5/blob/main/doc/commands/repo.8.rst Use this command to display detailed information about all repositories configured on the system, regardless of their enabled status. ```bash dnf5 repo info --all ``` -------------------------------- ### Install Changelog Plugin Source: https://github.com/rpm-software-management/dnf5/blob/main/dnf5-plugins/changelog_plugin/CMakeLists.txt Installs the compiled changelog_cmd_plugin library to the appropriate dnf5 plugins directory. ```cmake install(TARGETS changelog_cmd_plugin LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}/dnf5/plugins/) ``` -------------------------------- ### Print Available Upgrades with Severities (Python) Source: https://github.com/rpm-software-management/dnf5/blob/main/doc/dnf_daemon/examples.rst Lists all available upgrades, their source repositories, and the severity of associated advisories. Ensure the script is run with appropriate permissions. ```Python import dnf5_pb2 import dnf5_client def print_upgrades_with_severities(): """Print all available upgrades, the repository they come from and severity of associated advisory if present.""" with dnf5_client.Dnf5Client() as client: for upgrade in client.get_upgrades(): print(f"Package: {upgrade.name}\nRepo: {upgrade.repo}\nSeverity: {upgrade.severity}\n") if __name__ == "__main__": print_upgrades_with_severities() ``` -------------------------------- ### Install Manifest Plugin Source: https://github.com/rpm-software-management/dnf5/blob/main/dnf5-plugins/manifest_plugin/CMakeLists.txt Installs the compiled manifest_cmd_plugin as a shared library to the dnf5 plugins directory. ```cmake install(TARGETS manifest_cmd_plugin LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}/dnf5/plugins/) ``` -------------------------------- ### DNF5 Template Command Help Output Source: https://github.com/rpm-software-management/dnf5/blob/main/doc/templates/template-command.rst Example output of the dnf5 template --help command, detailing its specific options. ```text $ dnf5 template --help Usage: dnf5 [GLOBAL OPTIONS] template [OPTIONS] Options: --bar print bar --foo print foo ``` -------------------------------- ### DNF5 Global Help Output Source: https://github.com/rpm-software-management/dnf5/blob/main/doc/templates/template-command.rst Example output of the dnf5 --help command, showing the newly added 'template' command. ```text $ dnf5 --help ... Software Management Commands: install Install software upgrade Upgrade software ... template A command that prints its name and arguments' name ``` -------------------------------- ### DNF5 'repository-packages info --available' equivalent Source: https://github.com/rpm-software-management/dnf5/blob/main/doc/changes_from_dnf4.7.rst The 'dnf repository-packages info --available [...]' command is now 'dnf5 --repo= info --available [...]'. DNF5 includes installed packages in the available list, color-coded for reinstallation. ```bash dnf repository-packages info --available [...] ``` ```bash dnf5 --repo= info --available [...] ``` -------------------------------- ### Load a Custom Repository with Python 3 Source: https://github.com/rpm-software-management/dnf5/blob/main/doc/tutorial/bindings/python3/repos.rst This snippet demonstrates how to load a single custom repository. Provide the path to your repository file. ```python import dnf5 session = dnf5.session.Session() # Load a custom repository from a file # Replace '/etc/my_custom_repo.repo' with the actual path to your .repo file session.load_repo_from_file('/etc/my_custom_repo.repo') for repo in session.get_repos(): print(f"Loaded repository: {repo.id}") ``` -------------------------------- ### DNF5 'repository-packages list --available' equivalent Source: https://github.com/rpm-software-management/dnf5/blob/main/doc/changes_from_dnf4.7.rst The 'dnf repository-packages list --available [...]' command is now 'dnf5 --repo= list --available [...]'. DNF5 includes installed packages in the available list, color-coded for reinstallation. ```bash dnf repository-packages list --available [...] ``` ```bash dnf5 --repo= list --available [...] ``` -------------------------------- ### bgettext CP_ Macro Example Source: https://github.com/rpm-software-management/dnf5/blob/main/include/libdnf5/utils/bgettext/README.md Example usage of the CP_ macro for marking strings. These strings are intended for translation. ```c label1 = CP_("Vehicles", "Bus", "Buses", n); label2 = CP_("Signal", "Bus", "Buses", n); ``` -------------------------------- ### Install Packages by Advisory Source: https://github.com/rpm-software-management/dnf5/blob/main/doc/commands/install.8.rst Install all packages associated with a specific advisory. This is useful for applying a set of related updates or fixes. ```bash dnf5 install --advisory=FEDORA-2022-07aa56297a \* ``` -------------------------------- ### Configure DNF5 Base in Python Source: https://github.com/rpm-software-management/dnf5/blob/main/doc/tutorial/api-changes/session.rst Demonstrates setting configuration options for a DNF5 Base object using property access. ```python import dnf5 b = dnf5.Base() b.conf.skip_unavailable = True b.conf.best_match = False b.conf.allow_vendor_change = True b.conf.autodetect_provides = True b.conf.download_dir = "/tmp/dnf5-download" b.conf.install_root = "/tmp/dnf5-root" b.conf.log_dir = "/tmp/dnf5-log" b.conf.log_level = 1 b.conf.log_path = "/tmp/dnf5.log" b.conf.max_parallel_downloads = 10 b.conf.max_concurrent_downloads = 5 b.conf.max_installonlypkgs = 3 b.conf.module_defaults = "Everything" b.conf.module_stream_polarity = "strict" b.conf.module_verify = True b.conf.nogpgcheck = False b.conf.overwrite_existing = False b.conf.package_dir = "/tmp/dnf5-packages" b.conf.plugin_path = ["/tmp/dnf5-plugins"] b.conf.protected_packages = ["kernel", "glibc"] b.conf.read_only = False b.conf.repo_gpgcheck = True b.conf.reset_metadata = False b.conf.retries = 10 b.conf.skip_broken = False b.conf.skip_unavailable = False b.conf.substitutions = {"a": "b"} b.conf.tsflags = ["test"] b.conf.use_delta = "automatic" b.conf.user_agent = "My DNF5 Client" b.conf.gpgcheck = True ``` -------------------------------- ### Get Operation: Reading Variable Values Source: https://github.com/rpm-software-management/dnf5/blob/main/doc/libdnf5_plugins/actions.8.rst Details on how to use the 'get' operation with the 'vars' domain to read the values of variables. ```APIDOC ### Reading a variable value *Request format:* ```json {"op":"get", "domain":"vars", "args":{"name":""}} ``` *Response format:* ```json {"op":"reply", "requested_op":"get", "domain":"vars", "status":"OK", "return":{"vars":[{"name":"", "value":""}]}} ``` *Description:* * ```` - the name of the variable; in a request, it can contain globs, in which case the value of all matching variables will be read * ```` - the read value of the variable The number of ``vars`` items in the response depends on the number of matching variables. *Example:* ```json {"op":"get", "domain":"vars", "args":{"name":"test_var*"}} {"op":"reply", "requested_op":"get", "domain":"vars", "status":"OK", "return":{"vars":[{"name":"test_var1", "value":"value1"}]}} ``` ``` -------------------------------- ### Install DNF5 Man Pages Source: https://github.com/rpm-software-management/dnf5/blob/main/doc/CMakeLists.txt Installs various DNF5 man pages to the share/man/man8 directory. This is typically done during the build process. ```cmake install(FILES ${CMAKE_CURRENT_BINARY_DIR}/man/dnf5-automatic.8 DESTINATION share/man/man8) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/man/dnf5-builddep.8 DESTINATION share/man/man8) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/man/dnf5-changelog.8 DESTINATION share/man/man8) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/man/dnf5-config-manager.8 DESTINATION share/man/man8) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/man/dnf5-copr.8 DESTINATION share/man/man8) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/man/dnf5-needs-restarting.8 DESTINATION share/man/man8) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/man/dnf5-repoclosure.8 DESTINATION share/man/man8) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/man/dnf5-repomanage.8 DESTINATION share/man/man8) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/man/dnf5-reposync.8 DESTINATION share/man/man8) ``` -------------------------------- ### List All Available Package Versions Source: https://github.com/rpm-software-management/dnf5/blob/main/doc/commands/list.8.rst This command lists all available versions of packages, not just the latest one, from enabled repositories. ```bash dnf5 list --available --showduplicates ``` -------------------------------- ### List Repositories in JSON Format Source: https://github.com/rpm-software-management/dnf5/blob/main/doc/commands/repo.8.rst This command outputs a JSON array where each object describes an available repository. The output includes fields like 'id', 'name', and 'is_enabled'. ```bash dnf5 repo list --json ``` -------------------------------- ### Install Ruby Build Dependencies Source: https://github.com/rpm-software-management/dnf5/blob/main/doc/tutorial/install-build-deps.rst Install the Ruby bindings and CLI modules for libdnf5. These packages are necessary for integrating libdnf5 functionality into Ruby applications. ```bash $ dnf install ruby-libdnf5 ruby-libdnf5-cli ``` -------------------------------- ### Add a new repository with a specified baseurl Source: https://github.com/rpm-software-management/dnf5/blob/main/doc/dnf5_plugins/config-manager.8.rst Create a new repository configuration file with a specified baseurl. The repository ID and target filename are automatically generated from the baseurl. ```bash dnf5 config-manager addrepo --set=baseurl=http://example.com/different/repo ``` -------------------------------- ### Install dnf5 Header Files with Relative Paths Source: https://github.com/rpm-software-management/dnf5/blob/main/dnf5/include/dnf5/CMakeLists.txt This snippet finds all header files and installs them into the include/dnf5 directory, maintaining their original directory structure. ```cmake file(GLOB_RECURSE DNF5_HEADERS *.hpp *.h) # preserve relative paths of the header files foreach(abspath ${DNF5_HEADERS}) # relative path to the header file file(RELATIVE_PATH relpath ${CMAKE_CURRENT_SOURCE_DIR} ${abspath}) # dirname of the relative path get_filename_component(relpath_dir ${relpath} DIRECTORY) install(FILES ${abspath} DESTINATION include/dnf5/${relpath_dir}) endforeach() ``` -------------------------------- ### Download Package by Architecture Source: https://github.com/rpm-software-management/dnf5/blob/main/doc/commands/download.8.rst Download a package specifically for a given architecture. ```bash dnf5 download python --arch x86_64 ```