Product SiteDocumentation Site

Transaction elements

Transaction sets are made up of transaction elements. A transaction element makes up one part of a transaction and holds one package per operation (install or remove) in each transaction set. That is, there is one transaction element per package per operation in the transaction set. You can iterate over a transaction set to get each transaction element. Once you have a transaction element, you can call methods on each element to check entries in the header as well as get dependency sets for the package.
Table 17-4 lists the informational methods you can call on a transaction element. Most of the methods listed in Table 17-4 return a single value.
Table 17-4 Informational methods on transaction sets
Returns package architecture
Returns package epoch
Returns package operating system
Returns package release number
Returns package version
Returns package name
Returns package name-epoch-version-release
Returns the package dependency set for a given tag
Returns the file info set for the package
For more complex checking, the DS method returns the package dependency set for a given tag:
ds = te.DS(tag_name)
Pass one of 'Providename', 'Requirename', 'Obsoletename', or 'Conflictname' for the tag name. For example:
ds = te.DS('Requirename')
The FI method returns the file info set for the package:
fi = te.FI(tag_name)
For the FI method, you must pass a tag name of 'Basenames'.
As an example, Listing 17-6 shows how to iterate through a transaction set to get transaction elements.
Listing 17-6:
# Adds all package files on command line to a transaction
# and prints out the transaction elements.
# Usage:
# python rpm_file1.rpm rpm_file2.rpm ...

import os
import sys

import rpm

def readRpmHeader(ts, filename):
    """ Read an rpm header. """
    fd =, os.O_RDONLY)
        h = ts.hdrFromFdno(fd)
    return h

ts = rpm.TransactionSet()

# Set to not verify DSA signatures.

for filename in sys.argv[1:]:
    h = readRpmHeader(ts, filename)
    print "Installing %s-%s-%s" % (h['name'], h['version'], h['release'])
    ts.addInstall(h, filename, 'i')

print "This will install:"
for te in ts:
    print "%s-%s-%s" % (te.N(), te.V(), te.R() )


print "This will install:"
for te in ts:
    print "%s-%s-%s" % (te.N(), te.V(), te.R() )
The script sets up a transaction and then prints out the elements, never completing the transaction. The purpose here is just to show what is in the transaction. The second set of printed output shows the results of the check and order methods, covered in the following section.