Callbacks

Callbacks

To get progress status and hook in at other stages in a transaction you need to use a callback

class simpleCallback:
    def __init__(self):
        self.fdnos = {}

    def callback(self, what, amount, total, mydata, wibble):
    	"""what -- callback type, amount -- 
        if what == rpm.RPMCALLBACK_TRANS_START:
            pass

        elif what == rpm.RPMCALLBACK_INST_OPEN_FILE:
            hdr, path = mydata
            print "Installing %s\r" % (hdr["name"])
            fd = os.open(path, os.O_RDONLY)
            nvr = '%s-%s-%s' % ( hdr['name'], hdr['version'], hdr['release'] )
            self.fdnos[nvr] = fdno
            return fd

	elif what == rpm.RPMCALLBACK_INST_CLOSE_FILE:
            hdr, path = mydata
            nvr = '%s-%s-%s' % ( hdr['name'], hdr['version'], hdr['release'] )
            os.close(self.fdnos[nvr])

        elif what == rpm.RPMCALLBACK_INST_PROGRESS:
            hdr, path = mydata
            print "%s:  %.5s%% done\r" % (hdr["name"], (float(amount) / total) * 100)