RPM Control from Python

shaneal smanek at gmail.com
Wed Aug 13 20:50:09 CEST 2008


Hello,

I'm trying to script some sysadmin stuff, that requires rpm
manipulation (querying installed packages, removing packages,
installing packages).

Rather than manually parsing rpm's output, I noticed that someone had
written python-bindings for the rpmlib library (called rpm-python).
This seems much cleaner, but the documentation is sparse, and I
haven't been able to get uninstalling to work.

As root, I run the following:

>>> import rpm
>>> ts=rpm.ts()
>>> ts.addErase("lynx")
>>>

I get no error messages/exceptions, but lynx is not removed.

I've also tried things along the lines of:

>>> mi = ts.dbMatch(rpm.RPMTAG_NAME, "lynx")
>>> for idx in mi:
...     instance = mi.instance()
...     ts.addErase(instance)

and

>>> mi = ts.dbMatch(rpm.RPMTAG_NAME, "lynx")
>>> for idx in mi:
...     ts.addErase(idx)

I've further confirmed that ts.dbMatch(rpm.RPMTAG_NAME, "lynx") does
in fact find the header for the lynx package via something like:
>>> mi = ts.dbMatch(rpm.RPMTAG_NAME, "lynx")
>>> for hdr in mi:
...     print hdr['name'], hdr['version']
...
lynx 2.8.5

The only real documentation I've been able to find is
http://people.redhat.com/pnasrat/rpm-python/rpm-python-slides/frames.html

Is there some other module I should be using for rpm manipulation? Or,
if not, does anyone know what I'm doing wrong with this one?



More information about the Python-list mailing list