Need an example program that implements rpm -pql via import rpm

Daniel Mahoney catdude at gmail.com
Fri Mar 4 10:24:26 EST 2011


On Thu, 03 Mar 2011 22:24:24 -0500, Steven W. Orr wrote:

> I look everywhere but I couldn't find anything. Could someone please
> point me to a small example program that does an import rpm, takes an
> rpm file as an argument and gets the list of files contained in the
> file, the same as if I had used the commandline
> 
> rpm -pql foo-1.23-4.i586.rpm
> 
> Much appreciated.
> 
> TIA

This is just a quick and dirty script, but how about:

import os
import rpm
import sys

ts = rpm.TransactionSet()
fd = os.open(sys.argv[1], os.O_RDONLY)
h = ts.hdrFromFdno(fd)
os.close(fd)

flist = h.fiFromHeader()
for file in flist:
    print file[0]



Dan



More information about the Python-list mailing list