I have an embedded platform on which I deploy application code using RPMs. Traditionally this was done after the fact on the target platform (i.e. installing rpm via command line on the target platform through a console). To make life easier and simpler (or so I thought), I decided to directly install the RPM onto the target filesystem as part of the build process on the host. I thought to use the Python RPM module and interacting with the RPM database that resides on the target filesystem. Here's what I tried (note that the RPM database location has been modified to point to the database on the target filesystem as opposed to the default on the host):
Code:
import os, rpm
rpmtsCallback_fd = None
def runCallback(reason, amount, total, key, client_data):
global rpmtsCallback_fd
print 'callback called with reason' + str(reason)
if reason == rpm.RPMCALLBACK_INST_OPEN_FILE:
print "Opening file."
rpmtsCallback_fd = os.open(key, os.O_RDONLY)
return rpmtsCallback_fd
elif reason == rpm.RPMCALLBACK_INST_CLOSE_FILE:
print "Closing file"
os.close(rpmtsCallback_fd)
rpm.addMacro("_dbpath", "/home/mbilloo/test_rfs/var/lib/rpm/")
trs = rpm.TransactionSet()
fdno = os.open("/home/mbilloo/test_rfs/application.rpm", os.O_RDONLY)
hdr = trs.hdrFromFdno(fdno)
os.close(fdno)
print 'Installing ' + str(hdr['name']) + ' to RFS'
trs.addInstall(hdr, "/home/mbilloo/test_rfs/application.rpm", 'u')
unresolved_deps = trs.check()
if unresolved_deps:
print "Have unresolved dependencies: %s" % (unresolved_deps,)
exit
trs.order()
trs.run(runCallback, None)
mi = trs.dbMatch()
print 'size of mi = ' + str(len(mi))
for h in mi:
print h['name']
A few interesting things happen. First, the RPM database in the target filesystem doesn't get populated (len returned is 0). Secondly, my callback does not get called with reason rpm.RPMCALLBACK_INST_OPEN_FILE nor rpm.RPMCALLBACK_INST_CLOSE_FILE. It first gets called with reason rpm.RPMCALLBACK_TRANS_START, then with reason rpm.RPMCALLBACK_TRANS_PROGRESS, then finally with reason rpm.RPMCALLBACK_TRANS_STOP. Why doesn't the RPM actually get installed into the database after the transaction occurs?