[yum-git] plugins/list-data yum-utils.spec
James Antill
james at linux.duke.edu
Sun Jan 20 02:11:58 UTC 2008
plugins/list-data/list-data.conf | 2
plugins/list-data/list-data.py | 249 +++++++++++++++++++++++++++++++++++++++
yum-utils.spec | 15 ++
3 files changed, 265 insertions(+), 1 deletion(-)
New commits:
commit b9ac2c5f77056d522b3461b3abe100c9acd8e610
Author: James Antill <james at and.org>
Date: Tue Jan 15 18:19:50 2008 -0500
List vendors, groups, packagers, buildhosts, licenses, arches, buildhosts,
baseurls, package-sizes, archive-sizes, installed-sizes, committers
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..59979d5
--- /dev/null
+++ b/plugins/list-data/list-data.py
@@ -0,0 +1,249 @@
+#! /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 <james.antill at redhat.com>
+#
+# 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
+
+# For baseurl
+import urlparse
+
+# For committers
+import re
+
+import UnicodeWidth
+
+# 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" % ('=' * 20, name, '=' * 20))
+ pkgs.sort(key=lambda x: x.name)
+ calc = {}
+ for pkg in pkgs:
+ data = self.get_data(pkg)
+ calc.setdefault(data, []).append(pkg)
+ maxlen = 0
+ totlen = 0
+ for data in calc:
+ val = len(data)
+ totlen += len(calc[data])
+ if val > maxlen:
+ maxlen = val
+ fmt = "%%-%ds %%6s (%%3d%%%%)" % maxlen
+ for data in sorted(calc):
+ val = len(calc[data])
+ msg(fmt % (str(data), loc_num(val), (100 * val) / totlen))
+ self.show_pkgs(msg, calc[data])
+
+ # pkg.vendor has weird values, for instance
+ def get_data(self, data):
+ if not hasattr(data, self.attr):
+ return self.unknown
+
+ val = getattr(data, self.attr)
+ if val is None:
+ return self.unknown
+ if type(val) == type([]):
+ return self.unknown
+
+ tval = str(val).strip()
+ if tval == "":
+ 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, data): # Special version for baseurl
+ val = self.oget_data(data)
+ if val == self.unknown:
+ return val
+ (scheme, netloc, path, query, fragid) = urlparse.urlsplit(val)
+ return "%s://%s/" % (scheme, netloc)
+
+class SizeRangeData:
+ def __init__(self, beg, msg):
+ self._beg = beg
+ self._msg = msg
+
+ def __cmp__(self, o):
+ if not hasattr(o, '_beg'):
+ return 1
+ return cmp(self._beg, o._beg)
+
+ def __str__(self):
+ return self._msg
+
+ def __len__(self):
+ return len(self._msg)
+
+ def __hash__(self):
+ return hash(self._msg)
+
+def size_get_data(self, data):
+ val = self.oget_data(data)
+ if val == self.unknown:
+ return val
+
+ # Even if it was sane, don't put 1GB and up here, or the alpha sorting
+ # won't be correct.
+ nums = (( 10 * 1024, " 10KB"),
+ ( 25 * 1024, " 25KB"),
+ ( 50 * 1024, " 50KB"),
+ ( 75 * 1024, " 75KB"),
+ (100 * 1024, "100KB"),
+ (250 * 1024, "250KB"),
+ (500 * 1024, "500KB"),
+ (750 * 1024, "750KB"),
+ ( 1 * 1024 * 1024, " 1MB"),
+ ( 5 * 1024 * 1024, " 5MB"),
+ ( 10 * 1024 * 1024, " 10MB"),
+ ( 50 * 1024 * 1024, " 50MB"),
+ (100 * 1024 * 1024, "100MB"),
+ (500 * 1024 * 1024, "500MB"),
+ )
+ pnum = (0, " 0KB")
+ for num in nums:
+ if val >= pnum[0] and val <= num[0]:
+ msg = "[ %s - %s ] " % (pnum[1], num[1])
+ return SizeRangeData(pnum[0], msg)
+ pnum = num
+ msg = "[ %s - %s ] " % (pnum[1], " " * len(pnum[1]))
+ return SizeRangeData(pnum[0], msg)
+
+def _nf2ascii(x):
+ """ does .encode("ascii", "replace") but it never fails. """
+ ret = []
+ for val in x:
+ if ord(val) >= 128:
+ val = '?'
+ ret.append(val)
+ return "".join(ret)
+
+def committer_get_data(self, data):
+ if not hasattr(data, self.attr):
+ return self.unknown
+ val = getattr(data, self.attr)
+
+ # No good way to get number of utf-8 code points Arghh.
+ val = val[0][1]
+ # .encode("ascii", "replace") fails as does .encode("utf-8")
+ val = _nf2ascii(val)
+ # Hacky way to get rid of version numbers...
+ return re.sub("""> .*""", '>', val)
+
+def _list_data_custom(conduit, data, func):
+ cmd = ListDataCommands(*data)
+ cmd.oget_data = cmd.get_data
+ cmd.get_data = types.MethodType(func, cmd)
+ conduit.registerCommand(cmd)
+
+ cmd = InfoDataCommands(*data)
+ cmd.oget_data = cmd.get_data
+ cmd.get_data = types.MethodType(func, cmd)
+ conduit.registerCommand(cmd)
+
+
+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))
+
+ _list_data_custom(conduit, ('baseurls', 'url'), url_get_data)
+ _list_data_custom(conduit, ('package-sizes', 'packagesize'), size_get_data)
+ _list_data_custom(conduit, ('archive-sizes', 'archivesize'), size_get_data)
+ _list_data_custom(conduit, ('installed-sizes', 'installedsize'),
+ size_get_data)
+
+ _list_data_custom(conduit, ('committers', 'changelog'),
+ committer_get_data)
+ # Buildtime/installtime/committime?
diff --git a/yum-utils.spec b/yum-utils.spec
index bc0d61b..7f33b82 100644
--- a/yum-utils.spec
+++ b/yum-utils.spec
@@ -203,6 +203,14 @@ Requires: yum >= 3.0.5
This plugin adds the command alias, and parses the aliases config. file to
enable aliases.
+%package -n yum-list-data
+Summary: Yum plugin to list aggregate package data
+Group: System Environment/Base
+Requires: yum >= 3.0.5
+
+%description -n yum-list-data
+This plugin adds the commands list-vendors, groups, baseurls, packagers,
+buildhosts, licenses and arches.
%prep
%setup -q
@@ -215,7 +223,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 +374,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>
More information about the Yum-cvs-commits
mailing list