Product SiteDocumentation Site

Running the transaction

After setting up the transaction set, perform the transaction by calling run. You need to provide two parameters:
ts.run(callback, client_data)
The callback parameter must be a Python function. The client_data is any data you want to pass to the callback. There may be more than one package in the transaction set, so this data should not be specific to a particular package.
Warning
You must not pass None as the client_data or you will get a Python error.

Transaction run Method Callbacks

The callback you pass to the run method on a transaction set is essential. Your callback must work properly, or the transaction will fail. You must provide a callback.
Your callback will get called a number of times, mostly as a means to report progress. If you are writing a graphical user interface, for example, you can use the progress callbacks to update a visual progress meter.
The basic syntax for the transaction set run callback is:
def runCallback(reason, amount, total, key, client_data):
    # Do your stuff...
    pass
The key is the data you provided in the call to the addInstall method. The client_data is the data you passed to the run method.
Each time your callback is called, the transaction set will provide a reason flag. Table 17-5 lists the values for the reason parameter.
Table 17-5 Transaction set run callback reason values
Value
Reason
rpm.RPMCALLBACK_UNKNOWN
Unknown problem
rpm.RPMCALLBACK_INST_PROGRESS
Progress for installation
rpm.RPMCALLBACK_INST_START
Start of installation
rpm.RPMCALLBACK_INST_OPEN_FILE
Callback should open package file
rpm.RPMCALLBACK_INST_CLOSE_FILE
Callback should close package file
rpm.RPMCALLBACK_TRANS_PROGRESS
Transaction progress
rpm.RPMCALLBACK_TRANS_START
Transaction start
rpm.RPMCALLBACK_TRANS_STOP
Transaction stop
rpm.RPMCALLBACK_UNINST_PROGRESS
Uninstallation progress
rpm.RPMCALLBACK_UNINST_START
Uninstallation start
rpm.RPMCALLBACK_UNINST_STOP
Uninstallation stop
rpm.RPMCALLBACK_REPACKAGE_PROGRESS
Repackaging progress
rpm.RPMCALLBACK_REPACKAGE_START
Repackaging start
rpm.RPMCALLBACK_REPACKAGE_STOP
Repackaging stop
rpm.RPMCALLBACK_UNPACK_ERROR
Error unpacking package file
rpm.RPMCALLBACK_CPIO_ERROR
cpio error getting package payload
Your callback must handle at least two cases: a reason value of rpm.RPMCALLBACK_INST_OPEN_FILE and rpm.RPMCALLBACK_INST_CLOSE_FILE.
With the reason of rpm.RPMCALLBACK_INST_OPEN_FILE, you must open the RPM package file and return a file descriptor for the file. You need to keep this file descriptor in a global-scope or otherwise-accessible variable, because with the reason of rpm.RPMCALLBACK_INST_CLOSE_FILE, you must close this file.