[yum-commits] Branch 'yum-3_2_X' - 3 commits - cli.py docs/yum.8 test/simpleupdatetests.py test/testbase.py yumcommands.py yum/__init__.py yum/packageSack.py

James Antill james at osuosl.org
Fri Apr 1 05:10:22 UTC 2011


 cli.py                    |    4 -
 docs/yum.8                |   18 ++++++
 test/simpleupdatetests.py |  119 ++++++++++++++++++++++++++++++++++++++++++++++
 test/testbase.py          |    4 +
 yum/__init__.py           |   58 +++++++++++++++++-----
 yum/packageSack.py        |    9 +++
 yumcommands.py            |    8 +--
 7 files changed, 200 insertions(+), 20 deletions(-)

New commits:
commit bde809e32d0164aacca22503643901a3444385ac
Author: James Antill <james at and.org>
Date:   Wed Mar 30 18:01:29 2011 -0400

    Add tests for update-to/upgrade-to, and fix generic code so tests work.

diff --git a/test/simpleupdatetests.py b/test/simpleupdatetests.py
index 6bc2efe..6177fb1 100644
--- a/test/simpleupdatetests.py
+++ b/test/simpleupdatetests.py
@@ -871,3 +871,122 @@ class SimpleUpdateTests(OperationsTests):
                                      [pa1, pa2], multi_cmds=True)
         self.assert_(res=='ok', msg)
         self.assertResult((pa1, pa2))
+
+    # Test how update-to != update.
+    def _setupUpdateTo(self):
+        foo11 = FakePackage('foo', '1', '1', '0', 'i386')
+        foo11.addProvides('foobar', 'EQ', ('0', '1', '1'))
+        foo12 = FakePackage('foo', '1', '2', '0', 'i386')
+        foo12.addProvides('foobar', 'EQ', ('0', '1', '2'))
+        foo13 = FakePackage('foo', '1', '3', '0', 'i386')
+        foo13.addProvides('foobar', 'EQ', ('0', '1', '3'))
+        foo20 = FakePackage('foo', '2', '0', '0', 'i386')
+        foo20.addProvides('foobar', 'EQ', ('0', '2', '0'))
+        all = (foo11, foo12, foo13, foo20)
+        return locals()
+
+    def testUpdateTo1_1(self):
+        pkgs = self._setupUpdateTo()
+        res, msg = self.runOperation(['update', 'foo'],
+                                     [pkgs['foo11']],
+                                     pkgs['all'])
+        self.assert_(res=='ok', msg)
+        self.assertResult((pkgs['foo20'],))
+
+    def testUpdateTo1_2(self):
+        pkgs = self._setupUpdateTo()
+        res, msg = self.runOperation(['update-to', 'foo'],
+                                     [pkgs['foo11']],
+                                     pkgs['all'])
+        self.assert_(res=='ok', msg)
+        self.assertResult((pkgs['foo20'],))
+
+    def testUpdateTo2_1(self):
+        pkgs = self._setupUpdateTo()
+        res, msg = self.runOperation(['update', 'foo-1-2'],
+                                     [pkgs['foo11']],
+                                     pkgs['all'])
+        self.assert_(res=='ok', msg)
+        self.assertResult((pkgs['foo12'],))
+
+    def testUpdateTo2_2(self):
+        pkgs = self._setupUpdateTo()
+        res, msg = self.runOperation(['update-to', 'foo-1-2'],
+                                     [pkgs['foo11']],
+                                     pkgs['all'])
+        self.assert_(res=='ok', msg)
+        self.assertResult((pkgs['foo12'],))
+
+    def testUpdateTo3_1(self):
+        pkgs = self._setupUpdateTo()
+        res, msg = self.runOperation(['update', 'foo-1-2'],
+                                     [pkgs['foo12']],
+                                     pkgs['all'])
+        self.assert_(res=='ok', msg)
+        self.assertResult((pkgs['foo20'],))
+
+    def testUpdateTo3_2(self):
+        pkgs = self._setupUpdateTo()
+        res, msg = self.runOperation(['update-to', 'foo-1-2'],
+                                     [pkgs['foo12']],
+                                     pkgs['all'])
+        # Nothing to do...
+        self.assert_(res==0, msg)
+
+
+    def testUpdateToProv1_1(self):
+        pkgs = self._setupUpdateTo()
+        res, msg = self.runOperation(['update', 'foobar'],
+                                     [pkgs['foo11']],
+                                     pkgs['all'])
+        self.assert_(res=='ok', msg)
+        self.assertResult((pkgs['foo20'],))
+
+    def testUpdateToProv1_2(self):
+        pkgs = self._setupUpdateTo()
+        res, msg = self.runOperation(['update-to', 'foobar'],
+                                     [pkgs['foo11']],
+                                     pkgs['all'])
+        self.assert_(res=='ok', msg)
+        self.assertResult((pkgs['foo20'],))
+
+    def testUpdateToProv2_1(self):
+        pkgs = self._setupUpdateTo()
+        #  This is kind of annoying, maybe even a bug (but an old one) what
+        # happens is that in "update" we only look for provides matches on
+        # installed pkgs. ... so we can't see a version mismatch. Thus. we
+        # don't see any pkgs.
+        #  It also prints an annoying msg. at critical level. So ignoring.
+        if True:
+            return
+        res, msg = self.runOperation(['update', 'foobar = 1-2'],
+                                     [pkgs['foo11']],
+                                     pkgs['all'])
+        # self.assert_(res=='ok', msg)
+        # self.assertResult((pkgs['foo12'],))
+        self.assert_(res==0, msg)
+
+    def testUpdateToProv2_2(self):
+        pkgs = self._setupUpdateTo()
+        res, msg = self.runOperation(['update-to', 'foobar = 1-2'],
+                                     [pkgs['foo11']],
+                                     pkgs['all'])
+        self.assert_(res=='ok', msg)
+        self.assertResult((pkgs['foo12'],))
+
+    def testUpdateToProv3_1(self):
+        pkgs = self._setupUpdateTo()
+        res, msg = self.runOperation(['update', 'foobar = 1-2'],
+                                     [pkgs['foo12']],
+                                     pkgs['all'])
+        self.assert_(res=='ok', msg)
+        self.assertResult((pkgs['foo20'],))
+
+    def testUpdateToProv3_2(self):
+        pkgs = self._setupUpdateTo()
+        res, msg = self.runOperation(['update-to', 'foobar = 1-2'],
+                                     [pkgs['foo12']],
+                                     pkgs['all'])
+        # Nothing to do...
+        self.assert_(res==0, msg)
+
diff --git a/test/testbase.py b/test/testbase.py
index d9e23f1..12025ce 100644
--- a/test/testbase.py
+++ b/test/testbase.py
@@ -18,6 +18,8 @@ from yum.rpmsack import RPMDBPackageSack as _rpmdbsack
 import inspect
 from rpmUtils import arch
 from rpmUtils.transaction import initReadOnlyTransaction
