[Yum-devel] Using yum as deps checker

Richard W.M. Jones rjones at redhat.com
Mon Mar 30 13:42:18 UTC 2009


On Mon, Mar 30, 2009 at 02:21:22PM +0100, Stephen Childs wrote:
> Basically I would like to be able to pass a transaction set into YUM and  
> get back a list of the extra packages that need to be added to resolve  
> dependencies.

This is something that's so obvious, yet there is no command line way
to do it that I could find.  I used the following Python snippet
(actually created originally by Seth Vidal):

import yum
import yum.misc
import sys

yb = yum.YumBase ()

basepkg = yb.pkgSack.returnPackages (patterns=[sys.argv[1]])[0]
deps = dict ({basepkg:False})

# Recursively find all the dependencies.
stable = False
while not stable:
    stable = True
    for pkg in deps.keys():
        if deps[pkg] == False:
            deps[pkg] = []
            stable = False
            for r in pkg.requires:
                ps = yb.whatProvides (r[0], r[1], r[2])
                best = yb._bestPackageFromList (ps.returnPackages ())
                if best.name != pkg.name:
                    deps[pkg].append (best)
                    if not deps.has_key (best):
                        deps[best] = False
            deps[pkg] = yum.misc.unique (deps[pkg])

for pkg in deps.keys ():
    print "%s: " % pkg,
    for p in deps[pkg]:
        print "%s " % p,
    print ""

Save the above to a file and do:

  python deps.py glibc

for example.

I really wish there was a way to suppress the "Loaded plugins" line.
It's also really slow.  Suggestions how to speed it up are welcome.

Rich.

-- 
Richard Jones, Emerging Technologies, Red Hat  http://et.redhat.com/~rjones
virt-p2v converts physical machines to virtual machines.  Boot with a
live CD or over the network (PXE) and turn machines into Xen guests.
http://et.redhat.com/~rjones/virt-p2v


More information about the Yum-devel mailing list