Make SetConfig.getSetAtoms() raise a PackageSetNotFound exception when
authorZac Medico <zmedico@gentoo.org>
Tue, 28 Oct 2008 09:07:39 +0000 (09:07 -0000)
committerZac Medico <zmedico@gentoo.org>
Tue, 28 Oct 2008 09:07:39 +0000 (09:07 -0000)
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
pym/portage/sets/__init__.py

index 73d143e630cbafcaf1e198a9f664957316a8e1bd..1d324998c11d03157c9ed0ca7830a1fceeb7e0f5 100644 (file)
@@ -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:
index b892bb308f0e4d35b773d8349f10dcf6abf20165..a668c83246d938941e4aed7043cd547c5cd0010a 100644 (file)
@@ -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)