summaryrefslogtreecommitdiffstats
path: root/pym
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2007-06-21 10:57:55 +0000
committerZac Medico <zmedico@gentoo.org>2007-06-21 10:57:55 +0000
commit7d1934b2609cdc021ed6b24c76c2d1cff560c127 (patch)
treec03ec08f7ae05e12cd5fb30a79802998f5ede216 /pym
parentc9e582c047784201639c0dfda08b35626acf79c1 (diff)
downloadportage-7d1934b2609cdc021ed6b24c76c2d1cff560c127.tar.gz
portage-7d1934b2609cdc021ed6b24c76c2d1cff560c127.tar.bz2
portage-7d1934b2609cdc021ed6b24c76c2d1cff560c127.zip
Remove lots of unnecessary list generation via dict.keys().
svn path=/main/trunk/; revision=6911
Diffstat (limited to 'pym')
-rw-r--r--pym/emerge/__init__.py16
-rw-r--r--pym/portage/__init__.py35
2 files changed, 30 insertions, 21 deletions
diff --git a/pym/emerge/__init__.py b/pym/emerge/__init__.py
index 031691be6..e62611e8e 100644
--- a/pym/emerge/__init__.py
+++ b/pym/emerge/__init__.py
@@ -441,7 +441,7 @@ class search(object):
if self.searchre.search(full_desc):
self.matches["desc"].append([full_package,masked])
self.mlen=0
- for mtype in self.matches.keys():
+ for mtype in self.matches:
self.matches[mtype].sort()
self.mlen += len(self.matches[mtype])
@@ -450,7 +450,7 @@ class search(object):
print "\b\b \n[ Results for search key : "+white(self.searchkey)+" ]"
print "[ Applications found : "+white(str(self.mlen))+" ]"
print " "
- for mtype in self.matches.keys():
+ for mtype in self.matches:
for match,masked in self.matches[mtype]:
if mtype=="pkg":
catpack=match
@@ -2214,7 +2214,7 @@ class depgraph(object):
mylist = getlist(self.settings, "system")
worlddict=genericdict(worldlist)
- for x in worlddict.keys():
+ for x in worlddict:
if not portage.isvalidatom(x):
world_problems = True
continue
@@ -2697,7 +2697,7 @@ class depgraph(object):
if myfilesdict is None:
myfilesdict="[empty/missing/bad digest]"
else:
- for myfetchfile in myfilesdict.keys():
+ for myfetchfile in myfilesdict:
if myfetchfile not in myfetchlist:
mysize+=myfilesdict[myfetchfile]
myfetchlist.append(myfetchfile)
@@ -3612,7 +3612,7 @@ def unmerge(settings, myopts, vartree, unmerge_action, unmerge_files,
if not slotmap.has_key(myslot):
slotmap[myslot]={}
slotmap[myslot][localtree.dbapi.cpv_counter(mypkg)]=mypkg
- for myslot in slotmap.keys():
+ for myslot in slotmap:
counterkeys=slotmap[myslot].keys()
counterkeys.sort()
if not counterkeys:
@@ -3639,7 +3639,7 @@ def unmerge(settings, myopts, vartree, unmerge_action, unmerge_files,
finally:
if vdb_lock:
portage.locks.unlockdir(vdb_lock)
- for x in pkgmap.keys():
+ for x in pkgmap:
for y in localtree.dep_match(x):
if y not in pkgmap[x]["omitted"] and \
y not in pkgmap[x]["selected"] and \
@@ -3695,7 +3695,7 @@ def unmerge(settings, myopts, vartree, unmerge_action, unmerge_files,
if not autoclean:
countdown(int(settings["CLEAN_DELAY"]), ">>> Unmerging")
- for x in pkgmap.keys():
+ for x in pkgmap:
for y in pkgmap[x]["selected"]:
print ">>> Unmerging "+y+"..."
emergelog(xterm_titles, "=== Unmerging... ("+y+")")
@@ -3879,7 +3879,7 @@ def post_emerge(trees, mtimedb, retval):
if vardbapi.plib_registry.hasEntries():
print colorize("WARN", "!!!") + " existing preserved libs:"
plibdata = vardbapi.plib_registry.getPreservedLibs()
- for cpv in plibdata.keys():
+ for cpv in plibdata:
print colorize("WARN", ">>>") + " package: %s" % cpv
for f in plibdata[cpv]:
print colorize("WARN", " * ") + " - %s" % f
diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py
index d80a72d51..6e2d38781 100644
--- a/pym/portage/__init__.py
+++ b/pym/portage/__init__.py
@@ -1644,9 +1644,8 @@ class config(object):
def load_infodir(self,infodir):
self.modifying()
- if self.configdict.has_key("pkg"):
- for x in self.configdict["pkg"].keys():
- del self.configdict["pkg"][x]
+ if "pkg" in self.configdict:
+ self.configdict["pkg"].clear()
else:
writemsg("No pkg setup for settings instance?\n",
noiselevel=-1)
@@ -2105,8 +2104,7 @@ class config(object):
return self.virts_p
virts = self.getvirtuals(myroot)
if virts:
- myvkeys = virts.keys()
- for x in myvkeys:
+ for x in virts:
vkeysplit = x.split("/")
if not self.virts_p.has_key(vkeysplit[1]):
self.virts_p[vkeysplit[1]] = virts[x]
@@ -2227,7 +2225,16 @@ class config(object):
return x
def keys(self):
- return unique_array(flatten([x.keys() for x in self.lookuplist]))
+ return list(self)
+
+ def __iter__(self):
+ keys = set()
+ for d in self.lookuplist:
+ for k in d:
+ if k in keys:
+ continue
+ keys.add(k)
+ yield k
def __setitem__(self,mykey,myvalue):
"set a value; will be thrown away at reset() time"
@@ -2240,7 +2247,7 @@ class config(object):
def environ(self):
"return our locally-maintained environment"
mydict={}
- for x in self.keys():
+ for x in self:
myvalue = self[x]
if not isinstance(myvalue, basestring):
writemsg("!!! Non-string value in config: %s=%s\n" % \
@@ -2639,7 +2646,7 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0, locks_in_subdir=".locks",
noiselevel=-1)
return 0
del distlocks_subdir
- for myfile in filedict.keys():
+ for myfile in filedict:
"""
fetched status
0 nonexistent
@@ -2870,7 +2877,7 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0, locks_in_subdir=".locks",
else:
eout = portage.output.EOutput()
eout.quiet = mysettings.get("PORTAGE_QUIET", None) == "1"
- for x_key in mydigests[myfile].keys():
+ for x_key in mydigests[myfile]:
eout.ebegin("%s %s ;-)" % (myfile, x_key))
eout.eend(0)
fetched=2
@@ -3126,7 +3133,7 @@ def digestcheck(myfiles, mysettings, strict=0, justmanifest=0):
def spawnebuild(mydo,actionmap,mysettings,debug,alwaysdep=0,logfile=None):
if alwaysdep or "noauto" not in mysettings.features:
# process dependency first
- if "dep" in actionmap[mydo].keys():
+ if "dep" in actionmap[mydo]:
retval=spawnebuild(actionmap[mydo]["dep"],actionmap,mysettings,debug,alwaysdep=alwaysdep,logfile=logfile)
if retval:
return retval
@@ -3932,11 +3939,11 @@ def doebuild(myebuild, mydo, myroot, mysettings, debug=0, listonly=0,
# merge the deps in so we have again a 'full' actionmap
# be glad when this can die.
- for x in actionmap.keys():
+ for x in actionmap:
if len(actionmap_deps.get(x, [])):
actionmap[x]["dep"] = ' '.join(actionmap_deps[x])
- if mydo in actionmap.keys():
+ if mydo in actionmap:
retval = spawnebuild(mydo,
actionmap, mysettings, debug, logfile=logfile)
elif mydo=="qmerge":
@@ -4942,9 +4949,11 @@ class FetchlistDict(UserDict.DictMixin):
"""Returns the complete fetch list for a given package."""
return self.portdb.getfetchlist(pkg_key, mysettings=self.settings,
all=True, mytree=self.mytree)[1]
+ def __contains__(self):
+ return pkg_key in self.keys()
def has_key(self, pkg_key):
"""Returns true if the given package exists within pkgdir."""
- return pkg_key in self.keys()
+ return pkg_key in self
def keys(self):
"""Returns keys for all packages within pkgdir"""
return self.portdb.cp_list(self.cp, mytree=self.mytree)