This does the "yum list vendors" feature from the TODO list[1], as well as anything else useful I could think of in a generic package. Any objects to commiting? Any requests for other fields?
I'd also like to do a similar plugin which does filtering, Ie. exclude all pacakges not matching X, Y, Z. Any objections to that? [1] http://wiki.linux.duke.edu/YumTodo -- James Antill <[EMAIL PROTECTED]> Red Hat
commit 235e43c0f3bf12c1d3ed74aa32fb060fef487347
Author: James Antill <[EMAIL PROTECTED]>
Date: Tue Jan 15 18:19:50 2008 -0500
List vendors, groups, baseurls, packagers, buildhosts, licenses and arches
diff --git a/plugins/list-data/list-data.conf b/plugins/list-data/list-data.conf
new file mode 100644
index 0000000..8e4d76c
--- /dev/null
+++ b/plugins/list-data/list-data.conf
@@ -0,0 +1,2 @@
+[main]
+enabled=1
diff --git a/plugins/list-data/list-data.py b/plugins/list-data/list-data.py
new file mode 100755
index 0000000..1f95b8a
--- /dev/null
+++ b/plugins/list-data/list-data.py
@@ -0,0 +1,155 @@
+#! /usr/bin/python -tt
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Library General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+#
+# Copyright Red Hat Inc. 2007, 2008
+#
+# Author: James Antill <[EMAIL PROTECTED]>
+#
+# Examples:
+#
+# yum list-vendors
+# yum list-packagers yum*
+# yum list-groups updates
+
+
+import yum
+import types
+from yum.plugins import TYPE_INTERACTIVE
+import logging # for commands
+from yum import logginglevels
+
+import urlparse
+
+# Decent (UK/US English only) number formatting.
+import locale
+locale.setlocale(locale.LC_ALL, '')
+
+def loc_num(x):
+ """ Return a string of a number in the readable "locale" format. """
+ return locale.format("%d", int(x), True)
+
+requires_api_version = '2.5'
+plugin_type = (TYPE_INTERACTIVE,)
+
+class ListDataCommands:
+ unknown = "-- Unknown --"
+
+ def __init__(self, name, attr):
+ self.name = name
+ self.attr = attr
+
+ def getNames(self):
+ return ['list-' + self.name]
+
+ def getUsage(self):
+ return self.getNames()[0]
+
+ def doCheck(self, base, basecmd, extcmds):
+ pass
+
+ def show_pkgs(self, msg, pkgs):
+ pass
+
+ def show_data(self, msg, pkgs, name):
+ if not pkgs:
+ return
+ msg("%s %s %s" % ('-' * 10, name, '-' * 10))
+ pkgs.sort(key=lambda x: x.name)
+ calc = {}
+ for pkg in pkgs:
+ data = self.get_data(pkg)
+ calc.setdefault(data, []).append(pkg)
+ maxlen = 0
+ for data in calc:
+ val = len(data)
+ if val > maxlen:
+ maxlen = val
+ fmt = "%%-%ds %%6s" % (maxlen)
+ for data in sorted(calc):
+ msg(fmt % (data, loc_num(len(calc[data]))))
+ self.show_pkgs(msg, calc[data])
+
+ # pkg.vendor has weird values, for instance
+ def get_data(self, data):
+ val = getattr(data, self.attr)
+ if val is None:
+ return self.unknown
+ if type(val) == type([]):
+ return self.unknown
+
+ val = str(val).strip()
+ if val == "":
+ return self.unknown
+
+ return val
+
+ def doCommand(self, base, basecmd, extcmds):
+ logger = logging.getLogger("yum.verbose.main")
+ def msg(x):
+ logger.log(logginglevels.INFO_2, x)
+ def msg_warn(x):
+ logger.warn(x)
+
+ 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')
+
+ return 0, [basecmd + ' done']
+
+class InfoDataCommands(ListDataCommands):
+ def getNames(self):
+ return ['info-' + self.name]
+
+ def show_pkgs(self, msg, pkgs):
+ for pkg in pkgs:
+ msg(" %s" % (pkg))
+
+def url_get_data(self, y): # Special version for baseurl
+ val = self.oget_data(y)
+ if val == self.unknown:
+ return val
+ (scheme, netloc, path, query, fragid) = urlparse.urlsplit(val)
+ return "%s://%s/" % (scheme, netloc)
+
+def config_hook(conduit):
+ '''
+ Yum Plugin Config Hook:
+ Add the 'list-vendors', 'list-baseurls', 'list-packagers',
+ 'list-buildhosts' commands and the info varients.
+ '''
+
+ for data in [('vendors', 'vendor'),
+ ('groups', 'group'),
+ ('packagers', 'packager'),
+ ('licenses', 'license'),
+ ('arches', 'arch'),
+ ('buildhosts', 'buildhost')]:
+ conduit.registerCommand(ListDataCommands(*data))
+ conduit.registerCommand(InfoDataCommands(*data))
+
+ data = ('baseurls', 'url')
+ cmd = ListDataCommands(*data)
+ cmd.oget_data = cmd.get_data
+ cmd.get_data = types.MethodType(url_get_data, cmd)
+ conduit.registerCommand(cmd)
+
+ cmd = InfoDataCommands(*data)
+ cmd.oget_data = cmd.get_data
+ cmd.get_data = types.MethodType(url_get_data, cmd)
+ conduit.registerCommand(cmd)
diff --git a/yum-utils.spec b/yum-utils.spec
index 5c74e92..817f18b 100644
--- a/yum-utils.spec
+++ b/yum-utils.spec
@@ -215,7 +215,7 @@ make -C updateonboot DESTDIR=$RPM_BUILD_ROOT install
# Plugins to install
plugins="changelog fastestmirror fedorakmod protectbase versionlock tsflags kernel-module \
downloadonly allowdowngrade skip-broken priorities refresh-updatesd merge-conf \
- security protect-packages basearchonly upgrade-helper aliases"
+ security protect-packages basearchonly upgrade-helper aliases list-data"
mkdir -p $RPM_BUILD_ROOT/%{_sysconfdir}/yum/pluginconf.d/ $RPM_BUILD_ROOT/usr/lib/yum-plugins/
@@ -366,6 +366,11 @@ fi
%config(noreplace) %{_sysconfdir}/yum/aliases.conf
/usr/lib/yum-plugins/aliases.*
+%files -n yum-list-data
+%defattr(-, root, root)
+%config(noreplace) %{_sysconfdir}/yum/pluginconf.d/list-data.conf
+/usr/lib/yum-plugins/list-data.*
+
%changelog
* Sun Jan 13 2008 Seth Vidal <skvidal at fedoraproject.org>
signature.asc
Description: This is a digitally signed message part
_______________________________________________ Yum-devel mailing list [email protected] https://lists.dulug.duke.edu/mailman/listinfo/yum-devel
