monkut
monkut

Reputation: 43832

Find rpm dependencies using python yum/rpm API?

It seems like it should be available, but I just can't seem to find it.

Something like:

pkg = rpm.Package(name="some package")
dependencies = pkg.dependencies()

Is there something like this available, that would be cleaner than what I'm doing now?

Currently, I'm wrapping the rpm command with subprocess and manually parsing the output:

cmd = "rpm -qRp {file} | sort | uniq".format(file=filename)
cmd_output = subprocess.check_output(cmd, shell=True)
# ... long parse of cmd_output

Upvotes: 0

Views: 2319

Answers (1)

Stan
Stan

Reputation: 2599

Following scipt will list all Requires from a package provided on commandline (full path to rpm file):

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)

for dep in h[rpm.RPMTAG_REQUIRENAME]:
    print dep

Or alternatively to work with package in rpm database:

import os
import rpm
import sys

ts = rpm.TransactionSet()
mi = ts.dbMatch('name', sys.argv[1])
for ind in range(mi.count()):
    h = mi.next()
    for dep in h[rpm.RPMTAG_REQUIRENAME]:
        print dep

Upvotes: 6

Related Questions