formatting output in rpm-python?
Armijn Hemel <[email protected]> Fri, 16 Jan 2004 12:12:14 +0100
| Newsgroups | gmane.linux.redhat.rpm.python |
|---|---|
| Message-ID | <[email protected]> |
hello,
I'm playing around a bit with the Python bindings for RPM. I made a small
script which only pulls from the database what a package requires,
nothing fancy. But, unlike for example 'rpm -qR <package-name>' I get
some extra output.
<code>
#!/usr/bin/python
import os, sys, rpm
def readRpmHeader(ts, filename):
fd = os.open(filename, os.O_RDONLY)
h = ts.hdrFromFdno(fd)
os.close(fd)
return h
rpm.addMacro("_dbpath",
"/usr/lib/rpmdb/i386-redhat-linux/redhat")
redhatts = rpm.TransactionSet()
redhatts.openDB()
mi = redhatts.dbMatch('name', sys.argv[1])
for h in mi:
print "%s-%s-%s" % (h['name'], h['version'], h['release'])
print h.dsFromHeader('requirename')
</code>
If I run this script, called rpmquery.py, for example like this:
$ ./rpmquery.py rpm
I get as output lines like this:
R textutils
It prepends this `R ', which `rpm -qR' does not. I've done some digging
in the RPM source, but I can't find where it gets prepended. To be
honest, I find it a bit annoying that this kind of formatting is already
done for me by the software. I don't think this `R ' is actually
present in the RPM database itself (please correct me if I'm wrong).
Is there a workaround for this, apart from stripping the first two
characters? And where exactly in the source is this stuff prepended (if
that is the case)?
thanks in advance,
armijn
--
---------------------------------------------------------------------------
[email protected] | http://www.uulug.nl/ | UULug: Utrecht Linux Users Group
---------------------------------------------------------------------------