[yum-git] cli.py output.py yum/comps.py yum/__init__.py yum/misc.py
Seth Vidal
skvidal at linux.duke.edu
Tue Apr 15 22:30:00 UTC 2008
cli.py | 39 ++++++----
output.py | 9 +-
yum/__init__.py | 199 ++++++++++++++++++++++++++++----------------------------
yum/comps.py | 53 ++++++++++++--
yum/misc.py | 11 ++-
5 files changed, 184 insertions(+), 127 deletions(-)
New commits:
commit 0af2ab2a5985c6000c12199b562144dcea63a410
Author: Seth Vidal <skvidal at fedoraproject.org>
Date: Tue Apr 15 18:27:10 2008 -0400
- make groups work for groups with different groupids but the same name (dumb!)
- make groupinfo and grouplist display properly in other languages
- add return_groups() method to comps object - returns all matches not just the first one like return_group() did
diff --git a/cli.py b/cli.py
index 0454c9a..9d093c1 100644
--- a/cli.py
+++ b/cli.py
@@ -804,20 +804,21 @@ class YumBaseCli(yum.YumBase, output.YumOutput):
uservisible=0
installed, available = self.doGroupLists(uservisible=uservisible)
-
+ mylang = yum.misc.get_my_lang_code()
+
if len(installed) > 0:
self.verbose_logger.log(yum.logginglevels.INFO_2,
_('Installed Groups:'))
for group in installed:
self.verbose_logger.log(yum.logginglevels.INFO_2, ' %s',
- group.name)
+ group.nameByLang(mylang))
if len(available) > 0:
self.verbose_logger.log(yum.logginglevels.INFO_2,
_('Available Groups:'))
for group in available:
self.verbose_logger.log(yum.logginglevels.INFO_2, ' %s',
- group.name)
+ group.nameByLang(mylang))
return 0, [_('Done')]
@@ -825,10 +826,12 @@ class YumBaseCli(yum.YumBase, output.YumOutput):
def returnGroupInfo(self, userlist):
"""returns complete information on a list of groups"""
for strng in userlist:
- group = self.comps.return_group(strng)
- if group:
+ group_matched = False
+ for group in self.comps.return_groups(strng):
self.displayPkgsInGroups(group)
- else:
+ group_matched = True
+
+ if not group_matched:
self.logger.error(_('Warning: Group %s does not exist.'), strng)
return 0, []
@@ -839,18 +842,22 @@ class YumBaseCli(yum.YumBase, output.YumOutput):
pkgs_used = []
for group_string in grouplist:
- group = self.comps.return_group(group_string)
- if not group:
- self.logger.critical(_('Warning: Group %s does not exist.'), group_string)
- continue
+ group_matched = False
+ for group in self.comps.return_groups(group_string):
+ group_matched = True
+
- try:
- txmbrs = self.selectGroup(group.groupid)
- except yum.Errors.GroupsError:
- self.logger.critical(_('Warning: Group %s does not exist.'), group_string)
+ try:
+ txmbrs = self.selectGroup(group.groupid)
+ except yum.Errors.GroupsError:
+ self.logger.critical(_('Warning: Group %s does not exist.'), group_string)
+ continue
+ else:
+ pkgs_used.extend(txmbrs)
+
+ if not group_matched:
+ self.logger.error(_('Warning: Group %s does not exist.'), group_strng)
continue
- else:
- pkgs_used.extend(txmbrs)
if not pkgs_used:
return 0, [_('No packages in any requested group available to install or update')]
diff --git a/output.py b/output.py
index cc80301..c0cbb02 100644
--- a/output.py
+++ b/output.py
@@ -29,7 +29,7 @@ import re # For YumTerm
from urlgrabber.progress import TextMeter
from urlgrabber.grabber import URLGrabError
-from yum.misc import sortPkgObj, prco_tuple_to_string, to_str, to_unicode_maybe
+from yum.misc import sortPkgObj, prco_tuple_to_string, to_str, to_unicode_maybe, get_my_lang_code
from rpmUtils.miscutils import checkSignals
from yum.constants import *
@@ -367,9 +367,10 @@ class YumOutput:
def displayPkgsInGroups(self, group):
- print _('\nGroup: %s') % group.name
- if group.description != "":
- print _(' Description: %s') % group.description.encode("UTF-8")
+ mylang = get_my_lang_code()
+ print _('\nGroup: %s') % group.nameByLang(mylang)
+ if group.descriptionByLang(mylang) != "":
+ print _(' Description: %s') % to_unicode_maybe(group.descriptionByLang(mylang))
if len(group.mandatory_packages) > 0:
print _(' Mandatory Packages:')
for item in sorted(group.mandatory_packages):
diff --git a/yum/__init__.py b/yum/__init__.py
index 3b029ca..6bde7b5 100644
--- a/yum/__init__.py
+++ b/yum/__init__.py
@@ -1726,107 +1726,109 @@ class YumBase(depsolve.Depsolve):
txmbrs_used = []
- thisgroup = self.comps.return_group(grpid)
- if not thisgroup:
+ thesegroups = self.comps.return_groups(grpid)
+ if not thesegroups:
raise Errors.GroupsError, _("No Group named %s exists") % grpid
- thisgroup.toremove = True
- pkgs = thisgroup.packages
- for pkg in thisgroup.packages:
- txmbrs = self.remove(name=pkg)
- txmbrs_used.extend(txmbrs)
- for txmbr in txmbrs:
- txmbr.groups.append(thisgroup.groupid)
-
+ for thisgroup in thesegroups:
+ thisgroup.toremove = True
+ pkgs = thisgroup.packages
+ for pkg in thisgroup.packages:
+ txmbrs = self.remove(name=pkg)
+ txmbrs_used.extend(txmbrs)
+ for txmbr in txmbrs:
+ txmbr.groups.append(thisgroup.groupid)
+
return txmbrs_used
def groupUnremove(self, grpid):
"""unmark any packages in the group from being removed"""
- thisgroup = self.comps.return_group(grpid)
- if not thisgroup:
+ thesegroups = self.comps.return_groups(grpid)
+ if not thesegroups:
raise Errors.GroupsError, _("No Group named %s exists") % grpid
- thisgroup.toremove = False
- pkgs = thisgroup.packages
- for pkg in thisgroup.packages:
- for txmbr in self.tsInfo:
- if txmbr.po.name == pkg and txmbr.po.state in TS_INSTALL_STATES:
- try:
- txmbr.groups.remove(grpid)
- except ValueError:
- self.verbose_logger.log(logginglevels.DEBUG_1,
- _("package %s was not marked in group %s"), txmbr.po,
- grpid)
- continue
-
- # if there aren't any other groups mentioned then remove the pkg
- if len(txmbr.groups) == 0:
- self.tsInfo.remove(txmbr.po.pkgtup)
+ for thisgroup in thesegroups:
+ thisgroup.toremove = False
+ pkgs = thisgroup.packages
+ for pkg in thisgroup.packages:
+ for txmbr in self.tsInfo:
+ if txmbr.po.name == pkg and txmbr.po.state in TS_INSTALL_STATES:
+ try:
+ txmbr.groups.remove(grpid)
+ except ValueError:
+ self.verbose_logger.log(logginglevels.DEBUG_1,
+ _("package %s was not marked in group %s"), txmbr.po,
+ grpid)
+ continue
+
+ # if there aren't any other groups mentioned then remove the pkg
+ if len(txmbr.groups) == 0:
+ self.tsInfo.remove(txmbr.po.pkgtup)
def selectGroup(self, grpid):
"""mark all the packages in the group to be installed
returns a list of transaction members it added to the transaction
set"""
-
- txmbrs_used = []
-
+
if not self.comps.has_group(grpid):
raise Errors.GroupsError, _("No Group named %s exists") % grpid
-
- thisgroup = self.comps.return_group(grpid)
- if not thisgroup:
+ txmbrs_used = []
+ thesegroups = self.comps.return_groups(grpid)
+
+ if not thesegroups:
raise Errors.GroupsError, _("No Group named %s exists") % grpid
-
- if thisgroup.selected:
- return txmbrs_used
-
- thisgroup.selected = True
-
- pkgs = []
- if 'mandatory' in self.conf.group_package_types:
- pkgs.extend(thisgroup.mandatory_packages)
- if 'default' in self.conf.group_package_types:
- pkgs.extend(thisgroup.default_packages)
- if 'optional' in self.conf.group_package_types:
- pkgs.extend(thisgroup.optional_packages)
- for pkg in pkgs:
- self.verbose_logger.log(logginglevels.DEBUG_2,
- _('Adding package %s from group %s'), pkg, thisgroup.groupid)
- try:
- txmbrs = self.install(name = pkg)
- except Errors.InstallError, e:
- self.verbose_logger.debug(_('No package named %s available to be installed'),
- pkg)
- else:
- txmbrs_used.extend(txmbrs)
- for txmbr in txmbrs:
- txmbr.groups.append(thisgroup.groupid)
-
- if self.conf.enable_group_conditionals:
- for condreq, cond in thisgroup.conditional_packages.iteritems():
- if self.isPackageInstalled(cond):
- try:
- txmbrs = self.install(name = condreq)
- except Errors.InstallError:
- # we don't care if the package doesn't exist
- continue
+ for thisgroup in thesegroups:
+ if thisgroup.selected:
+ continue
+
+ thisgroup.selected = True
+
+ pkgs = []
+ if 'mandatory' in self.conf.group_package_types:
+ pkgs.extend(thisgroup.mandatory_packages)
+ if 'default' in self.conf.group_package_types:
+ pkgs.extend(thisgroup.default_packages)
+ if 'optional' in self.conf.group_package_types:
+ pkgs.extend(thisgroup.optional_packages)
+
+ for pkg in pkgs:
+ self.verbose_logger.log(logginglevels.DEBUG_2,
+ _('Adding package %s from group %s'), pkg, thisgroup.groupid)
+ try:
+ txmbrs = self.install(name = pkg)
+ except Errors.InstallError, e:
+ self.verbose_logger.debug(_('No package named %s available to be installed'),
+ pkg)
+ else:
txmbrs_used.extend(txmbrs)
for txmbr in txmbrs:
txmbr.groups.append(thisgroup.groupid)
- continue
- # Otherwise we hook into tsInfo.add
- pkgs = self.pkgSack.searchNevra(name=condreq)
- if pkgs:
- pkgs = self.bestPackagesFromList(pkgs)
- if self.tsInfo.conditionals.has_key(cond):
- self.tsInfo.conditionals[cond].extend(pkgs)
- else:
- self.tsInfo.conditionals[cond] = pkgs
+
+ if self.conf.enable_group_conditionals:
+ for condreq, cond in thisgroup.conditional_packages.iteritems():
+ if self.isPackageInstalled(cond):
+ try:
+ txmbrs = self.install(name = condreq)
+ except Errors.InstallError:
+ # we don't care if the package doesn't exist
+ continue
+ txmbrs_used.extend(txmbrs)
+ for txmbr in txmbrs:
+ txmbr.groups.append(thisgroup.groupid)
+ continue
+ # Otherwise we hook into tsInfo.add
+ pkgs = self.pkgSack.searchNevra(name=condreq)
+ if pkgs:
+ pkgs = self.bestPackagesFromList(pkgs)
+ if self.tsInfo.conditionals.has_key(cond):
+ self.tsInfo.conditionals[cond].extend(pkgs)
+ else:
+ self.tsInfo.conditionals[cond] = pkgs
return txmbrs_used
@@ -1836,27 +1838,28 @@ class YumBase(depsolve.Depsolve):
if not self.comps.has_group(grpid):
raise Errors.GroupsError, _("No Group named %s exists") % grpid
- thisgroup = self.comps.return_group(grpid)
- if not thisgroup:
+ thesegroups = self.comps.return_groups(grpid)
+ if not thesegroups:
raise Errors.GroupsError, _("No Group named %s exists") % grpid
- thisgroup.selected = False
-
- for pkgname in thisgroup.packages:
-
- for txmbr in self.tsInfo:
- if txmbr.po.name == pkgname and txmbr.po.state in TS_INSTALL_STATES:
- try:
- txmbr.groups.remove(grpid)
- except ValueError:
- self.verbose_logger.log(logginglevels.DEBUG_1,
- _("package %s was not marked in group %s"), txmbr.po,
- grpid)
- continue
-
- # if there aren't any other groups mentioned then remove the pkg
- if len(txmbr.groups) == 0:
- self.tsInfo.remove(txmbr.po.pkgtup)
+ for thisgroup in thesegroups:
+ thisgroup.selected = False
+
+ for pkgname in thisgroup.packages:
+
+ for txmbr in self.tsInfo:
+ if txmbr.po.name == pkgname and txmbr.po.state in TS_INSTALL_STATES:
+ try:
+ txmbr.groups.remove(grpid)
+ except ValueError:
+ self.verbose_logger.log(logginglevels.DEBUG_1,
+ _("package %s was not marked in group %s"), txmbr.po,
+ grpid)
+ continue
+
+ # if there aren't any other groups mentioned then remove the pkg
+ if len(txmbr.groups) == 0:
+ self.tsInfo.remove(txmbr.po.pkgtup)
@@ -2444,6 +2447,10 @@ class YumBase(depsolve.Depsolve):
ver=nevra_dict['version'], rel=nevra_dict['release'])
if len(pkgs) == 0:
+ # FIXME we should give the caller some nice way to hush this warning
+ # probably just a kwarg of 'silence_warnings' or something
+ # b/c when this is called from groupRemove() it makes a lot of
+ # garbage noise
self.logger.warning(_("No package matched to remove"))
for po in pkgs:
diff --git a/yum/comps.py b/yum/comps.py
index fe4a022..f9b94ed 100755
--- a/yum/comps.py
+++ b/yum/comps.py
@@ -71,19 +71,36 @@ class Group(object):
return lst
packages = property(_packageiter)
-
+
+ def _expand_languages(self, lang):
+ import gettext
+ languages = [lang]
+
+ if 'C' not in languages:
+ languages.append('C')
+
+ # now normalize and expand the languages
+ nelangs = []
+ for lang in languages:
+ for nelang in gettext._expand_lang(lang):
+ if nelang not in nelangs:
+ nelangs.append(nelang)
+ return nelangs
+
def nameByLang(self, lang):
- if self.translated_name.has_key[lang]:
- return self.translated_name[lang]
- else:
- return self.name
+
+ for langcode in self._expand_languages(lang):
+ if self.translated_name.has_key(langcode):
+ return self.translated_name[langcode]
+
+ return self.name
def descriptionByLang(self, lang):
- if self.translated_description.has_key[lang]:
- return self.translated_description[lang]
- else:
- return self.description
+ for langcode in self._expand_languages(lang):
+ if self.translated_description.has_key(langcode):
+ return self.translated_description[langcode]
+ return self.description
def parse(self, elem):
for child in elem:
@@ -367,7 +384,7 @@ class Comps(object):
def has_group(self, grpid):
- exists = self.return_group(grpid)
+ exists = self.return_groups(grpid)
if exists:
return True
@@ -388,6 +405,22 @@ class Comps(object):
return None
+ def return_groups(self, grpid):
+ returns = {}
+ if self._groups.has_key(grpid):
+ thisgroup = self._groups[grpid]
+ returns[thisgroup.groupid] = thisgroup
+
+ # do matches against group names and ids, too
+ for group in self.groups:
+ names = [ group.name, group.groupid ]
+ names.extend(group.translated_name.values())
+ if grpid in names:
+ returns[group.groupid] = group
+
+ return returns.values()
+
+
def add(self, srcfile = None):
if not srcfile:
diff --git a/yum/misc.py b/yum/misc.py
index d710ad1..2b4dbfb 100644
--- a/yum/misc.py
+++ b/yum/misc.py
@@ -551,4 +551,13 @@ def to_str(obj):
obj = str(obj)
return obj
-
+def get_my_lang_code():
+ import locale
+ mylang = locale.getlocale()
+ if mylang == (None, None): # odd :)
+ mylang = 'C'
+ else:
+ mylang = '.'.join(mylang)
+
+ return mylang
+
More information about the Yum-cvs-commits
mailing list