[yum-commits] Branch 'yum-3_2_X' - 4 commits - output.py yumcommands.py yum/__init__.py yum/rpmsack.py

James Antill james at osuosl.org
Wed Dec 16 19:11:44 UTC 2009


 output.py       |    7 +++---
 yum/__init__.py |   39 +++++++++++++++++++++++++++++++---
 yum/rpmsack.py  |   64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 yumcommands.py  |    5 +---
 4 files changed, 106 insertions(+), 9 deletions(-)

New commits:
commit 54f1dd8963e61109999d10fc3b0bd854cb995141
Author: James Antill <james at and.org>
Date:   Fri Dec 11 17:02:32 2009 -0500

    Do rpmdb checks when we have no history

diff --git a/output.py b/output.py
index f87247d..89c8f91 100755
--- a/output.py
+++ b/output.py
@@ -1282,7 +1282,9 @@ to exit.
                 lmark = '>'
             print fmt % (old.tid, name, tm, uiacts, num), "%s%s" % (lmark,rmark)
         lastdbv = self.history.last()
-        if lastdbv is not None:
+        if lastdbv is None:
+            self._rpmdb_warn_checks(warn=False)
+        else:
             #  If this is the last transaction, is good and it doesn't
             # match the current rpmdb ... then mark it as bad.
             rpmdbv  = self.rpmdb.simpleVersion(main_only=True)[0]
diff --git a/yum/__init__.py b/yum/__init__.py
index 706f790..20fc516 100644
--- a/yum/__init__.py
+++ b/yum/__init__.py
@@ -1101,8 +1101,8 @@ class YumBase(depsolve.Depsolve):
         lastdbv = self.history.last()
         if lastdbv is not None:
             lastdbv = lastdbv.end_rpmdbversion
-        if lastdbv is not None and rpmdbv != lastdbv:
-            self._rpmdb_warn_checks()
+        if lastdbv is None or rpmdbv != lastdbv:
+            self._rpmdb_warn_checks(warn=lastdbv is not None)
         if self.conf.history_record:
             self.history.beg(rpmdbv, using_pkgs, list(self.tsInfo))
 
diff --git a/yumcommands.py b/yumcommands.py
index a1c2b45..a09ba83 100644
--- a/yumcommands.py
+++ b/yumcommands.py
@@ -1160,8 +1160,8 @@ class VersionCommand(YumCommand):
                 lastdbv = base.history.last()
                 if lastdbv is not None:
                     lastdbv = lastdbv.end_rpmdbversion
-                if lastdbv is not None and data[0] != lastdbv:
-                    base._rpmdb_warn_checks()
+                if lastdbv is None or data[0] != lastdbv:
+                    base._rpmdb_warn_checks(warn=lastdbv is not None)
                 if vcmd not in ('group-installed', 'group-all'):
                     cols.append(("%s %s/%s" % (_("Installed:"), rel, ba),
                                  str(data[0])))
commit 30c94bf851fa27eaccf51c6cff8d3c5613f57dfd
Author: James Antill <james at and.org>
Date:   Fri Dec 11 16:57:38 2009 -0500

    Use showdups for obsoletes, so "list obsoletes" is sane for RHEL like repos

diff --git a/yum/__init__.py b/yum/__init__.py
index 7e87730..706f790 100644
--- a/yum/__init__.py
+++ b/yum/__init__.py
@@ -1902,6 +1902,15 @@ class YumBase(depsolve.Depsolve):
                         continue
                     nobsoletesTuples.append((po, instpo))
                 obsoletesTuples = nobsoletesTuples
+            if not showdups:
+                obsoletes = packagesNewestByName(obsoletes)
+                filt = set(obsoletes)
+                nobsoletesTuples = []
+                for po, instpo in obsoletesTuples:
+                    if po not in filt:
+                        continue
+                    nobsoletesTuples.append((po, instpo))
+                obsoletesTuples = nobsoletesTuples
         
         # packages recently added to the repositories
         elif pkgnarrow == 'recent':
commit 219c59ff5ed1984a846bfb0ebf0a66b1a6115546
Author: James Antill <james at and.org>
Date:   Fri Dec 11 02:09:31 2009 -0500

     Create a _rpmdb_warn_checks function, and use that when we find an
    rpmdb version warning.
    
     Change the text on the warning, hopefully Panu will be happier :).
    
     Use the rpmdb.check_* functions, to see if we find any problems.

diff --git a/output.py b/output.py
index b748ef9..f87247d 100755
--- a/output.py
+++ b/output.py
@@ -1287,8 +1287,7 @@ to exit.
             # match the current rpmdb ... then mark it as bad.
             rpmdbv  = self.rpmdb.simpleVersion(main_only=True)[0]
             if lastdbv.end_rpmdbversion != rpmdbv:
-                errstring = _('Warning: RPMDB has been altered since the last yum transaction.')
-                self.logger.warning(errstring)
+                self._rpmdb_warn_checks()
 
     def _history_get_transactions(self, extcmds):
         if len(extcmds) < 2:
