[yum-git] 2 commits - docs/yum-filter-data.1 docs/yum-list-data.1 plugins/filter-data plugins/list-data

James Antill james at linux.duke.edu
Tue Feb 5 15:38:15 UTC 2008


 docs/yum-filter-data.1             |   29 +++++++++-----
 docs/yum-list-data.1               |   13 ++++++
 plugins/filter-data/filter-data.py |   73 +++++++++++++++++++++++++++++++------
 plugins/list-data/list-data.py     |   56 +++++++++++++++++++++++++++-
 4 files changed, 148 insertions(+), 23 deletions(-)

New commits:
commit bd4b1ebcd312242a8933f9daff6776b6f1aa34ed
Author: James Antill <james at and.org>
Date:   Tue Feb 5 10:38:11 2008 -0500

    Fix copy and paste problem

diff --git a/docs/yum-filter-data.1 b/docs/yum-filter-data.1
index 223292b..0c4f1be 100644
--- a/docs/yum-filter-data.1
+++ b/docs/yum-filter-data.1
@@ -19,7 +19,7 @@ These are the options added to yum that are available in the "list updates",
 .IP "\fB\--filter-vendors\fP"
 This option includes packages which have a vendor which matches one of the
 passed vendor wildcard strings, or is unknown. Note that vendors can have
-spaces in their value, so "," is the only way to specify multiple groups as one
+spaces in their value, so "," is the only way to specify multiple vendors as one
 option argument.
 .IP "\fB\--filter-groups\fP"
 This option includes packages which have a group which matches one of the
@@ -29,23 +29,23 @@ option argument.
 .IP "\fB\--filter-packagers\fP"
 This option includes packages which have a packager which matches one of the
 passed packager wildcard strings, or is unknown. Note that vendors can have
-spaces in their value, so "," is the only way to specify multiple groups as one
-option argument.
+spaces in their value, so "," is the only way to specify multiple packagers as
+one option argument.
 .IP "\fB\--filter-licenses\fP"
 This option includes packages which have a license which matches one of the
 passed license wildcard strings, or is unknown. Note that licenses can have
-spaces in their value, so "," is the only way to specify multiple groups as one
-option argument.
+spaces in their value, so "," is the only way to specify multiple licenses as
+one option argument.
 .IP "\fB\--filter-arches\fP"
 This option includes packages which have a arch which matches one of the
 passed arch wildcard strings, or is unknown.
 .IP "\fB\--filter-committers\fP"
 This option includes packages which have a committer which matches one of the
 passed committer wildcard strings, or is unknown. Note that committers can have
-spaces in their value, so "," is the only way to specify multiple groups as one
-option argument. Also, committer values are so loosely formed that they could
-contain commas too, it is recommeneded to not do that but you can work around it
-by using "?".
+spaces in their value, so "," is the only way to specify multiple committers as
+one option argument. Also, committer values are so loosely formed that they 
+could contain commas too, it is recommeneded to not do that but you can work
+around it by using "?".
 .IP "\fB\--filter-buildhosts\fP"
 This option includes packages which have a buildhost which matches one of the
 passed buildhost wildcard strings, or is unknown.
@@ -63,9 +63,9 @@ This option includes packages which have a installedsize which is within one of
 the passed installedsize ranges, or is unknown.
 .IP "\fB\--filter-yum-groups\fP"
 This option includes packages which are in a yum group which matches one of the
-passed yum group id strings, or is unknown. Note that groups can have
-spaces in their value, so "," is the only way to specify multiple groups as one
-option argument.
+passed yum group id strings, or is unknown. Note that yum groups can have
+spaces in their value, so "," is the only way to specify multiple yum groups as
+one option argument.
 .PP
 .PP
 
commit 66acf34f58d8acc647ffb32916fc34e31f545301
Author: James Antill <james at and.org>
Date:   Tue Feb 5 10:37:00 2008 -0500

    Add yum groups, to filter-data and list-data

diff --git a/docs/yum-filter-data.1 b/docs/yum-filter-data.1
index 65a66e5..223292b 100644
--- a/docs/yum-filter-data.1
+++ b/docs/yum-filter-data.1
@@ -61,6 +61,11 @@ the passed archivesize ranges, or is unknown.
 .IP "\fB\--filter-installed-sizes\fP"
 This option includes packages which have a installedsize which is within one of
 the passed installedsize ranges, or is unknown.
+.IP "\fB\--filter-yum-groups\fP"
+This option includes packages which are in a yum group which matches one of the
+passed yum group id strings, or is unknown. Note that groups can have
+spaces in their value, so "," is the only way to specify multiple groups as one
+option argument.
 .PP
 .PP
 
