Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dnf): use repoquery #1392

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 27 additions & 24 deletions meta_package_manager/managers/dnf.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,50 +50,53 @@ class DNF(PackageManager):

pre_args = ("--color=never",)

list_cmd_regexp = re.compile(r"(\S+)\.\S+\s+(\S+)\s+\S+")
DELEMITER = "___MPM___"

@property
def installed(self) -> Iterator[Package]:
"""Fetch installed packages.

.. code-block:: shell-session

► dnf --color=never list --installed
► dnf repoquery --userinstalled --qf FORMAT
Installed Packages
acl.x86_64 2.2.53-1.el8 @anaconda
audit.x86_64 3.0-0.10.20180831git0047a6c.el8 @anaconda
audit-libs.x86_64 3.0-0.10.20180831git0047a6c.el8 @anaconda
acl 2.2.53-1.el8 annaconda_dummary x86_64
audit 2.2.53-1.el8 audit_dummary x86_64
audit-libs 2.2.53-1.el8 audit_libs_dummary x86_64
(...)
"""
output = self.run_cli("list", "--installed")
qf = ["%{name}", "%{version}", "%{summary}", "%{arch}"]
output = self.run_cli("repoquery", "--userinstalled", "--qf", DNF.DELEMITER.join(qf))

for package in output.splitlines()[1:]:
match = self.list_cmd_regexp.match(package)
if match:
package_id, installed_version = match.groups()
yield self.package(id=package_id, installed_version=installed_version)
for line_package in output.splitlines():
package_id, installed_version, summary, arch = line_package.split(DNF.DELEMITER)
yield self.package(id=package_id, description=summary, installed_version=installed_version, arch=arch)

@property
def outdated(self) -> Iterator[Package]:
"""Fetch outdated packages.

.. code-block:: shell-session

► dnf --color=never list --upgrades
Last metadata expiration check: 0:22:12 ago on Sun 03 Apr 2022.
Available Upgrades
acl.x86_64 2.2.53-1.el8 updates
audit.x86_64 3.0-0.10.20180831git0047a6c.el8 updates
audit-libs.x86_64 3.0-0.10.20180831git0047a6c.el8 updates
► dnf repoquery --upgrades --qf FORMAT
Installed Packages
acl 2.2.53-1.el8 2.6.53-1.el8 annaconda_dummary x86_64
audit 2.2.53-1.el8 2.5.53-1.el8 audit_dummary x86_64
audit-libs 2.2.53-1.el8 2.6.53-1.el8 audit_libs_dummary x86_64
(...)
"""
output = self.run_cli("list", "--upgrades")

for package in output.splitlines()[2:]:
match = self.list_cmd_regexp.match(package)
if match:
package_id, latest_version = match.groups()
yield self.package(id=package_id, latest_version=latest_version)
qf = ["%{name}", "%{version}", "%{evr}", "%{summary}", "%{arch}"]
output = self.run_cli("repoquery", "--upgrades", "--qf", DNF.DELEMITER.join(qf))

for line_package in output.splitlines():
package_id, installed_version, last_version, summary, arch = line_package.split(DNF.DELEMITER)
yield self.package(
id=package_id,
description=summary,
installed_version=installed_version,
arch=arch,
latest_version=last_version,
)

@search_capabilities(extended_support=False, exact_support=False)
def search(self, query: str, extended: bool, exact: bool) -> Iterator[Package]:
Expand Down
Loading