[Yum-devel] Using yum as deps checker

Seth Vidal skvidal at fedoraproject.org
Mon Mar 30 13:50:17 UTC 2009



On Mon, 30 Mar 2009, Richard W.M. Jones wrote:

> 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.
>

First - this isn't dep solving b/c it doesn't check it against the running 
system. It is entirely doing it against what is available in the repos not 
anything w/the rpmdb.

Second - this isn't as fast as resolveDeps b/c resolveDeps is optimized a 
great deal more than the above calls.

Third - if you want to suppress the loaded plugins line - then change your 
yum debuglevel (in yum.conf or in code) to be 1.

-sv



More information about the Yum-devel mailing list