@@ -78,9 +83,13 @@ To list updates for a specific group use:
 .IP
 yum --filter-groups='App*/Sys*' list updates
 .PP
-To apply updates to a specific set of group use:
+To apply updates to a specific set of groups use:
 .IP
 yum --filter-groups='App*/System,Devel*/Lib*,System Environment/Base' update
+.PP
+To apply updates to a specific set of yum groups use:
+.IP
+yum --filter-yum-groups='KDE,Core,Printing Support' update
 
 .SH "SEE ALSO"
 .nf
diff --git a/docs/yum-list-data.1 b/docs/yum-list-data.1
index d97b816..c5826e8 100644
--- a/docs/yum-list-data.1
+++ b/docs/yum-list-data.1
@@ -54,6 +54,10 @@ added yum \fIcommand\fPs are:
 .br 
 .I \fR * info-installed-sizes
 .br 
+.I \fR * list-yum-groups
+.br 
+.I \fR * info-yum-groups
+.br 
 .PP 
 all of which take the same arguments as the list and info yum commands. The
 difference between the list and info varieties is that the info versions lists
@@ -107,6 +111,11 @@ the packages, examples are "[    1B -  10KB ]" and "[ 750KB -   1MB ]".
 Is used to list the aggregate of specified ranges the installedsize attribute on
 the packages, examples are "[    1B -  10KB ]" and "[ 750KB -   1MB ]".
 .IP
+.IP "\fBlist-yum-groups\fP" "\fBinfo-yum-groups\fP"
+Is used to list the aggregate of the yum groups that the packages are in,
+examples are in "yum grouplist". Note that in yum groups a package can be in
+more than one group at a time.
+.IP
 .PP 
 It is worth noting that some of the above data can be "unknown", to yum, at
 which point a seperate aggregation called "-- Unknown --" is listed.
@@ -123,6 +132,10 @@ yum list-committers 'yum*'
 To list ranges of the sizes of pacakges installed or available, use:
 .IP
 yum list-package-sizes
+.PP
+To list yum groups that have an update, use:
+.IP
+yum list-yum-groups
 
 
 .SH "SEE ALSO"
diff --git a/plugins/filter-data/filter-data.py b/plugins/filter-data/filter-data.py
index 585d4c9..4e9cbf3 100644
--- a/plugins/filter-data/filter-data.py
+++ b/plugins/filter-data/filter-data.py
@@ -62,7 +62,31 @@ def fd__get_data(pkg, attr, strip=True):
 def range_match(sz, rang):
     return sz >= rang[0] and sz <= rang[1]
 
-def fd_should_filter_pkg(opts, pkg, used_map):
+all_yum_grp_mbrs = {}
+def fd_make_group_data(base, opts):
+    global all_yum_grp_mbrs
+
+    for pat in opts.filter_yum_groups:
+
+        group = base.comps.return_group(pat)
+        if not group:
+            base.logger.critical('Warning: Group %s does not exist.', pat)
+            continue
+
+        for pkgname in group.mandatory_packages:
+            all_yum_grp_mbrs.setdefault(pkgname, []).append(pat)
+        for pkgname in group.default_packages:
+            all_yum_grp_mbrs.setdefault(pkgname, []).append(pat)
+        for pkgname in group.optional_packages:
+            all_yum_grp_mbrs.setdefault(pkgname, []).append(pat)
+        for pkgname, cond in group.conditional_packages.iteritems():
+            all_yum_grp_mbrs.setdefault(pkgname, []).append(pat)
+
+def fd_free_group_data():
+    global all_yum_grp_mbrs
+    all_yum_grp_mbrs = {}
+
+def fd_should_filter_pkg(base, opts, pkg, used_map):
     """ Do the package filtering for. """
 
     for (attrs, attr) in [('vendors', 'vendor'),
@@ -74,30 +98,37 @@ def fd_should_filter_pkg(opts, pkg, used_map):
                           ('buildhosts', 'buildhost'),
                           ('urls', 'url')]:
         pats = getattr(opts, 'filter_' + attrs)
-        done = len(pats)
+        filt = len(pats)
         for pat in pats:
             data = fd__get_data(pkg, attr)
             if data == fd__unknown or fnmatch.fnmatch(data, pat):
                 used_map[attrs][pat] = True
-                done = False
+                filt = False
                 break
-        if done:
+        if filt:
             return (attrs, attr)
 
     for (attrs, attr) in [('package-sizes', 'packagesize'),
                           ('archive-sizes', 'archivesize'),
                           ('installed-sizes', 'installedsize')]:
         rangs = getattr(opts, 'filter_' + attrs.replace('-', '_'))
