From 3b9dad5506e62806cd3b0e46adf7f2b23276853b Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Tue, 28 Oct 2008 09:07:39 +0000 Subject: Make SetConfig.getSetAtoms() raise a PackageSetNotFound exception when necessary and add handling code in emerge. This solves an unhandled KeyError that was raise when a nested set did not exist. Thanks to ABCD for reporting. svn path=/main/trunk/; revision=11732 --- pym/_emerge/__init__.py | 11 +++++++++-- pym/portage/sets/__init__.py | 20 +++++++++++++++++--- 2 files changed, 26 insertions(+), 5 deletions(-) (limited to 'pym') diff --git a/pym/_emerge/__init__.py b/pym/_emerge/__init__.py index 73d143e63..1d324998c 100644 --- a/pym/_emerge/__init__.py +++ b/pym/_emerge/__init__.py @@ -13698,15 +13698,22 @@ def expand_set_arguments(myfiles, myaction, root_config): display_missing_pkg_set(root_config, s) return (None, 1) setconfig.active.append(s) + try: + set_atoms = setconfig.getSetAtoms(s) + except portage.exception.PackageSetNotFound, e: + writemsg_level(("emerge: the given set '%s' " + \ + "contains a non-existent set named '%s'.\n") % \ + (s, e), level=logging.ERROR, noiselevel=-1) + return (None, 1) if myaction in unmerge_actions and \ not sets[s].supportsOperation("unmerge"): sys.stderr.write("emerge: the given set '%s' does " % s + \ "not support unmerge operations\n") retval = 1 - elif not setconfig.getSetAtoms(s): + elif not set_atoms: print "emerge: '%s' is an empty set" % s elif myaction not in do_not_expand: - newargs.extend(setconfig.getSetAtoms(s)) + newargs.extend(set_atoms) else: newargs.append(SETPREFIX+s) for e in sets[s].errors: diff --git a/pym/portage/sets/__init__.py b/pym/portage/sets/__init__.py index b892bb308..a668c8324 100644 --- a/pym/portage/sets/__init__.py +++ b/pym/portage/sets/__init__.py @@ -2,10 +2,14 @@ # Distributed under the terms of the GNU General Public License v2 # $Id$ +__all__ = ["SETPREFIX", "get_boolean", "SetConfigError", + "SetConfig", "load_default_config"] + import os from ConfigParser import SafeConfigParser, NoOptionError from portage import load_mod from portage.const import USER_CONFIG_PATH, GLOBAL_CONFIG_PATH +from portage.exception import PackageSetNotFound SETPREFIX = "@" @@ -131,7 +135,13 @@ class SetConfig(object): return self.psets.copy() def getSetAtoms(self, setname, ignorelist=None): - myset = self.getSets()[setname] + """ + This raises PackageSetNotFound if the give setname does not exist. + """ + try: + myset = self.getSets()[setname] + except KeyError: + raise PackageSetNotFound(setname) myatoms = myset.getAtoms() parser = self._parser extend = set() @@ -150,8 +160,12 @@ class SetConfig(object): ignorelist.add(setname) for n in myset.getNonAtoms(): - if n.startswith(SETPREFIX) and n[len(SETPREFIX):] in self.psets: - extend.add(n[len(SETPREFIX):]) + if n.startswith(SETPREFIX): + s = n[len(SETPREFIX):] + if s in self.psets: + extend.add(n[len(SETPREFIX):]) + else: + raise PackageSetNotFound(s) for s in ignorelist: extend.discard(s) -- cgit v1.2.3-1-g7c22