rpm -qf questions

James Antill james at fedoraproject.org
Sun Apr 12 16:21:36 UTC 2009

On Fri, 2009-04-10 at 15:12 -0700, Tan wrote:
> hello all,
> firstly, i have a particular need to quickly query for package info
> given a batch of files so, i've tried the following:
> rpm -qf `cat files.list` --nodigest --nosignature
> where files.list contains approximately 650 files. this query took 1s
> on my machine to complete while repeatedly invoking the same query for
> each filename took 1 min.  however, rpm man page doesn't mention the
> -f (--file) option can take a list of files so i'm quite hesitant to
> use this in my script. can i reliably depend on this behavior?
> secondly, i'd like to have the package name and the filename used in
> the query to be printed in the format <package-name>:<filename>, so
> i've added a --qf '%{NAME}:%{FILENAMES}\n' to the query. this does
> what i want but it seems like a strange thing to do as FILENAMES is a
> list and should be enclosed in the [ ] brackets.  i've read the doc
> and my usage should output something similarly to <package-name>:
> (array)  instead.  how can i print out the package name and filename
> properly?  thanks alot.

#! /usr/bin/python -tt

import sys
import yum

if len(sys.argv) < 2:

yb = yum.YumBase()

for line in open(sys.argv[1]):
    line = line[:-1]
    found = False
    for pkg in yb.rpmdb.searchPrco(line, 'provides'):
        found = True
        print "%s:%s" % (pkg, line)
    if not found:
        print "<unknown>:%s" % line

...if you can't use the yum API, then looking at the above should give
you hints on how to convert to the rpm-python API. And if you can't use
python, that should give you hints on how to use the C API instead.

James Antill - james at fedoraproject.org
"I'd just like to see a realistic approach to updates via
 packages." -- Les Mikesell

More information about the Rpm-list mailing list