I'm using the snippet of code below in order to resolve dependencies
from a list of packages, and it works fine.

However there are some problems I can't work out how to fix:

(1) How do I emulate the '--quiet' command line option, ie. make it so
that the yum libraries don't send lots of messages to stdout (which
conflicts with the list that I want to write to stdout).

(2) When I run this as non-root, it works, *unless* the yum repo is
not up to date.  If the yum repo is not up to date then it fails
because it tries to download and overwrite package lists in a
root-owned directory.  Now obviously other tools eg. yumdownloader
work fine as non-root.  How can I fix that?

(3) How can I make it use a non-default location for the yum
configuration (instead of /etc/yum.conf /etc/yum.repos.d/*)?
Alternately emulate --disablerepo/--enablerepo on the command line?

Thanks,

Rich.

----------------------------------------------------------------------
import yum
import yum.misc
import sys

yb = yum.YumBase ()
#yum.logginglevels.setDebugLevel(0) -- doesn't work?

# Look up the base packages from the command line.
deps = dict ()
pkgs = yb.pkgSack.returnPackages (patterns=sys.argv[2:])
for pkg in pkgs:
    deps[pkg] = 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])

f = open (sys.argv[1], \"w\")
for pkg in deps.keys ():
    f.write (\"%s %s %s %s %s\\n\" %
             (pkg.name, pkg.epoch, pkg.version, pkg.release, pkg.arch))
f.close ()


-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-top is 'top' for virtual machines.  Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://et.redhat.com/~rjones/virt-top
_______________________________________________
Yum-devel mailing list
[email protected]
http://lists.baseurl.org/mailman/listinfo/yum-devel

Reply via email to