[Yum-devel] [PATCH] Return objects from the rpmdb.check_* functions, so it's easier to add more

Tim Lauridsen tim.lauridsen at googlemail.com
Tue Jan 5 10:09:30 UTC 2010


On Mon, Jan 4, 2010 at 9:10 PM, James Antill <james at and.org> wrote:

> ---
>  yum/__init__.py |   19 ++++++++-----------
>  yum/rpmsack.py  |   45 +++++++++++++++++++++++++++++++++++++++++----
>  2 files changed, 49 insertions(+), 15 deletions(-)
>
> diff --git a/yum/__init__.py b/yum/__init__.py
> index 48be3e8..d87c180 100644
> --- a/yum/__init__.py
> +++ b/yum/__init__.py
> @@ -1073,23 +1073,20 @@ class YumBase(depsolve.Depsolve):
>             out(_('Warning: RPMDB altered outside of yum.'))
>
>         rc = 0
> +        probs = []
>         if chkcmd in ('all', 'dependencies'):
>             prob2ui = {'requires' : _('missing requires'),
>                        'conflicts' : _('installed conflict')}
> -            for (pkg, prob, ver, opkgs) in
> self.rpmdb.check_dependencies():
> -                rc += 1
> -                if opkgs:
> -                    opkgs = ": " + ', '.join(map(str, opkgs))
> -                else:
> -                    opkgs = ''
> -                out("%s %s %s%s" % (pkg, prob2ui[prob], ver, opkgs))
> +            probs.extend(self.rpmdb.check_dependencies())
>
>         if chkcmd in ('all', 'duplicates'):
>             iopkgs = set(self.conf.installonlypkgs)
> -            for (pkg, prob, opkg) in self.rpmdb.check_duplicates(iopkgs):
> -                rc += 1
> -                out(_("%s is a duplicate of %s") % (pkg, opkg))
> -        return rc
> +            probs.extend(self.rpmdb.check_duplicates(iopkgs))
> +
> +        for prob in sorted(probs):
> +            out(prob)
> +
> +        return len(probs)
>
>     def runTransaction(self, cb):
>         """takes an rpm callback object, performs the transaction"""
> diff --git a/yum/rpmsack.py b/yum/rpmsack.py
> index 229adaa..4f79fad 100644
> --- a/yum/rpmsack.py
> +++ b/yum/rpmsack.py
> @@ -32,7 +32,7 @@ from packageSack import PackageSackBase,
> PackageSackVersion
>  import fnmatch
>  import re
>
> -from yum.i18n import to_unicode
> +from yum.i18n import to_unicode, _
>  import constants
>
>  import yum.depsolve
> @@ -80,6 +80,40 @@ class RPMInstalledPackage(YumInstalledPackage):
>         return val
>
>
> +class RPMDBProblem:
> +    '''
> +    Represents a problem in the rpmdb, from the check_*() functions.
> +    '''
> +    def __init__(self, pkg, problem, **kwargs):
> +        self.pkg = pkg
> +        self.problem = problem
> +        for kwarg in kwargs:
> +            setattr(self, kwarg, kwargs[kwarg])
> +
> +    def __cmp__(self, other):
> +        if other is None:
> +            return 1
> +        return cmp(self.pkg, other.pkg) or cmp(self.problem, problem)
> +
> +
> +class RPMDBProblemDependency(RPMDBProblem):
> +    def __str__(self):
> +        if self.problem == 'requires':
> +            return "%s %s %s" % (self.pkg, _('has missing requires of'),
> +                                 self.missing)
> +
> +        return "%s %s %s: %s" % (self.pkg, _('has installed conflicts'),
> +                                 self.found,', '.join(map(str,
> self.conflicts)))
> +
> +
> +class RPMDBProblemDuplicate(RPMDBProblem):
> +    def __init__(self, pkg, **kwargs):
> +        RPMDBProblem.__init__(self, pkg, "duplicate", **kwargs)
> +
> +    def __str__(self):
> +        return _("%s is a duplicate with %s") % (self.pkg, self.duplicate)
> +
> +
>  class RPMDBPackageSack(PackageSackBase):
>     '''
>     Represent rpmdb as a packagesack
> @@ -1072,7 +1106,8 @@ class RPMDBPackageSack(PackageSackBase):
>                     continue
>                 flags = yum.depsolve.flags.get(flags, flags)
>                 missing = miscutils.formatRequire(req, ver, flags)
> -                problems.append((pkg, "requires", missing, []))
> +                prob = RPMDBProblemDependency(pkg, "requires",
> missing=missing)
> +                problems.append(prob)
>
>             for creq in pkg.conflicts:
>                 if creq[0].startswith('rpmlib'): continue
> @@ -1083,7 +1118,9 @@ class RPMDBPackageSack(PackageSackBase):
>                     continue
>                 flags = yum.depsolve.flags.get(flags, flags)
>                 found = miscutils.formatRequire(req, ver, flags)
> -                problems.append((pkg, "conflicts", found, res))
> +                prob = RPMDBProblemDependency(pkg, "conflicts",
> found=found,
> +                                              conflicts=res)
> +                problems.append(prob)
>         return problems
>
>     def _iter_two_pkgs(self, ignore):
> @@ -1111,7 +1148,7 @@ class RPMDBPackageSack(PackageSackBase):
>                     continue
>
>             # More than one pkg, they aren't version equal, or aren't
> multiarch
> -            problems.append((pkg, "dup", last))
> +            problems.append(RPMDBProblemDuplicate(pkg, duplicate=last))
>         return problems
>
>
> --
> 1.6.5.2
>
> _______________________________________________
> Yum-devel mailing list
> Yum-devel at lists.baseurl.org
> http://lists.baseurl.org/mailman/listinfo/yum-devel
>

The pathes ar OK, it is a minor API break (check_dependencies return objects
instead of tuples) but that should not be a problem, check_dependencies is
kind of new :) and you changes the only consumer to support it. So ACK from
me.

Tim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.baseurl.org/pipermail/yum-devel/attachments/20100105/c774fbf4/attachment-0001.htm>


More information about the Yum-devel mailing list