implement set arguments to reconfigure and create package sets on the commandline
authorMarius Mauch <genone@gentoo.org>
Sun, 28 Sep 2008 16:08:50 +0000 (16:08 -0000)
committerMarius Mauch <genone@gentoo.org>
Sun, 28 Sep 2008 16:08:50 +0000 (16:08 -0000)
svn path=/main/trunk/; revision=11581

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

index 09a92f23a9c0d4a35cd7a59d4ca96429e05101aa..39ab9f6619823351bfaf11d92deef12d57c60450 100644 (file)
@@ -13395,12 +13395,38 @@ def expand_set_arguments(myfiles, myaction, root_config):
        myfiles = newargs
        del newargs
        newargs = []
+
+       # separators for set arguments
+       ARG_START = "{"
+       ARG_END = "}"
        
+       for i in range(0, len(myfiles)):
+               if myfiles[i].startswith(SETPREFIX):
+                       x = myfiles[i][len(SETPREFIX):]
+                       start = x.find(ARG_START)
+                       end = x.find(ARG_END)
+                       if start > 0 and start < end:
+                               namepart = x[:start]
+                               argpart = x[start+1:end]
+                               
+                               # TODO: implement proper quoting
+                               args = argpart.split(",")
+                               options = {}
+                               for a in args:
+                                       if "=" in a:
+                                               k, v  = a.split("=", 1)
+                                               options[k] = v
+                                       else:
+                                               options[a] = "True"
+                               setconfig.update(namepart, options)
+                               myfiles[i] = SETPREFIX + namepart
+       sets = setconfig.getSets()
+
        # WARNING: all operators must be of equal length
        IS_OPERATOR = "/@"
        DIFF_OPERATOR = "-@"
        UNION_OPERATOR = "+@"
-       
+               
        for a in myfiles:
                if a.startswith(SETPREFIX):
                        # support simple set operations (intersection, difference and union)
index f88e1b6ee8fcab466b7fa9674d750cd51a0d0f06..8e6a0ea86b9592bf5bac70365d5b6a0f26784a23 100644 (file)
@@ -33,6 +33,29 @@ class SetConfig(SafeConfigParser):
                self._parsed = False
                self.active = []
 
+       def update(self, setname, options):
+               self.errors = []
+               if not setname in self.psets:
+                       options["name"] = setname
+                       
+                       # for the unlikely case that there is already a section with the requested setname
+                       import random
+                       while setname in self.sections():
+                               setname = "%08d" % random.randint(0, 10**10)
+                       
+                       self.add_section(setname)
+                       for k, v in options.items():
+                               self.set(setname, k, v)                 
+               else:
+                       section = self.psets[setname].creator
+                       if self.has_option(section, "multiset") and self.getboolean(section, "multiset"):
+                               self.errors.append("Invalid request to reconfigure set '%s' generated by multiset section '%s'" % (setname, section))
+                               return
+                       for k, v in options.items():
+                               self.set(section, k, v)
+               self._parsed = False
+               self._parse()
+
        def _parse(self):
                if self._parsed:
                        return