[Rpm-maint] [rpm-software-management/rpm] Add real-life examples of Python RPM (PR #3177)
Panu Matilainen
notifications at github.com
Mon Jun 24 10:21:48 UTC 2024
@pmatilai commented on this pull request.
> @@ -0,0 +1,15 @@
+#!/usr/bin/python3
+
+# Install a package from a file stored on your system.
+# A Python equivalent for `rpm -i hello-2.12.1-4.fc40.x86_64.rpm`
+
+import os
+import rpm
+
+ts = rpm.TransactionSet()
+path = "/tmp/hello-2.12.1-4.fc40.x86_64.rpm"
+with open(path, "r") as fp:
+ filename = os.path.basename(path)
+ hdr = ts.hdrFromFdno(fp.fileno())
+ ts.addInstall(hdr, filename, "i")
+ts.run(lambda *args: print(args), {})
That said, the callback example actually sets a rather bad example: you don't want to use a header in the key, because it wastes enormous amounts of memory. If you want output a NEVRA in the callback, pass that string instead.
--
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/pull/3177#discussion_r1650766922
You are receiving this because you are subscribed to this thread.
Message ID: <rpm-software-management/rpm/pull/3177/review/2135358362 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rpm.org/pipermail/rpm-maint/attachments/20240624/29b8d843/attachment.html>
More information about the Rpm-maint
mailing list