Help with python api, accessing missing "requires" fields from a .src.rpm

Panu Matilainen pmatilai at
Mon Sep 12 07:05:07 UTC 2011

On 09/12/2011 06:03 AM, Thomas Dziedzic wrote:
> Hello,
> I'm trying to use the rpm python api and I have a question about retrieving
> info from hdrFromFdno
> I do hdr = hdrFromFdno(fd), and then I get back a hdr object with lots of
> data.
> The problem is that it seems that hdr lacks the Requires: parts of the .spec
> file. Everything else seems to be there, including the BuildRequires.
> The fd is for "rpm-4.8.0-16.el6.src.rpm" which I got from
> hdr[rpm.RPMTAG_REQUIRES] seems to be the BuildRequires portion of the .spec
> when I search for coreutils (one of the Requires packages) in the hdr by
> doing: for k in hdr: if isinstance(hdr[k], collections.Iterable): if
> 'coreutils' in hdr[k]: print k I get nothing

This is the expected behavior: the source rpm does not carry any 
information about the binary package(s) that might get produced from it. 
The only meaningful requires for a source rpm are its build-requires really.

The information about binary packages is only present in the binary 
packages themselves. Some of that information can be retrieved by 
parsing the *spec* from an srpm, and inspecting that. For example taking 
the above rpm-4.8.0-16.el6.src.rpm, unpack it and then you can do:

 >>> import rpm
 >>> spec = rpm.spec("rpm.spec")
 >>> for p in spec.packages:
...     print p.header['requires']
['coreutils', 'db4-utils', 'popt', 'curl', '/bin/sh']
['rpm', 'libcap(x86-64)', '/sbin/ldconfig', '/sbin/ldconfig']
['rpm', 'popt-devel(x86-64)', 'file-devel(x86-64)']
['rpm', 'elfutils', 'binutils', 'findutils', 'sed', 'grep', 'gawk', 
'diffutils', 'file', 'patch', 'unzip', 'gzip', 'bzip2', 'cpio', 'lzma', 
'xz', 'pkgconfig', '/usr/bin/gdb-add-index']
['crontabs', 'logrotate', 'rpm']

Do note that the headers from a parsed spec will miss lots of 
information: there are no file lists, no autogenerated dependencies etc. 
For those you need to look at the actual binary packages.

	- Panu -

More information about the Rpm-list mailing list