Rpmhdr Class Reference
[PYTHON API.]

A python header object represents an RPM package header. More...


Detailed Description

A python header object represents an RPM package header.

All RPM packages have headers that provide metadata for the package. Header objects can be returned by database queries or loaded from a binary package on disk.

The ts.hdrFromFdno() function returns the package header from a package on disk, verifying package signatures and digests of the package while reading.

Note: The older method rpm.headerFromPackage() which has been replaced by ts.hdrFromFdno() used to return a (hdr, isSource) tuple.

If you need to distinguish source/binary headers, do:

        import os, rpm

        ts = rpm.TranssactionSet()
        fdno = os.open("/tmp/foo-1.0-1.i386.rpm", os.O_RDONLY)
        hdr = ts.hdrFromFdno(fdno)
        os.close(fdno)
        if hdr[rpm.RPMTAG_SOURCEPACKAGE]:
           print "header is from a source package"
        else:
           print "header is from a binary package"

The Python interface to the header data is quite elegant. It presents the data in a dictionary form. We'll take the header we just loaded and access the data within it:

        print hdr[rpm.RPMTAG_NAME]
        print hdr[rpm.RPMTAG_VERSION]
        print hdr[rpm.RPMTAG_RELEASE]
in the case of our "foo-1.0-1.i386.rpm" package, this code would output:
  	foo
  	1.0
  	1

You make also access the header data by string name:

        print hdr['name']
        print hdr['version']
        print hdr['release']

This method of access is a teensy bit slower because the name must be translated into the tag number dynamically. You also must make sure the strings in header lookups don't get translated, or the lookups will fail.


The documentation for this class was generated from the following file:
Generated on Fri Oct 12 08:44:57 2007 for rpm by  doxygen 1.5.2