From b16786098deb74e6827b5d634e771f4d4da79751 Mon Sep 17 00:00:00 2001 From: Fabian Groffen Date: Mon, 16 Oct 2006 08:55:51 +0000 Subject: [PATCH] Merge from trunk 4717:4719 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 | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pym/portage_util.py b/pym/portage_util.py index 182010436..32f673772 100644 --- a/pym/portage_util.py +++ b/pym/portage_util.py @@ -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): -- 2.26.2