Fix setconfig loader to use config files instead of hardcoded fallbacks
authorMarius Mauch <genone@gentoo.org>
Tue, 4 Dec 2007 09:58:22 +0000 (09:58 -0000)
committerMarius Mauch <genone@gentoo.org>
Tue, 4 Dec 2007 09:58:22 +0000 (09:58 -0000)
svn path=/main/trunk/; revision=8839

bin/emaint
pym/_emerge/__init__.py
pym/portage/sets/__init__.py

index d9f74a2251f9f701dc82f61296ba6711d7b3b007..a5d7566f225a4b52fa8b6b287e121e9368b13ad4 100755 (executable)
@@ -23,8 +23,8 @@ class WorldHandler(object):
                self.not_installed = []
                self.invalid_category = []
                self.okay = []
-               from portage.sets import make_default_config
-               setconfig = make_default_config(portage.settings,
+               from portage.sets import load_default_config
+               setconfig = load_default_config(portage.settings,
                        portage.db[portage.settings["ROOT"]])
                self._sets = setconfig.getSetsWithAliases()
 
index 4af56b273f2efad8c90ace6108ca05c43f47b37c..0d97e6190312cd6ad7d544dbddd4d964dc991b34 100644 (file)
@@ -52,7 +52,7 @@ import portage.exception
 from portage.data import secpass
 from portage.util import normalize_path as normpath
 from portage.util import writemsg
-from portage.sets import make_default_config, SETPREFIX
+from portage.sets import load_default_config, SETPREFIX
 from portage.sets.base import InternalPackageSet
 
 from itertools import chain, izip
@@ -586,7 +586,7 @@ class RootConfig(object):
                self.settings = trees["vartree"].settings
                self.root = self.settings["ROOT"]
                self.setconfig = setconfig
-               self.sets = self.setconfig.getSetsWithAliases()
+               self.sets = self.setconfig.getSets()
 
 def create_world_atom(pkg_key, metadata, args_set, root_config):
        """Create a new atom for the world file if one does not exist.  If the
@@ -6687,7 +6687,7 @@ def load_emerge_config(trees=None):
 
        for root, root_trees in trees.iteritems():
                settings = root_trees["vartree"].settings
-               setconfig = make_default_config(settings, root_trees)
+               setconfig = load_default_config(settings, root_trees)
                root_trees["root_config"] = RootConfig(root_trees, setconfig)
 
        settings = trees["/"]["vartree"].settings
@@ -6913,6 +6913,12 @@ def emerge_main():
                root_config = trees[settings["ROOT"]]["root_config"]
                setconfig = root_config.setconfig
                sets = root_config.sets
+               # emerge relies on the existance of sets with names "world" and "system"
+               for s in ("world", "system"):
+                       if s not in sets:
+                               print "emerge: incomplete set configuration, no set defined for \"%s\"" % s
+                               print "        sets defined: %s" % ", ".join(sets)
+                               return 1
                newargs = []
                for a in myfiles:
                        if a in ("system", "world"):
index 30c2bff495711cc152b695440b9f4ee5d2fecc58..d92eb3130f118dccfda354a027396fce83635a53 100644 (file)
@@ -5,10 +5,7 @@
 import os
 from ConfigParser import SafeConfigParser, NoOptionError
 from portage import load_mod
-
-DEFAULT_SETS = ["world", "system", "everything", "security"] \
-       +["package_"+x for x in ["mask", "unmask", "use", "keywords"]]
-del x
+from portage.const import USER_CONFIG_PATH, GLOBAL_CONFIG_PATH
 
 SETPREFIX = "@"
 
@@ -79,65 +76,31 @@ class SetConfig(SafeConfigParser):
                self._parse()
                return self.psets
 
-       def getSetsWithAliases(self):
-               self._parse()
-               if not self.aliases:
-                       shortnames = {}
-                       for name in self.psets:
-                               mysplit = name.split("/")
-                               if len(mysplit) > 1 and mysplit[0] == "sets" and mysplit[-1] != "":
-                                       if mysplit[-1] in shortnames:
-                                               del shortnames[mysplit[-1]]
-                                       else:
-                                               shortnames[mysplit[-1]] = self.psets[name]
-                       shortnames.update(self.psets)
-                       self.aliases = shortnames
-               return self.aliases
-
        def getSetAtoms(self, setname, ignorelist=None):
-               myset = self.getSetsWithAliases()[setname]
+               myset = self.getSets()[setname]
                myatoms = myset.getAtoms()
                if ignorelist is None:
                        ignorelist = set()
                ignorelist.add(setname)
                for n in myset.getNonAtoms():
-                       if n[0] == SETPREFIX and n[1:] in self.aliases:
+                       if n[0] == SETPREFIX and n[1:] in self.psets
                                if n[1:] not in ignorelist:
                                        myatoms.update(self.getSetAtoms(n[1:],
                                                ignorelist=ignorelist))
                return myatoms
 
-def make_default_config(settings, trees):
-       sc = SetConfig([], settings, trees)
-       sc.add_section("security")
-       sc.set("security", "class", "portage.sets.security.NewAffectedSet")
-       
-       sc.add_section("system")
-       sc.set("system", "class", "portage.sets.profiles.PackagesSystemSet")
-       
-       sc.add_section("world")
-       sc.set("world", "class", "portage.sets.files.WorldSet")
-       
-       sc.add_section("everything")
-       sc.set("everything", "class", "portage.sets.dbapi.EverythingSet")
-
-       sc.add_section("config")
-       sc.set("config", "class", "portage.sets.files.ConfigFileSet")
-       sc.set("config", "multiset", "true")
-       
-       sc.add_section("user-sets")
-       sc.set("user-sets", "class", "portage.sets.files.StaticFileSet")
-       sc.set("user-sets", "multiset", "true")
-
-       sc.add_section("rebuild-needed")
-       sc.set("rebuild-needed", "class", "portage.sets.dbapi.PreservedLibraryConsumerSet")
-       
-       return sc
+def load_default_config(settings, trees):
+       setconfigpaths = [os.path.join(GLOBAL_CONFIG_PATH, "sets.conf")]
+       setconfigpaths.append(os.path.join(settings["PORTDIR"], "sets.conf"))
+       setconfigpaths += [os.path.join(x, "sets.conf") for x in settings["PORDIR_OVERLAY"].split()]
+       setconfigpaths.append(os.path.join(settings["PORTAGE_CONFIGROOT"],
+               USER_CONFIG_PATH.lstrip(os.path.sep), "sets.conf"))
+       return SetConfig(setconfigpaths, settings, trees)
 
 # adhoc test code
 if __name__ == "__main__":
        import portage
-       sc = make_default_config(portage.settings, portage.db["/"])
+       sc = load_default_config(portage.settings, portage.db["/"])
        l, e = sc.getSets()
        for x in l:
                print x+":"