+import rpmUtils.miscutils
+
 
 #############################################################
 ### Helper classes ##########################################
@@ -320,6 +322,8 @@ class FakeRpmDb(packageSack.PackageSack):
         # convert flags & version for unversioned reqirements
         if not version:
             version=(None, None, None)
+        if type(version) in (str, type(None), unicode):
+            version = rpmUtils.miscutils.stringToVersion(version)
         if flags == '0':
             flags=None
         for po in self.provides.get(name, []):
diff --git a/yum/packageSack.py b/yum/packageSack.py
index 153edbb..4af563a 100644
--- a/yum/packageSack.py
+++ b/yum/packageSack.py
@@ -24,6 +24,7 @@ import re
 import fnmatch
 import misc
 from packages import parsePackages
+import rpmUtils.miscutils
 from rpmUtils.miscutils import compareEVR
 
 class PackageSackVersion:
@@ -702,6 +703,10 @@ class PackageSack(PackageSackBase):
     def getProvides(self, name, flags=None, version=(None, None, None)):
         """return dict { packages -> list of matching provides }"""
         self._checkIndexes(failure='build')
+        if version is None:
+            version = (None, None, None)
+        elif type(version) in (str, type(None), unicode):
+            version = rpmUtils.miscutils.stringToVersion(version)
         result = { }
         for po in self.provides.get(name, []):
             hits = po.matchingPrcos('provides', (name, flags, version))
@@ -716,6 +721,10 @@ class PackageSack(PackageSackBase):
     def getRequires(self, name, flags=None, version=(None, None, None)):
         """return dict { packages -> list of matching requires }"""
         self._checkIndexes(failure='build')
+        if version is None:
+            version = (None, None, None)
+        elif type(version) in (str, type(None), unicode):
+            version = rpmUtils.miscutils.stringToVersion(version)
         result = { }
         for po in self.requires.get(name, []):
             hits = po.matchingPrcos('requires', (name, flags, version))
