[yum-commits] Branch 'yum-3_2_X' - 3 commits - cli.py docs/yum.8 yumcommands.py

James Antill james at osuosl.org
Thu Jun 9 13:29:59 UTC 2011


 cli.py         |   50 +++++++++++++++++--
 docs/yum.8     |   42 ++++++---------
 yumcommands.py |  150 +++++++++++++++++++++++++++++----------------------------
 3 files changed, 138 insertions(+), 104 deletions(-)

New commits:
commit ce70570a435ec1904f04dbae346c3bd277fcef75
Author: Nick Jacek <njacek at redhat.com>
Date:   Wed Jun 8 15:01:20 2011 -0400

    Updated documentation for the new groups command.

diff --git a/docs/yum.8 b/docs/yum.8
index 1b5d161..1a8202a 100644
--- a/docs/yum.8
+++ b/docs/yum.8
@@ -45,15 +45,7 @@ gnome\-packagekit application\&.
 .br
 .I \fR * makecache
 .br
-.I \fR * groupinstall group1 [group2] [\&.\&.\&.]
-.br
-.I \fR * groupupdate group1 [group2] [\&.\&.\&.]
-.br 
-.I \fR * grouplist [hidden] [groupwildcard] [\&.\&.\&.]
-.br
-.I \fR * groupremove group1 [group2] [\&.\&.\&.]
-.br
-.I \fR * groupinfo group1 [\&.\&.\&.]
+.I \fR * groups  [\&.\&.\&.]
 .br
 .I \fR * search string1 [string2] [\&.\&.\&.]
 .br
@@ -201,44 +193,42 @@ the \fIClean Options\fP section below\&.
 Is used to download and make usable all the metadata for the currently enabled
 \fByum\fP repos.
 .IP 
-.IP "\fBgroupinstall\fP"
-Is used to install all of the individual packages in a group, of the specified
+.IP "\fBgroups\fP"
+A command, new in 3.4.2, that collects all the subcommands that act on groups together.
+
+"\fBgroup install\fP" is used to install all of the individual packages in a group, of the specified
 types (this works as if you'd taken each of those package names and put them on
 the command line for a "yum install" command).
  The group_package_types configuration option specifies which types will
 be installed.
-.IP 
-.IP "\fBgroupupdate\fP"
-Is just an alias for groupinstall, which will do the right thing because
+
+"\fBgroup update\fP" is just an alias for groupinstall, which will do the right thing because
 "yum install X" and "yum update X" do the same thing, when X is already
 installed.
-.IP 
-.IP "\fBgrouplist\fP"
-Is used to list the available groups from all \fByum\fP repos. Groups are marked
+
+"\fBgroup list\fP" is used to list the available groups from all \fByum\fP repos. Groups are marked
 as "installed" if all mandatory packages are installed, or if a group doesn't
 have any mandatory packages then it is installed if any of the optional or
 default package are installed.
 The optional "hidden" argument will also list groups marked as not being
 "user visible". If you pass the \-v option, to enable verbose mode, then the
 groupids are displayed.
-.IP 
-.IP "\fBgroupremove\fP"
-Is used to remove all of the packages in a group, unlike "groupinstall" this
+
+"\fBgroup remove\fP" is used to remove all of the packages in a group, unlike "groupinstall" this
 will remove everything regardless of group_package_types. It is worth pointing
-out that packages can be in more than one group, so "groupinstall X Y" followed
-by "groupremove Y" does not do give you the same result as "groupinstall X".
+out that packages can be in more than one group, so "group install X Y" followed
+by "group remove Y" does not do give you the same result as "group install X".
 
 The groupremove_leaf_only configuration changes the behaviour of this command
 to only remove packages which aren't required by something else.
