[Yum-devel] [PATCH] Return objects from the rpmdb.check_* functions, so it's easier to add more
James Antill
james at and.org
Mon Jan 4 20:10:03 UTC 2010
---
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
More information about the Yum-devel
mailing list