diff --git a/yum/__init__.py b/yum/__init__.py
index 72702b8..7e87730 100644
--- a/yum/__init__.py
+++ b/yum/__init__.py
@@ -1058,6 +1058,31 @@ class YumBase(depsolve.Depsolve):
             toRemove.add(dep)
             self._getDepsToRemove(dep, deptree, toRemove)
 
+    def _rpmdb_warn_checks(self, out=None, warn=True, chkcmd='all'):
+        if out is None:
+            out = self.logger.warning
+        if warn:
+            out(_('Warning: RPMDB altered outside of yum.'))
+
+        rc = 0
+        if chkcmd in ('all', 'duplicates'):
+            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))
+
+        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
+
     def runTransaction(self, cb):
         """takes an rpm callback object, performs the transaction"""
 
@@ -1077,8 +1102,7 @@ class YumBase(depsolve.Depsolve):
         if lastdbv is not None:
             lastdbv = lastdbv.end_rpmdbversion
         if lastdbv is not None and rpmdbv != lastdbv:
-            errstring = _('Warning: RPMDB has been altered since the last yum transaction.')
-            self.logger.warning(errstring)
+            self._rpmdb_warn_checks()
         if self.conf.history_record:
             self.history.beg(rpmdbv, using_pkgs, list(self.tsInfo))
 
diff --git a/yumcommands.py b/yumcommands.py
index 002164b..a1c2b45 100644
--- a/yumcommands.py
+++ b/yumcommands.py
@@ -1161,8 +1161,7 @@ class VersionCommand(YumCommand):
                 if lastdbv is not None:
                     lastdbv = lastdbv.end_rpmdbversion
                 if lastdbv is not None and data[0] != lastdbv:
-                    errstring = _('Warning: RPMDB has been altered since the last yum transaction.')
-                    base.logger.warning(errstring)
+                    base._rpmdb_warn_checks()
                 if vcmd not in ('group-installed', 'group-all'):
                     cols.append(("%s %s/%s" % (_("Installed:"), rel, ba),
                                  str(data[0])))
commit 297477422649aec3c3b4c473687521d9aea69a16
Author: James Antill <james at and.org>
Date:   Fri Dec 11 01:04:17 2009 -0500

    Add check_*() APIs to rpmdb, for when version doesn't match etc.

diff --git a/yum/rpmsack.py b/yum/rpmsack.py
index d6b524a..9b0cd29 100644
--- a/yum/rpmsack.py
+++ b/yum/rpmsack.py
@@ -21,6 +21,7 @@ import os
 import os.path
 
 from rpmUtils import miscutils
+from rpmUtils import arch
 from rpmUtils.transaction import initReadOnlyTransaction
 import misc
 import Errors
@@ -34,6 +35,8 @@ import re
 from yum.i18n import to_unicode
 import constants
 
+import yum.depsolve
+
 class RPMInstalledPackage(YumInstalledPackage):
 
     def __init__(self, rpmhdr, index, rpmdb):
@@ -727,6 +730,67 @@ class RPMDBPackageSack(PackageSackBase):
 
         return sorted(pkgs.keys())
 
+    def check_dependencies(self, pkgs=None):
+        """ Checks for any missing dependencies. """
+
+        if pkgs is None:
+            pkgs = self.returnPackages()
+
+        providers = set() # Speedup, as usual :)
+        problems = []
+        for pkg in sorted(pkgs): # The sort here is mainly for "UI"
+            for rreq in pkg.requires:
+                if rreq[0].startswith('rpmlib'): continue
+                if rreq in providers:            continue
+
+                (req, flags, ver) = rreq
+                if self.getProvides(req, flags, ver):
+                    providers.add(rreq)
+                    continue
+                flags = yum.depsolve.flags.get(flags, flags)
+                missing = miscutils.formatRequire(req, ver, flags)
+                problems.append((pkg, "requires", missing, []))
+
+            for creq in pkg.conflicts:
+                if creq[0].startswith('rpmlib'): continue
+
+                (req, flags, ver) = creq
+                res = self.getProvides(req, flags, ver)
+                if not res:
+                    continue
+                flags = yum.depsolve.flags.get(flags, flags)
+                found = miscutils.formatRequire(req, ver, flags)
+                problems.append((pkg, "conflicts", found, res))
+        return problems
+
+    def _iter_two_pkgs(self, ignore):
+        last = None
+        for pkg in sorted(self.returnPackages()):
+            if pkg.name in ignore:
+                continue
+            if last is None:
+                last = pkg
+                continue
+            yield last, pkg
+            last = pkg
+
+    def check_duplicates(self, ignore=[]):
+        """ Checks for any missing dependencies. """
+
+        problems = []
+        for last, pkg in self._iter_two_pkgs(ignore):
+            if pkg.name != last.name:
+                continue
+            if pkg.verEQ(last) and pkg != last:
+                if arch.isMultiLibArch(pkg.arch) and last.arch != 'noarch':
+                    continue
+                if arch.isMultiLibArch(last.arch) and pkg.arch != 'noarch':
+                    continue
+
+            # More than one pkg, they aren't version equal, or aren't multiarch
+            problems.append((pkg, "dup", last))
+        return problems
+
 
 def _sanitize(path):
     return path.replace('/', '').replace('~', '')


More information about the Yum-commits mailing list