first version of set integration in emerge
authorMarius Mauch <genone@gentoo.org>
Fri, 5 Oct 2007 19:29:17 +0000 (19:29 -0000)
committerMarius Mauch <genone@gentoo.org>
Fri, 5 Oct 2007 19:29:17 +0000 (19:29 -0000)
svn path=/main/trunk/; revision=7956

pym/emerge/__init__.py
pym/portage/sets/__init__.py

index efe456d3f108374226eee3978d46f5c91c12d081..eb47084a18a3bafbf5602e7daf1f8f60048fe5bb 100644 (file)
@@ -31,7 +31,7 @@ except ImportError:
        import portage
 del os.environ["PORTAGE_LEGACY_GLOBALS"]
 from portage import digraph, portdbapi
-from portage.const import NEWS_LIB_PATH, CACHE_PATH, PRIVATE_PATH
+from portage.const import NEWS_LIB_PATH, CACHE_PATH, PRIVATE_PATH, USER_CONFIG_PATH
 
 import emerge.help
 import portage.xpak, commands, errno, re, socket, time, types
@@ -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 InternalPackageSet
+from portage.sets import InternalPackageSet, SetConfig, make_default_config
 from portage.sets.profiles import PackagesSystemSet as SystemSet
 from portage.sets.files import WorldSet
 
@@ -6381,6 +6381,22 @@ def emerge_main():
                        print colorize("BAD", "\n*** emerging by path is broken and may not always work!!!\n")
                        break
 
+       if myaction not in ["search", "metadata", "sync"]:
+               setconfigpaths = ["/usr/share/portage/config/sets.conf", os.path.join(settings["PORTDIR"], "sets.conf"), \
+                       os.path.join(os.sep, settings["PORTAGE_CONFIGROOT"], USER_CONFIG_PATH, "sets.conf")]
+               #setconfig = SetConfig(setconfigpaths, settings, trees[settings["ROOT"]])
+               setconfig = make_default_config(settings, trees[settings["ROOT"]])
+               del setconfigpaths
+               packagesets, setconfig_errors = setconfig.getSetsWithAliases()
+               for s in packagesets:
+                       if s in myfiles:
+                               # TODO: check if the current setname also resolves to a package name
+                               if myaction in ["unmerge", "prune", "clean", "depclean"] and not packagesets[s].supportsOperation("unmerge"):
+                                       print "emerge: the given set %s does not support unmerge operations" % s
+                                       sys.exit(1)
+                               myfiles.extend(packagesets[s].getAtoms())
+                               myfiles.remove(s)
+
        if ("--tree" in myopts) and ("--columns" in myopts):
                print "emerge: can't specify both of \"--tree\" and \"--columns\"."
                sys.exit(1)
index 746a7e7a9d8e1c2696971d5e43985d9ea5246a62..c65cd8f89a9f25c7b338105657ff4bd4bdec6ca6 100644 (file)
@@ -174,8 +174,10 @@ class SetConfig(SafeConfigParser):
                self.psets = {}
                self.trees = trees
                self.settings = settings
-       
+               self._parsed = False
        def _parse(self):
+               if self._parsed:
+                       return
                for sname in self.sections():
                        # find classname for current section, default to file based sets
                        if not self.has_option(sname, "class"):
@@ -219,11 +221,25 @@ class SetConfig(SafeConfigParser):
                                else:
                                        self.errors.append("'%s' does not support individual set creation, section '%s' must be configured as multiset" % (classname, sname))
                                        continue
+               self._parsed = True
        
        def getSets(self):
                self._parse()
                return (self.psets, self.errors)
 
+       def getSetsWithAliases(self):
+               self._parse()
+               shortnames = {}
+               for name in self.psets:
+                       mysplit = name.split("/")
+                       if len(mysplit) > 1 and mysplit[-1] != "":
+                               if mysplit[-1] in shortnames:
+                                       del shortnames[mysplit[-1]]
+                               else:
+                                       shortnames[mysplit[-1]] = self.psets[name]
+               shortnames.update(self.psets)
+               return (shortnames, self.errors)
+
 def make_default_config(settings, trees):
        sc = SetConfig([], settings, trees)
        sc.add_section("security")