Merge from trunk 4717:4719
authorFabian Groffen <grobian@gentoo.org>
Mon, 16 Oct 2006 08:55:51 +0000 (08:55 -0000)
committerFabian Groffen <grobian@gentoo.org>
Mon, 16 Oct 2006 08:55:51 +0000 (08:55 -0000)
Make grabdict incremental, so that keys occuring multiple times will
stack up instead of overwritting eachother.  Thanks to Sven Wegener for
this suggestion.  Simplify and optimize grabdict.  Thanks to Brian
Harring for suggesting this.

svn path=/main/branches/prefix/; revision=4721

pym/portage_util.py

index 182010436b2a1d0a293ae3443195748618bb9c44..32f673772842133ea3c736e9d788327097e41d23 100644 (file)
@@ -144,7 +144,7 @@ def stack_lists(lists, incremental=1):
                                new_list[y] = True
        return new_list.keys()
 
-def grabdict(myfilename, juststrings=0, empty=0, recursive=0):
+def grabdict(myfilename, juststrings=0, empty=0, recursive=0, incremental=1):
        """This function grabs the lines in a file, normalizes whitespace and returns lines in a dictionary"""
        newdict={}
        for x in grablines(myfilename, recursive):
@@ -157,10 +157,13 @@ def grabdict(myfilename, juststrings=0, empty=0, recursive=0):
                        continue
                if len(myline) < 1 and empty == 1:
                        continue
-               if juststrings:
-                       newdict[myline[0]]=string.join(myline[1:])
+               if incremental:
+                       newdict.setdefault(myline[0], []).extend(myline[1:])
                else:
-                       newdict[myline[0]]=myline[1:]
+                       newdict[myline[0]] = myline[1:]
+       if juststrings:
+               for k, v in newdict.iteritems():
+                       newdict[k] = " ".join(v)
        return newdict
 
 def grabdict_package(myfilename, juststrings=0, recursive=0):