[Rpm-maint] [rpm-software-management/rpm] Add real-life examples of Python RPM (PR #3177)
Frank Dana
notifications at github.com
Mon Jul 29 23:23:32 UTC 2024
@ferdnyc commented on this pull request.
> @@ -0,0 +1,15 @@
+#!/usr/bin/python
+
+# Query a single installed package by its name.
+# A Python equivalent for `rpm -q hello`
+
+import rpm
+
+name = "hello"
+ts = rpm.TransactionSet()
+mi = ts.dbMatch("name", name)
+hdr = next(mi, None)
+if hdr:
Actually, I take that back. Because `mi` is an iterator, not a list, it will become `False` when exhausted, so that code will always print "No results" at the end of the loop. My mistake.
--
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/pull/3177#discussion_r1696080160
You are receiving this because you are subscribed to this thread.
Message ID: <rpm-software-management/rpm/pull/3177/review/2206295972 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rpm.org/pipermail/rpm-maint/attachments/20240729/08be6de4/attachment.html>
More information about the Rpm-maint
mailing list