The idea is that sometimes you want to say "make sure the entire
dep. tree for package XYZ is at the latest version"

 Things this patch doesn't do:

1. local packages.

2. implied deps. ... like @buildsys / @core.

3. recursive updates for updates that add new deps.
---
 cli.py         |   46 ++++++++++++++++++++++++++++++++++++++++
 yumcommands.py |   63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 108 insertions(+), 1 deletions(-)

diff --git a/cli.py b/cli.py
index 00374d8..f201c3b 100755
--- a/cli.py
+++ b/cli.py
@@ -92,6 +92,7 @@ class YumBaseCli(yum.YumBase, output.YumOutput):
         self.registerCommand(yumcommands.CheckUpdateCommand())
         self.registerCommand(yumcommands.SearchCommand())
         self.registerCommand(yumcommands.UpgradeCommand())
+        self.registerCommand(yumcommands.UpgradeAllCommand())
         self.registerCommand(yumcommands.LocalInstallCommand())
         self.registerCommand(yumcommands.ResolveDepCommand())
         self.registerCommand(yumcommands.ShellCommand())
@@ -825,6 +826,51 @@ class YumBaseCli(yum.YumBase, output.YumOutput):
         else:
             return 0, [_('No Packages marked for Update')]
 
+    def upgradeAllPkgs(self, userlist):
+        """Take user commands and populate transaction wrapper with
+        packages to be updated.
+
+        :param userlist: a list of names or wildcards specifying
+           packages to update.  If *userlist* is an empty list, yum
+           will perform a global update
+        :return: (exit_code, [ errors ])
+
+        exit_code is::
+
+            0 = we're done, exit
+            1 = we've errored, exit with error string
+            2 = we've got work yet to do, onto the next stage
+        """
+        # if there is no userlist, then do global update just like "updatePkgs"
+        # if there is a userlist then we find those packages, and their deps.
+
+        oldcount = len(self.tsInfo)
+        if len(userlist) == 0: # simple case - do them all
+            self.update()
+
+        else:
+            done = set()
+
+            def _pkg2ups(pkg):
+                if pkg.name in done:
+                    return
+
+                self.update(pattern=pkg.name)
+                done.add(pkg.name)
+
+                for req in pkg.requires:
+                    for npkg in self.returnInstalledPackagesByDep(req):
+                        _pkg2ups(npkg)
+
+            for pkg in self.rpmdb.returnPackages(patterns=userlist):
+                _pkg2ups(pkg)
+
+        if len(self.tsInfo) > oldcount:
+            change = len(self.tsInfo) - oldcount
+            return 2, [P_('%d package marked for Update', '%d packages marked 
for Update', change) % change]
+        else:
+            return 0, [_('No Packages marked for Update')]
+
     #  Note that we aren't in __init__ yet for a couple of reasons, but we 
     # probably will get there for 3.2.28.
     def distroSyncPkgs(self, userlist):
diff --git a/yumcommands.py b/yumcommands.py
index d9c70f3..2d0fbfc 100644
--- a/yumcommands.py
+++ b/yumcommands.py
@@ -1272,7 +1272,7 @@ class SearchCommand(YumCommand):
 
 class UpgradeCommand(YumCommand):
     """A class containing methods needed by the cli to execute the
-    update command.
+    upgrade command.
     """
 
     def getNames(self):
@@ -1331,6 +1331,67 @@ class UpgradeCommand(YumCommand):
         except yum.Errors.YumBaseError, e:
             return 1, [str(e)]
 
+class UpgradeAllCommand(YumCommand):
+    """A class containing methods needed by the cli to execute the
+    upgrade-all command.
+    """
+
+    def getNames(self):
+        """Return a list containing the names of this command.  This
+        command can be called from the command line by using any of these 
names.
+
+        :return: a list containing the names of this command
+        """
+        return ['upgrade-all', 'update-all']
+
+    def getUsage(self):
+        """Return a usage string for this command.
+
+        :return: a usage string for this command
+        """
+        return 'PACKAGE...'
+
+    def getSummary(self):
+        """Return a one line summary of this command.
+
+        :return: a one line summary of this command
+        """
+        return _("Update packages taking obsoletes into account")
+
+    def doCheck(self, base, basecmd, extcmds):
+        """Verify that conditions are met so that this command can
+         run.  These include that the program is being run by the root
+         user, and that there are enabled repositories with gpg.
+
+        :param base: a :class:`yum.Yumbase` object
+        :param basecmd: the name of the command
+        :param extcmds: the command line arguments passed to *basecmd*
+        """
+        checkRootUID(base)
+        checkGPGKey(base)
+        checkEnabledRepo(base, extcmds)
+
+    def doCommand(self, base, basecmd, extcmds):
+        """Execute this command.
+
+        :param base: a :class:`yum.Yumbase` object
+        :param basecmd: the name of the command
+        :param extcmds: the command line arguments passed to *basecmd*
+        :return: (exit_code, [ errors ])
+
+        exit_code is::
+
+            0 = we're done, exit
+            1 = we've errored, exit with error string
+            2 = we've got work yet to do, onto the next stage
+        """
+        base.conf.obsoletes = 1
+        self.doneCommand(base, _("Setting up Upgrade-All Process"))
+        try:
+            return base.upgradeAllPkgs(extcmds)
+        except yum.Errors.YumBaseError, e:
+            return 1, [str(e)]
+
 class LocalInstallCommand(YumCommand):
     """A class containing methods needed by the cli to execute the
     localinstall command.
-- 
1.7.6

_______________________________________________
Yum-devel mailing list
[email protected]
http://lists.baseurl.org/mailman/listinfo/yum-devel

Reply via email to