Creating a build chroot with rpm-python

"Albert Strasheim" <13640887-/[email protected]> Sat, 16 Apr 2005 13:57:19 +0200
Newsgroups gmane.linux.redhat.rpm.python
Message-ID <[email protected]>
Hello all,

I am trying to set up a build chroot using rpm-python.

I have the following basic script:

#!/usr/bin/env python

import rpm
import os

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

    def callback(self, what, amount, total, mydata, wibble):
        if rpm.RPMCALLBACK_CPIO_ERROR:
            print 'cpio error'
            print mydata
        elif rpm.RPMCALLBACK_INST_CLOSE_FILE:
            print 'inst close file'
            hdr, path = mydata
            nvr = '%s-%s-%s' % (hdr['name'], hdr['version'], hdr['release'])
            os.close(self.fdnos[nvr])
        elif rpm.RPMCALLBACK_INST_OPEN_FILE:
            print 'inst open file'
            hdr, path = mydata
            fd = os.open(path, os.O_RDONLY)
            nvr = '%s-%s-%s' % (hdr['name'], hdr['version'], hdr['release'])
            self.fdnos[nvr] = fdno
            print fd
            return fd
        elif rpm.RPMCALLBACK_INST_PROGRESS:
            print 'inst progress'
        elif rpm.RPMCALLBACK_INST_START:
            print 'inst start'
        elif rpm.RPMCALLBACK_REPACKAGE_PROGRESS:
            print 'repackage progress'
        elif rpm.RPMCALLBACK_REPACKAGE_START:
            print 'repackage start'
        elif rpm.RPMCALLBACK_REPACKAGE_STOP:
            print 'repackage stop'
        elif rpm.RPMCALLBACK_TRANS_PROGRESS:
            print 'trans progress'
        elif rpm.RPMCALLBACK_TRANS_START:
            print 'trans start'
        elif rpm.RPMCALLBACK_TRANS_STOP:
            print 'trans stop'
        elif rpm.RPMCALLBACK_UNINST_PROGRESS:
            print 'uninst progress'
        elif rpm.RPMCALLBACK_UNINST_START:
            print 'uninst start'
        elif rpm.RPMCALLBACK_UNINST_STOP:
            print 'uninst stop'
        elif rpm.RPMCALLBACK_UNKNOWN:
            print 'unknown'
        elif rpm.RPMCALLBACK_UNPACK_ERROR:
            print 'unpack error'
            pass
        pass

def main():
    bldimage = '/home/albert/bldimage'
    if not os.path.exists(bldimage):
        os.makedirs(bldimage)
    ts = rpm.ts(bldimage, rpm._RPMVSF_NOSIGNATURES)
    rpmloc = '/home/albert/setup-2.5.36-1.noarch.rpm'
    fdno = os.open(rpmloc, os.O_RDONLY)
    hdr = ts.hdrFromFdno(fdno)
    os.close(fdno)
    ts.addInstall(hdr, (hdr, rpmloc), 'i')
    errors = ts.check()
    if errors:
        print errors
        sys.exit(1)
    ts.order()
    cb = myCallback()
    errors = ts.run(cb.callback, '')
    if errors:
        print errors
        sys.exit(1)
    pass

if __name__ == '__main__':
    main()

This should simply unpack the setup-2.5.36-1 rpm in /home/albert/bldimage.
However, when I run it, I get the following:

cpio error
None
cpio error
None
cpio error
None
cpio error
(<rpm.hdr object at 0xb7f0e860>, '/home/albert/setup-2.5.36-1.noarch.rpm')
Traceback (most recent call last):
  File "/home/albert/lunglet/rpmpybork.py", line 81, in ?
    main()
  File "/home/albert/lunglet/rpmpybork.py", line 74, in main
    errors = ts.run(cb.callback, '')
TypeError: an integer is required

Running with strace shows the call to chroot() followed by a bunch of calls 
to stat64() and lstat64() for the directories and files in the package. 
These all return ENOENT (No such file or directory).

What am I doing wrong? Is there some way I can get debug information from 
rpm-python so I can figure out what is going on?

Thanks.

Regards,

Albert

P.S. This code is basically the same as the stuff in Tree Tools:

http://linux.duke.edu/projects/mini/treetools/