A python header object represents an RPM package header. More...
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 headerFromPackage function loads the package header from a package on disk. It returns a tuple of a "isSource" flag and the header object. The "isSource" flag is set to 1 if the package header was read from a source rpm or to 0 if the package header was read from a binary rpm.
For example:
import os, rpm fd = os.open("/tmp/foo-1.0-1.i386.rpm", os.O_RDONLY) (header, isSource) = rpm.headerFromPackage(fd) fd.close()
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:
in the case of our "foor-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 header['name']
This method of access is a 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.