How set the prefix when install a rpm using python.

Jorge Cisneros jorgecis at
Wed Nov 23 17:08:15 UTC 2016

Hi All

  I using something similar to the follow example to install a rpm from
python, and works fine. Now the problem that I have is how to change the
prefix, something like rpm -i --prefix ....

   Any ideas?



import rpm
import sys
import os

class myCallback(object):
    def __init__(self):
        self._fd = None

    def callback(self, event, amount, total, key, mydata):
        if event == rpm.RPMCALLBACK_INST_OPEN_FILE:
            print "Installing", key
            self._fd =, os.O_RDONLY)
            return self._fd
        elif event == rpm.RPMCALLBACK_INST_CLOSE_FILE:
            self._fd = os.close(self._fd)

if __name__ == '__main__':
    for path in sys.argv[1:]:
        fd =, os.O_RDONLY)
        hdr = ts.hdrFromFdno(fd)
        ts.addInstall(hdr, path, 'u')

    if ts.problems():
        rc = 1
        cb = myCallback()
        rc = (, None) != None)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Rpm-list mailing list