commit e36ea7d4dd847438fff6062e854419e5267fe2d0
Author: James Antill <james at and.org>
Date:   Wed Mar 30 18:01:05 2011 -0400

    Add docs for update-to/upgrade-to, and explain update/upgrade behaviour.

diff --git a/docs/yum.8 b/docs/yum.8
index 0f1b1ba..39c7253 100644
--- a/docs/yum.8
+++ b/docs/yum.8
@@ -23,10 +23,14 @@ gnome\-packagekit application\&.
 .br 
 .I \fR * update [package1] [package2] [\&.\&.\&.]
 .br 
+.I \fR * update-to [package1] [package2] [\&.\&.\&.]
+.br 
 .I \fR * check\-update
 .br 
 .I \fR * upgrade [package1] [package2] [\&.\&.\&.] 
 .br
+.I \fR * upgrade-to [package1] [package2] [\&.\&.\&.] 
+.br
 .I \fR * distribution-synchronization [package1] [package2] [\&.\&.\&.] 
 .br
 .I \fR * remove | erase package1 [package2] [\&.\&.\&.]
@@ -112,6 +116,16 @@ If the main obsoletes configure option is true (default) or the \-\-obsoletes
 flag is present \fByum\fP will include package 
 obsoletes in its calculations - this makes it better for distro\-version 
 changes, for example: upgrading from somelinux 8.0 to somelinux 9.
+
+Note that "\fBupdate\fP" works on installed packages first, and only if there
+are no matches does it look for available packages. The difference is most
+noticable when you do "\fBupdate\fP foo-1-2" which will act exactly as
+"\fBupdate\fP foo" if foo-1-2 is installed. You can use the "\fBupdate-to\fP"
+if you'd prefer that nothing happen in the above case.
+.IP 
+.IP "\fBupdate-to\fP"
+This command works like "\fBupdate\fP" but always specifies the version of the
+package we want to update to.
 .IP 
 .IP "\fBcheck\-update\fP"
 Implemented so you could know if your machine had any updates that needed to
@@ -125,6 +139,10 @@ Running in verbose mode also shows obsoletes.
 Is the same as the update command with the \-\-obsoletes flag set. See update 
 for more details.
 .IP 
+.IP "\fBupgrade-to\fP"
+This command works like "\fBupgrade\fP" but always specifies the version of the
+package we want to update to.
+.IP 
 .IP "\fBdistribution\-synchronization\fP or \fBdistro\-sync\fP"
 Synchronizes the installed package set with the latest packages available, this
 is done by either obsoleting, upgrading or downgrading as appropriate. This will
commit 63f729d5ce3c13ae592ccd637532a5a8286718e3
Author: James Antill <james at and.org>
Date:   Wed Mar 30 18:00:08 2011 -0400

    Add update-to and upgrade-to commands, as "hidden" alias for update/upgrade.

diff --git a/cli.py b/cli.py
index eca1812..1b7d7e6 100644
--- a/cli.py
+++ b/cli.py
@@ -713,7 +713,7 @@ class YumBaseCli(yum.YumBase, output.YumOutput):
             return 1, [_('Nothing to do')]
         return 0, [_('Nothing to do')]
         
-    def updatePkgs(self, userlist, quiet=0):
+    def updatePkgs(self, userlist, quiet=0, update_to=False):
         """take user commands and populate transaction wrapper with 
            packages to be updated"""
         
@@ -740,7 +740,7 @@ class YumBaseCli(yum.YumBase, output.YumOutput):
                     userlist.remove(item)
                 
             for arg in userlist:
-                if not self.update(pattern=arg):
+                if not self.update(pattern=arg, update_to=update_to):
                     self._checkMaybeYouMeant(arg)
 
         if len(self.tsInfo) > oldcount:
diff --git a/yum/__init__.py b/yum/__init__.py
index d1f07d0..60c572d 100644
--- a/yum/__init__.py
+++ b/yum/__init__.py
@@ -3005,9 +3005,28 @@ class YumBase(depsolve.Depsolve):
 
         if not depstring:
             return []
