[Rpm-maint] [rpm-software-management/rpm] Add real-life examples of Python RPM (PR #3177)

Panu Matilainen notifications at github.com
Mon Jun 24 09:30:02 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), {})

You'll need to supply a callback that handles at least file open and close (rpm.RPMCALLBACK_INST_OPEN_FILE and rpm.RPMCALLBACK_INST_CLOSE_FILE), based on the key you supply. It's all ... rather arcane.

See "Callbacks" and the following slides in https://web.archive.org/web/20050320013335/http://www.ukuug.org/events/linux2004/programme/paper-PNasrat-1/rpm-python-slides/frames.html

-- 
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/pull/3177#discussion_r1650675811
You are receiving this because you are subscribed to this thread.

Message ID: <rpm-software-management/rpm/pull/3177/review/2135197132 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rpm.org/pipermail/rpm-maint/attachments/20240624/04f53e14/attachment.html>


More information about the Rpm-maint mailing list