-.IP 
-.IP "\fBgroupinfo\fP"
-Is used to give the description and package list of a group (and which type
+
+"\fBgroup info\fP" is used to give the description and package list of a group (and which type
 those packages are marked as). Note that you can use the yum-filter-data and
 yum-list-data plugins to get/use the data the other way around (Ie. what
 groups own packages need updating). If you pass the \-v option, to enable verbose
 mode, then the package names are matched against installed/available packages
 similar to the list command.
-.IP 
+.IP
 .IP "\fBshell\fP"
 Is used to enter the 'yum shell', when a filename is specified the contents of
 that file is executed in yum shell mode. See \fIyum-shell(8)\fP for more info
commit 4d18d511c998fb0ed274bf93421b59b0acc1431e
Author: Nick Jacek <njacek at redhat.com>
Date:   Wed Jun 8 15:01:19 2011 -0400

    Remove the unused group command classes.

diff --git a/yumcommands.py b/yumcommands.py
index 4c9e0a5..4dcbea7 100644
--- a/yumcommands.py
+++ b/yumcommands.py
@@ -430,17 +430,6 @@ class EraseCommand(YumCommand):
     def needTsRemove(self, base, basecmd, extcmds):
         return True
 
-class GroupCommand(YumCommand):
-    def doCommand(self, base, basecmd, extcmds):
-        self.doneCommand(base, _("Setting up Group Process"))
-
-        base.doRepoSetup(dosack=0)
-        try:
-            base.doGroupSetup()
-        except yum.Errors.GroupsError:
-            return 1, [_('No Groups on which to run command')]
-        except yum.Errors.YumBaseError, e:
-            return 1, [str(e)]
  
 class GroupsCommand(YumCommand):
     """ Single sub-command interface for most groups interaction. """
@@ -553,101 +542,6 @@ class GroupsCommand(YumCommand):
            return True
         return False
 
-class GroupListCommand(GroupCommand):
-    def getNames(self):
-        return ['grouplist']
-
-    def getUsage(self):
-        return ""
-
-    def getSummary(self):
-        return _("List available package groups")
-    
-    def doCheck(self, base, basecmd, extcmds):
-        checkEnabledRepo(base)
-
-    def doCommand(self, base, basecmd, extcmds):
-        GroupCommand.doCommand(self, base, basecmd, extcmds)
-        return base.returnGroupLists(extcmds)
-
-    def needTs(self, base, basecmd, extcmds):
-        return False
-
-class GroupInstallCommand(GroupCommand):
-    def getNames(self):
-        return ['groupinstall', 'groupupdate']
-
-    def getUsage(self):
-        return "GROUP..."
-
-    def getSummary(self):
-        return _("Install the packages in a group on your system")
-    
-    def doCheck(self, base, basecmd, extcmds):
-        checkRootUID(base)
-        checkGPGKey(base)
-        checkGroupArg(base, basecmd, extcmds)
-        checkEnabledRepo(base)
-
-    def doCommand(self, base, basecmd, extcmds):
-        GroupCommand.doCommand(self, base, basecmd, extcmds)
-        try:
-            return base.installGroups(extcmds)
-        except yum.Errors.YumBaseError, e:
-            return 1, [str(e)]
-
-class GroupRemoveCommand(GroupCommand):
-    def getNames(self):
-        return ['groupremove', 'grouperase']
-
-    def getUsage(self):
-        return "GROUP..."
-
-    def getSummary(self):
-        return _("Remove the packages in a group from your system")
-
-    def doCheck(self, base, basecmd, extcmds):
-        checkRootUID(base)
-        checkGroupArg(base, basecmd, extcmds)
-        checkEnabledRepo(base)
-
-    def doCommand(self, base, basecmd, extcmds):
-        GroupCommand.doCommand(self, base, basecmd, extcmds)
-        try:
-            return base.removeGroups(extcmds)
-        except yum.Errors.YumBaseError, e:
-            return 1, [str(e)]
-
-    def needTs(self, base, basecmd, extcmds):
-        return False
-
-    def needTsRemove(self, base, basecmd, extcmds):
-        return True
-
-class GroupInfoCommand(GroupCommand):
-    def getNames(self):
-        return ['groupinfo']
-
-    def getUsage(self):
-        return "GROUP..."
-
-    def getSummary(self):
-        return _("Display details about a package group")
-
-    def doCheck(self, base, basecmd, extcmds):
-        checkGroupArg(base, basecmd, extcmds)
-        checkEnabledRepo(base)
-
-    def doCommand(self, base, basecmd, extcmds):
-        GroupCommand.doCommand(self, base, basecmd, extcmds)
-        try:
-            return base.returnGroupInfo(extcmds)
-        except yum.Errors.YumBaseError, e:
-            return 1, [str(e)]
-
-    def needTs(self, base, basecmd, extcmds):
-        return False
-
 class MakeCacheCommand(YumCommand):
 
     def getNames(self):
commit f43c870aaad07f0f41fd368d47972f691a864bde
Author: Nick Jacek <njacek at redhat.com>
Date:   Wed Jun 8 15:01:18 2011 -0400

    Adds the Groups command, and removes individual command classes for grouplist etc. Adds the group summary function.

diff --git a/cli.py b/cli.py
index 7ef147d..5c3b9c3 100644
--- a/cli.py
+++ b/cli.py
@@ -84,11 +84,7 @@ class YumBaseCli(yum.YumBase, output.YumOutput):
         self.registerCommand(yumcommands.InfoCommand())
         self.registerCommand(yumcommands.ListCommand())
         self.registerCommand(yumcommands.EraseCommand())
-        self.registerCommand(yumcommands.GroupCommand())
-        self.registerCommand(yumcommands.GroupListCommand())
-        self.registerCommand(yumcommands.GroupInstallCommand())
-        self.registerCommand(yumcommands.GroupRemoveCommand())
-        self.registerCommand(yumcommands.GroupInfoCommand())
+        self.registerCommand(yumcommands.GroupsCommand())
         self.registerCommand(yumcommands.MakeCacheCommand())
         self.registerCommand(yumcommands.CleanCommand())
         self.registerCommand(yumcommands.ProvidesCommand())
@@ -1283,6 +1279,50 @@ class YumBaseCli(yum.YumBase, output.YumOutput):
             done = True
 
         return 0, [_('Done')]
+
+    def returnGroupSummary(self, userlist):
+
+        uservisible=1
+            
+        if len(userlist) > 0:
+            if userlist[0] == 'hidden':
+                uservisible=0
+                userlist.pop(0)
+        if not userlist:
+            userlist = None # Match everything...
+
+        installed, available = self.doGroupLists(uservisible=uservisible,
+                                                 patterns=userlist)
+        
+        def _out_grp(sect, num):
+            if not num:
+                return
+            self.verbose_logger.log(yum.logginglevels.INFO_2, '%s %u', sect,num)
+        done = 0
+        for group in installed:
+            if group.langonly: continue
+            done += 1
+        _out_grp(_('Installed Groups:'), done)
+
+        done = 0
+        for group in installed:
+            if not group.langonly: continue
+            done += 1
+        _out_grp(_('Installed Language Groups:'), done)
+
+        done = False
+        for group in available:
+            if group.langonly: continue
+            done += 1
+        _out_grp(_('Available Groups:'), done)
+
+        done = False
+        for group in available:
+            if not group.langonly: continue
+            done += 1
+        _out_grp(_('Available Language Groups:'), done)
+
+        return 0, [_('Done')]
     
     def returnGroupInfo(self, userlist):
         """returns complete information on a list of groups"""
diff --git a/yumcommands.py b/yumcommands.py
index baf5e93..4c9e0a5 100644
--- a/yumcommands.py
+++ b/yumcommands.py
@@ -441,7 +441,117 @@ class GroupCommand(YumCommand):
             return 1, [_('No Groups on which to run command')]
         except yum.Errors.YumBaseError, e:
             return 1, [str(e)]
+ 
+class GroupsCommand(YumCommand):
+    """ Single sub-command interface for most groups interaction. """
 
+    direct_commands = {'grouplist'    : 'list',
+                       'groupinstall' : 'install',
+                       'groupupdate'  : 'install',
+                       'groupremove'  : 'remove',
+                       'grouperase'   : 'remove',
+                       'groupinfo'    : 'info'}
+
+    def getNames(self):
+        return ['groups', 'group'] + self.direct_commands.keys()
+
+    def getUsage(self):
+        return "[list|info|summary|install|upgrade|remove|mark] [GROUP]"
+
+    def getSummary(self):
+        return _("Display, or use, the groups information")
+    
+    def _grp_setup_doCommand(self, base):
+        self.doneCommand(base, _("Setting up Group Process"))
+
+        base.doRepoSetup(dosack=0)
+        try:
+            base.doGroupSetup()
+        except yum.Errors.GroupsError:
+            return 1, [_('No Groups on which to run command')]
+        except yum.Errors.YumBaseError, e:
+            return 1, [str(e)]
+
+    def _grp_cmd(self, basecmd, extcmds):
+        if basecmd in self.direct_commands:
+            cmd = self.direct_commands[basecmd]
+        elif extcmds:
+            cmd = extcmds[0]
+            extcmds = extcmds[1:]
+        else:
+            cmd = 'summary'
+
+        remap = {'update' : 'upgrade',
+                 'erase' : 'remove',
+                 'mark-erase' : 'mark-remove',
+                 }
+        cmd = remap.get(cmd, cmd)
+
+        return cmd, extcmds
+
+    def doCheck(self, base, basecmd, extcmds):
+        cmd, extcmds = self._grp_cmd(basecmd, extcmds)
+
+        checkEnabledRepo(base)
+
+        if cmd in ('install', 'remove',
+                   'mark-install', 'mark-remove',
+                   'mark-members', 'info', 'mark-members-sync'):
+            checkGroupArg(base, cmd, extcmds)
+
+        if cmd in ('install', 'remove', 'upgrade',
+                   'mark-install', 'mark-remove',
+                   'mark-members', 'mark-members-sync'):
+            checkRootUID(base)
+
+        if cmd in ('install', 'upgrade'):
+            checkGPGKey(base)
+
+        cmds = ('list', 'info', 'remove', 'install', 'upgrade', 'summary',
+                'mark-install', 'mark-remove',
+                'mark-members', 'mark-members-sync')
+        if cmd not in cmds:
+            base.logger.critical(_('Invalid groups sub-command, use: %s.'),
+                                 ", ".join(cmds))
+            raise cli.CliError
+
+    def doCommand(self, base, basecmd, extcmds):
+        cmd, extcmds = self._grp_cmd(basecmd, extcmds)
+
+        self._grp_setup_doCommand(base)
+        if cmd == 'summary':
+            return base.returnGroupSummary(extcmds)
+
+        if cmd == 'list':
+            return base.returnGroupLists(extcmds)
+
+        try:
+            if cmd == 'info':
+                return base.returnGroupInfo(extcmds)
+            if cmd == 'install':
+                return base.installGroups(extcmds)
+            if cmd == 'upgrade':
+                return base.installGroups(extcmds, upgrade=True)
+            if cmd == 'remove':
+                return base.removeGroups(extcmds)
+
+        except yum.Errors.YumBaseError, e:
+            return 1, [str(e)]
+
+
+    def needTs(self, base, basecmd, extcmds):
+        cmd, extcmds = self._grp_cmd(basecmd, extcmds)
+
+        if cmd in ('list', 'info', 'remove', 'summary'):
+            return False
+        return True
+
+    def needTsRemove(self, base, basecmd, extcmds):
+        cmd, extcmds = self._grp_cmd(basecmd, extcmds)
+
+        if cmd in ('remove',):
+           return True
+        return False
 
 class GroupListCommand(GroupCommand):
     def getNames(self):


More information about the Yum-commits mailing list