Product SiteDocumentation Site

16.6.2. 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
Method
Returns
A
Returns package architecture
E
Returns package epoch
O
Returns package operating system
R
Returns package release number
V
Returns package version
N
Returns package name
NEVR
Returns package name-epoch-version-release
DS
Returns the package dependency set for a given tag
FI
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: te.py
#!/usr/bin/python
# Adds all package files on command line to a transaction
# and prints out the transaction elements.
# Usage:
# python te.py rpm_file1.rpm rpm_file2.rpm ...
#
import rpm, os, sys
def readRpmHeader(ts, filename):
""" Read an rpm header. """
fd = os.open(filename, os.O_RDONLY)
h = ts.hdrFromFdno(fd)
os.close(fd)
return h
ts = rpm.TransactionSet()
# Set to not verify DSA signatures.
ts.setVSFlags(rpm._RPMVSF_NOSIGNATURES)
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() )
ts.check()
ts.order()
print "This will install:"
for te in ts:
print "%s-%s-%s" % (te.N(), te.V(), te.R() )
The te.py 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.