-        results = self.pkgSack.searchProvides(depstring)
-        return results
-        
+
+        # parse the string out
+        #  either it is 'dep (some operator) e:v-r'
+        #  or /file/dep
+        #  or packagename
+        if type(depstring) == types.TupleType:
+            (depname, depflags, depver) = depstring
+        else:
+            depname = depstring
+            depflags = None
+            depver = None
+
+            if depstring[0] != '/':
+                # not a file dep - look at it for being versioned
+                dep_split = depstring.split()
+                if len(dep_split) == 3:
+                    depname, flagsymbol, depver = dep_split
+                    if not flagsymbol in SYMBOLFLAGS:
+                        raise Errors.YumBaseError, _('Invalid version flag from: %s') % str(depstring)
+                    depflags = SYMBOLFLAGS[flagsymbol]
+
+        return self.pkgSack.getProvides(depname, depflags, depver).keys()
 
     def returnPackageByDep(self, depstring):
         """Pass in a generic [build]require string and this function will 
@@ -3563,7 +3582,7 @@ class YumBase(depsolve.Depsolve):
             txmbr.reason = 'dep'
         return txmbr
 
-    def update(self, po=None, requiringPo=None, **kwargs):
+    def update(self, po=None, requiringPo=None, update_to=False, **kwargs):
         """try to mark for update the item(s) specified. 
             po is a package object - if that is there, mark it for update,
             if possible
@@ -3634,26 +3653,37 @@ class YumBase(depsolve.Depsolve):
             if kwargs['pattern'] and kwargs['pattern'][0] == '@':
                 return self._at_groupinstall(kwargs['pattern'])
 
-            (e, m, u) = self.rpmdb.matchPackageNames([kwargs['pattern']])
-            instpkgs.extend(e)
-            instpkgs.extend(m)
+            arg = kwargs['pattern']
+            if not update_to:
+                instpkgs  = self.rpmdb.returnPackages(patterns=[arg])
+            else:
+                availpkgs = self.pkgSack.returnPackages(patterns=[arg])
 
-            if u:
+            if not instpkgs and not availpkgs:
                 depmatches = []
-                arg = u[0]
                 try:
-                    depmatches = self.returnInstalledPackagesByDep(arg)
+                    if update_to:
+                        depmatches = self.returnPackagesByDep(arg)
+                    else:
+                        depmatches = self.returnInstalledPackagesByDep(arg)
                 except yum.Errors.YumBaseError, e:
                     self.logger.critical(_('%s') % e)
-                
-                instpkgs.extend(depmatches)
+
+                if update_to:
+                    availpkgs.extend(depmatches)
+                else:
+                    instpkgs.extend(depmatches)
 
             #  Always look for available packages, it doesn't seem to do any
             # harm (apart from some time). And it fixes weird edge cases where
             # "update a" (which requires a new b) is different from "update b"
             try:
-                pats = [kwargs['pattern']]
-                m = self.pkgSack.returnNewestByNameArch(patterns=pats)
+                if update_to:
+                    m = []
+                else:
+                    pats = [kwargs['pattern']]
+                    # pats += list(set([pkg.name for pkg in instpkgs]))
+                    m = self.pkgSack.returnNewestByNameArch(patterns=pats)
             except Errors.PackageSackError:
                 m = []
             availpkgs.extend(m)
diff --git a/yumcommands.py b/yumcommands.py
index 41f0092..fd69f05 100644
--- a/yumcommands.py
+++ b/yumcommands.py
@@ -207,7 +207,7 @@ class InstallCommand(YumCommand):
 
 class UpdateCommand(YumCommand):
     def getNames(self):
-        return ['update']
+        return ['update', 'update-to']
 
     def getUsage(self):
         return _("[PACKAGE...]")
@@ -223,7 +223,7 @@ class UpdateCommand(YumCommand):
     def doCommand(self, base, basecmd, extcmds):
         self.doneCommand(base, _("Setting up Update Process"))
         try:
-            return base.updatePkgs(extcmds)
+            return base.updatePkgs(extcmds, update_to=(basecmd == 'update-to'))
         except yum.Errors.YumBaseError, e:
             return 1, [str(e)]
 
@@ -691,7 +691,7 @@ class SearchCommand(YumCommand):
 
 class UpgradeCommand(YumCommand):
     def getNames(self):
-        return ['upgrade']
+        return ['upgrade', 'upgrade-to']
 
     def getUsage(self):
         return 'PACKAGE...'
@@ -708,7 +708,7 @@ class UpgradeCommand(YumCommand):
         base.conf.obsoletes = 1
         self.doneCommand(base, _("Setting up Upgrade Process"))
         try:
-            return base.updatePkgs(extcmds)
+            return base.updatePkgs(extcmds, update_to=(basecmd == 'upgrade-to'))
         except yum.Errors.YumBaseError, e:
             return 1, [str(e)]
 


More information about the Yum-commits mailing list