-        done = len(rangs)
+        filt = len(rangs)
         for rang in rangs:
             data = fd__get_data(pkg, attr, strip=False)
             if data == fd__unknown or range_match(data, rang):
                 used_map[attrs][rang] = True
-                done = False
+                filt = False
                 break
-        if done:
+        if filt:
             return (attrs, attr)
 
+    if pkg.name not in all_yum_grp_mbrs:
+        return ('yum-groups', None)
+
+    for pat in all_yum_grp_mbrs[pkg.name]:
+        used_map['yum-groups'][pat] = True
+        break
+
     return None
 
 def fd_gen_used_map(opts):
@@ -112,7 +143,8 @@ def fd_gen_used_map(opts):
                           ('urls', 'url'),
                           ('package-sizes', 'packagesize'),
                           ('archive-sizes', 'archivesize'),
-                          ('installed-sizes', 'installedsize')]:
+                          ('installed-sizes', 'installedsize'),
+                          ('yum-groups', None)]:
         used_map[attrs] = {}
         vattrs = attrs.replace('-', '_')
         for i in getattr(opts, 'filter_' + vattrs):
@@ -145,6 +177,11 @@ def fd_chk_used_map(used_map, msg):
                 else:
                     msg(attrs[:-1].capitalize() +
                         ' range \"%d-%d\" did not match any packages' % i)
+
+    for i in used_map['yum-groups']:
+        if not used_map['yum-groups'][i]:
+            msg('Yum group \"%s\" did not contain any packages' % i)
+
         
 #  You might think we'd just use the exclude_hook, and call delPackage
 # and indeed that works for list updates etc.
@@ -177,6 +214,8 @@ def fd_check_func_enter(conduit):
         vattrs = attrs.replace('-', '_')
         if len(getattr(opts, 'filter_' + vattrs)):
             ndata = False
+    if len(opts.filter_yum_groups):
+        ndata = False
     
     ret = None
     if len(args) >= 1:
@@ -257,12 +296,14 @@ def exclude_hook(conduit):
             data = conduit._base.doPackageLists(pkgnarrow=pn, patterns=args)
             pkgs.extend(data.updates)
             del data
-            
+
+    if opts.filter_yum_groups:
+        fd_make_group_data(conduit._base, opts)
     tot = 0
     cnt = 0
     for pkg in pkgs:
         tot += 1
-        which = fd_should_filter_pkg(opts, pkg, used_map)
+        which = fd_should_filter_pkg(conduit._base, opts, pkg, used_map)
         if which:
             fd_del_pkg(pkg, which)
         else:
@@ -273,6 +314,7 @@ def exclude_hook(conduit):
     else:
         conduit.info(2, 'No packages passed the filters, %d available' % tot)
 
+    fd_free_group_data()
     _in_plugin = False
 
 def preresolve_hook(conduit):
@@ -296,6 +338,8 @@ def preresolve_hook(conduit):
                      (tspkg.po, tspkg.po.repoid, which[0]))
         tsinfo.remove(tspkg.pkgtup)
 
+    if opts.filter_yum_groups:
+        fd_make_group_data(conduit._base, opts)
     tot = 0
     cnt = 0
     used_map = fd_gen_used_map(opts)
@@ -303,7 +347,7 @@ def preresolve_hook(conduit):
     tspkgs = tsinfo.getMembers()
     for tspkg in tspkgs:
         tot += 1
-        which = fd_should_filter_pkg(opts, tspkg.po, used_map)
+        which = fd_should_filter_pkg(conduit._base, opts, tspkg.po, used_map)
         if which:
             fd_del_pkg(tspkg, which)
         else:
@@ -314,6 +358,7 @@ def preresolve_hook(conduit):
         conduit.info(2, 'Left with %d of %d packages, after filters applied' % (cnt, tot))
     else:
         conduit.info(2, 'No packages passed the filters, %d available' % tot)
