def _get_installed_pkg_objects_dnf(name): dnf_base = pkgmanager.Base() dnf_base.fill_sack(load_system_repo=True, load_available_repos=False) query = dnf_base.sack.query() installed = query.installed() if name: # name__glob provides "shell-style wildcard match" per # https://dnf.readthedocs.io/en/latest/api_queries.html#dnf.query.Query.filter installed = installed.filter(name__glob=name) return list(installed)
def _get_packages_to_update_dnf(reposdir): """Query all the packages with dnf that has an update pending on the system. :param reposdir: The path to the hardcoded repositories for EUS (If any). :type reposdir: str | None """ packages = [] base = pkgmanager.Base() # If we have an reposdir, that means we are trying to check the packages under # CentOS Linux 8.4 or 8.5 and Oracle Linux 8.4. # That means we need to use our hardcoded repository files instead of the system ones. if reposdir: base.conf.reposdir = reposdir # Set DNF to read from the proper config files, at this moment, DNF can't # automatically read and load the config files # so we have to specify it to him. # We set the PRIO_MAINCONFIG as the base config file to be read. # We also set the folder /etc/dnf/vars as the main point for vars # replacement in repo files. # See this bugzilla comment: # https://bugzilla.redhat.com/show_bug.cgi?id=1920735#c2 base.conf.read(priority=pkgmanager.dnf.conf.PRIO_MAINCONFIG) base.conf.substitutions.update_from_etc(installroot=base.conf.installroot, varsdir=base.conf.varsdir) base.read_all_repos() base.fill_sack() # Get a list of all packages to upgrade in the system base.upgrade_all() base.resolve() # Iterate over each and every one of them and append to # the packages list for package in base.transaction: packages.append(package.name) return packages