+    fd_free_group_data()
 
 def config_hook(conduit):
     '''
@@ -336,6 +381,7 @@ def config_hook(conduit):
     parser.values.filter_packages_sizes  = []
     parser.values.filter_archive_sizes   = []
     parser.values.filter_installed_sizes = []
+    parser.values.filter_yum_groups      = []
     def ogroups(opt, key, val, parser):
         parser.values.filter_groups.extend(str(val).split(","))
     def make_sopt(attrs):
@@ -399,5 +445,10 @@ def config_hook(conduit):
                           help='Filter to packages with a %s in the given range'
                           % attr)
 
+    # This is kind of odd man out, but...
+    parser.add_option('--filter-yum-groups', action="callback",
+                      callback=make_sopt('yum_groups'),default=[],type="string",
+                      help='Filter to packages within a matching yum group')
+
 if __name__ == '__main__':
     print "This is a plugin that is supposed to run from inside YUM"
diff --git a/plugins/list-data/list-data.py b/plugins/list-data/list-data.py
index 52b88c1..b84fb1b 100755
--- a/plugins/list-data/list-data.py
+++ b/plugins/list-data/list-data.py
@@ -52,6 +52,12 @@ class ListDataCommands:
         self.name = name
         self.attr = attr
 
+    def cmd_beg(self):
+        pass
+
+    def cmd_end(self):
+        pass
+
     def getNames(self):
         return ['list-' + self.name]
 
@@ -79,7 +85,11 @@ Display aggregate data on the %s attribute of a group of packages""" % self.attr
         calc = {}
         for pkg in pkgs:
             data = self.get_data(pkg)
-            calc.setdefault(data, []).append(pkg)
+            if type(data) != type([]):
+                calc.setdefault(data, []).append(pkg)
+            else:
+                for sdata in data:
+                    calc.setdefault(sdata, []).append(pkg)
         maxlen = 0
         totlen = 0
         for data in calc:
@@ -120,12 +130,14 @@ Display aggregate data on the %s attribute of a group of packages""" % self.attr
         def msg_warn(x):
             logger.warn(x)
 
+        self.cmd_beg()
         ypl = base.returnPkgLists(extcmds)
         self.show_data(msg, ypl.installed, 'Installed Packages')
         self.show_data(msg, ypl.available, 'Available Packages')
         self.show_data(msg, ypl.extras,    'Extra Packages')
         self.show_data(msg, ypl.updates,   'Updated Packages')
         self.show_data(msg, ypl.obsoletes, 'Obsoleting Packages')
+        self.cmd_end()
 
         return 0, [basecmd + ' done']
             
@@ -202,15 +214,51 @@ def size_get_data(self, data):
     msg = "[ %s - %s ]  " % (pnum[1], " " * len(pnum[1]))
     return SizeRangeData(pnum[0], msg)    
 
-def _list_data_custom(conduit, data, func):
+
+all_yum_grp_mbrs = {}
+def yum_group_make_data(self):
+    global all_yum_grp_mbrs
+
+    base = self.attr
+    installed, available = base.doGroupLists(uservisible=0)
+    for group in installed + available:
+
+        # Should use translated_name/nameByLang()
+        for pkgname in group.mandatory_packages:
+            all_yum_grp_mbrs.setdefault(pkgname, []).append(group.name)
+        for pkgname in group.default_packages:
+            all_yum_grp_mbrs.setdefault(pkgname, []).append(group.name)
+        for pkgname in group.optional_packages:
+            all_yum_grp_mbrs.setdefault(pkgname, []).append(group.name)
+        for pkgname, cond in group.conditional_packages.iteritems():
+            all_yum_grp_mbrs.setdefault(pkgname, []).append(group.name)
+
+def yum_group_free_data(self):
+    global all_yum_grp_mbrs
+    all_yum_grp_mbrs = {}
+
+def yum_group_get_data(self, pkg):
+    if pkg.name not in all_yum_grp_mbrs:
+        return self.unknown
+    return all_yum_grp_mbrs[pkg.name]
+
+def _list_data_custom(conduit, data, func, beg=None, end=None):
     cmd = ListDataCommands(*data)
     cmd.oget_data = cmd.get_data 
     cmd.get_data  = types.MethodType(func, cmd)
+    if beg:
+        cmd.cmd_beg = types.MethodType(beg, cmd)
+    if end:
+        cmd.cmd_end = types.MethodType(end, cmd)
     conduit.registerCommand(cmd)
 
     cmd = InfoDataCommands(*data)
     cmd.oget_data = cmd.get_data 
     cmd.get_data  = types.MethodType(func, cmd)
+    if beg:
+        cmd.cmd_beg = types.MethodType(beg, cmd)
+    if end:
+        cmd.cmd_end = types.MethodType(end, cmd)
     conduit.registerCommand(cmd)
     
         
@@ -237,4 +285,8 @@ def config_hook(conduit):
     _list_data_custom(conduit, ('installed-sizes', 'installedsize'),
                       size_get_data)
     
+    _list_data_custom(conduit, ('yum-groups', conduit._base),
+                      yum_group_get_data,
+                      beg=yum_group_make_data, end=yum_group_free_data)
+    
     # Buildtime/installtime/committime?



More information about the Yum-cvs-commits mailing list