summaryrefslogtreecommitdiffstats
path: root/bitbake
diff options
context:
space:
mode:
authorChris Larson <clarson@mvista.com>2009-06-11 13:10:04 -0700
committerRichard Purdie <rpurdie@linux.intel.com>2010-03-22 15:01:59 +0000
commitada2a8494a88b59de25c0a44fce30190f560eff4 (patch)
tree67f60f7ae769b74815757e45c12e4d694270a802 /bitbake
parent9d9b47bae4b880ec57eda0e647b1d24fbc3ba3cf (diff)
downloadpoky-ada2a8494a88b59de25c0a44fce30190f560eff4.tar.gz
Avoid unnecessary calls to keys() when iterating over dictionaries.
dict objects provide an __iter__ method for the iteration which gives you the keys, so calling keys directly is unnecessary, and isn't really a best practice. The only time you really need to call the keys is if there's a danger of the dict changing out from underneith you, either due to external forces or due to modification of the iterable in the loop. Iterations over os.environ are apparently subject to such changes, so they must continue to use keys(). As an aside, also switches a couple spots to using sorted() rather than creating a temporary list with keys() and sorting that. (Bitbake rev: 5b6ccb16c6e71e23dac6920cd2df994d67c2587b) Signed-off-by: Chris Larson <clarson@mvista.com> Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
Diffstat (limited to 'bitbake')
-rw-r--r--bitbake/lib/bb/cooker.py9
-rw-r--r--bitbake/lib/bb/data_smart.py4
-rw-r--r--bitbake/lib/bb/fetch/__init__.py4
-rw-r--r--bitbake/lib/bb/manifest.py2
-rw-r--r--bitbake/lib/bb/providers.py14
-rw-r--r--bitbake/lib/bb/shell.py18
6 files changed, 21 insertions, 30 deletions
diff --git a/bitbake/lib/bb/cooker.py b/bitbake/lib/bb/cooker.py
index 5f9becccac..938bdeaaea 100644
--- a/bitbake/lib/bb/cooker.py
+++ b/bitbake/lib/bb/cooker.py
@@ -219,18 +219,15 @@ class BBCooker:
219 latest_versions = {} 219 latest_versions = {}
220 220
221 # Sort by priority 221 # Sort by priority
222 for pn in pkg_pn.keys(): 222 for pn in pkg_pn:
223 (last_ver,last_file,pref_ver,pref_file) = bb.providers.findBestProvider(pn, self.configuration.data, self.status) 223 (last_ver,last_file,pref_ver,pref_file) = bb.providers.findBestProvider(pn, self.configuration.data, self.status)
224 preferred_versions[pn] = (pref_ver, pref_file) 224 preferred_versions[pn] = (pref_ver, pref_file)
225 latest_versions[pn] = (last_ver, last_file) 225 latest_versions[pn] = (last_ver, last_file)
226 226
227 pkg_list = pkg_pn.keys()
228 pkg_list.sort()
229
230 bb.msg.plain("%-35s %25s %25s" % ("Package Name", "Latest Version", "Preferred Version")) 227 bb.msg.plain("%-35s %25s %25s" % ("Package Name", "Latest Version", "Preferred Version"))
231 bb.msg.plain("%-35s %25s %25s\n" % ("============", "==============", "=================")) 228 bb.msg.plain("%-35s %25s %25s\n" % ("============", "==============", "================="))
232 229
233 for p in pkg_list: 230 for p in sorted(pkg_pn):
234 pref = preferred_versions[p] 231 pref = preferred_versions[p]
235 latest = latest_versions[p] 232 latest = latest_versions[p]
236 233
@@ -487,7 +484,7 @@ class BBCooker:
487 self.status.preferred[providee] = provider 484 self.status.preferred[providee] = provider
488 485
489 # Calculate priorities for each file 486 # Calculate priorities for each file
490 for p in self.status.pkg_fn.keys(): 487 for p in self.status.pkg_fn:
491 self.status.bbfile_priority[p] = calc_bbfile_priority(p) 488 self.status.bbfile_priority[p] = calc_bbfile_priority(p)
492 489
493 def buildWorldTargetList(self): 490 def buildWorldTargetList(self):
diff --git a/bitbake/lib/bb/data_smart.py b/bitbake/lib/bb/data_smart.py
index 988d5c3578..dac7fb705e 100644
--- a/bitbake/lib/bb/data_smart.py
+++ b/bitbake/lib/bb/data_smart.py
@@ -219,7 +219,7 @@ class DataSmart:
219 if not var in self.dict: 219 if not var in self.dict:
220 self._makeShadowCopy(var) 220 self._makeShadowCopy(var)
221 221
222 for i in flags.keys(): 222 for i in flags:
223 if i == "content": 223 if i == "content":
224 continue 224 continue
225 self.dict[var][i] = flags[i] 225 self.dict[var][i] = flags[i]
@@ -229,7 +229,7 @@ class DataSmart:
229 flags = {} 229 flags = {}
230 230
231 if local_var: 231 if local_var:
232 for i in local_var.keys(): 232 for i in local_var:
233 if i == "content": 233 if i == "content":
234 continue 234 continue
235 flags[i] = local_var[i] 235 flags[i] = local_var[i]
diff --git a/bitbake/lib/bb/fetch/__init__.py b/bitbake/lib/bb/fetch/__init__.py
index 435c02683c..d181eea71b 100644
--- a/bitbake/lib/bb/fetch/__init__.py
+++ b/bitbake/lib/bb/fetch/__init__.py
@@ -139,7 +139,7 @@ def encodeurl(decoded):
139 url += "%s" % host 139 url += "%s" % host
140 url += "%s" % path 140 url += "%s" % path
141 if p: 141 if p:
142 for parm in p.keys(): 142 for parm in p:
143 url += ";%s=%s" % (parm, p[parm]) 143 url += ";%s=%s" % (parm, p[parm])
144 144
145 return url 145 return url
@@ -169,7 +169,7 @@ def uri_replace(uri, uri_find, uri_replace, d):
169# bb.msg.note(1, bb.msg.domain.Fetcher, "uri_replace: no match") 169# bb.msg.note(1, bb.msg.domain.Fetcher, "uri_replace: no match")
170 return uri 170 return uri
171# else: 171# else:
172# for j in i.keys(): 172# for j in i:
173# FIXME: apply replacements against options 173# FIXME: apply replacements against options
174 return bb.encodeurl(result_decoded) 174 return bb.encodeurl(result_decoded)
175 175
diff --git a/bitbake/lib/bb/manifest.py b/bitbake/lib/bb/manifest.py
index 4e4b7d98ec..418367759f 100644
--- a/bitbake/lib/bb/manifest.py
+++ b/bitbake/lib/bb/manifest.py
@@ -96,7 +96,7 @@ def mangle (func, line, d):
96 varmap["${datadir}"] = "${STAGING_DATADIR}" 96 varmap["${datadir}"] = "${STAGING_DATADIR}"
97 97
98 matched = 0 98 matched = 0
99 for key in varmap.keys(): 99 for key in varmap:
100 if dest.startswith(key): 100 if dest.startswith(key):
101 dest = varmap[key] + "/" + dest[len(key):] 101 dest = varmap[key] + "/" + dest[len(key):]
102 matched = 1 102 matched = 1
diff --git a/bitbake/lib/bb/providers.py b/bitbake/lib/bb/providers.py
index 8617251ca3..c9fe7c7d7f 100644
--- a/bitbake/lib/bb/providers.py
+++ b/bitbake/lib/bb/providers.py
@@ -50,14 +50,10 @@ def sortPriorities(pn, dataCache, pkg_pn = None):
50 if preference not in priorities[priority]: 50 if preference not in priorities[priority]:
51 priorities[priority][preference] = [] 51 priorities[priority][preference] = []
52 priorities[priority][preference].append(f) 52 priorities[priority][preference].append(f)
53 pri_list = priorities.keys()
54 pri_list.sort(lambda a, b: a - b)
55 tmp_pn = [] 53 tmp_pn = []
56 for pri in pri_list: 54 for pri in sorted(priorities, lambda a, b: a - b):
57 pref_list = priorities[pri].keys()
58 pref_list.sort(lambda a, b: b - a)
59 tmp_pref = [] 55 tmp_pref = []
60 for pref in pref_list: 56 for pref in sorted(priorities[pri], lambda a, b: b - a):
61 tmp_pref.extend(priorities[pri][pref]) 57 tmp_pref.extend(priorities[pri][pref])
62 tmp_pn = [tmp_pref] + tmp_pn 58 tmp_pn = [tmp_pref] + tmp_pn
63 59
@@ -193,17 +189,17 @@ def _filterProviders(providers, item, cfgData, dataCache):
193 pkg_pn[pn] = [] 189 pkg_pn[pn] = []
194 pkg_pn[pn].append(p) 190 pkg_pn[pn].append(p)
195 191
196 bb.msg.debug(1, bb.msg.domain.Provider, "providers for %s are: %s" % (item, pkg_pn.keys())) 192 bb.msg.debug(1, bb.msg.domain.Provider, "providers for %s are: %s" % (item, pkg_pn()))
197 193
198 # First add PREFERRED_VERSIONS 194 # First add PREFERRED_VERSIONS
199 for pn in pkg_pn.keys(): 195 for pn in pkg_pn():
200 sortpkg_pn[pn] = sortPriorities(pn, dataCache, pkg_pn) 196 sortpkg_pn[pn] = sortPriorities(pn, dataCache, pkg_pn)
201 preferred_versions[pn] = findPreferredProvider(pn, cfgData, dataCache, sortpkg_pn[pn], item) 197 preferred_versions[pn] = findPreferredProvider(pn, cfgData, dataCache, sortpkg_pn[pn], item)
202 if preferred_versions[pn][1]: 198 if preferred_versions[pn][1]:
203 eligible.append(preferred_versions[pn][1]) 199 eligible.append(preferred_versions[pn][1])
204 200
205 # Now add latest verisons 201 # Now add latest verisons
206 for pn in sortpkg_pn.keys(): 202 for pn in sortpkg_pn():
207 if pn in preferred_versions and preferred_versions[pn][1]: 203 if pn in preferred_versions and preferred_versions[pn][1]:
208 continue 204 continue
209 preferred_versions[pn] = findLatestProvider(pn, cfgData, dataCache, sortpkg_pn[pn][0]) 205 preferred_versions[pn] = findLatestProvider(pn, cfgData, dataCache, sortpkg_pn[pn][0])
diff --git a/bitbake/lib/bb/shell.py b/bitbake/lib/bb/shell.py
index 66e51719a4..7abea0f126 100644
--- a/bitbake/lib/bb/shell.py
+++ b/bitbake/lib/bb/shell.py
@@ -147,7 +147,7 @@ class BitBakeShellCommands:
147 global last_exception 147 global last_exception
148 globexpr = params[0] 148 globexpr = params[0]
149 self._checkParsed() 149 self._checkParsed()
150 names = globfilter( cooker.status.pkg_pn.keys(), globexpr ) 150 names = globfilter( cooker.status.pkg_pn, globexpr )
151 if len( names ) == 0: names = [ globexpr ] 151 if len( names ) == 0: names = [ globexpr ]
152 print "SHELL: Building %s" % ' '.join( names ) 152 print "SHELL: Building %s" % ' '.join( names )
153 153
@@ -294,9 +294,7 @@ class BitBakeShellCommands:
294 def help( self, params ): 294 def help( self, params ):
295 """Show a comprehensive list of commands and their purpose""" 295 """Show a comprehensive list of commands and their purpose"""
296 print "="*30, "Available Commands", "="*30 296 print "="*30, "Available Commands", "="*30
297 allcmds = cmds.keys() 297 for cmd in sorted(cmds):
298 allcmds.sort()
299 for cmd in allcmds:
300 function,numparams,usage,helptext = cmds[cmd] 298 function,numparams,usage,helptext = cmds[cmd]
301 print "| %s | %s" % (usage.ljust(30), helptext) 299 print "| %s | %s" % (usage.ljust(30), helptext)
302 print "="*78 300 print "="*78
@@ -322,10 +320,10 @@ class BitBakeShellCommands:
322 what, globexpr = params 320 what, globexpr = params
323 if what == "files": 321 if what == "files":
324 self._checkParsed() 322 self._checkParsed()
325 for key in globfilter( cooker.status.pkg_fn.keys(), globexpr ): print key 323 for key in globfilter( cooker.status.pkg_fn, globexpr ): print key
326 elif what == "providers": 324 elif what == "providers":
327 self._checkParsed() 325 self._checkParsed()
328 for key in globfilter( cooker.status.pkg_pn.keys(), globexpr ): print key 326 for key in globfilter( cooker.status.pkg_pn, globexpr ): print key
329 else: 327 else:
330 print "Usage: match %s" % self.print_.usage 328 print "Usage: match %s" % self.print_.usage
331 match.usage = "<files|providers> <glob>" 329 match.usage = "<files|providers> <glob>"
@@ -473,10 +471,10 @@ SRC_URI = ""
473 what = params[0] 471 what = params[0]
474 if what == "files": 472 if what == "files":
475 self._checkParsed() 473 self._checkParsed()
476 for key in cooker.status.pkg_fn.keys(): print key 474 for key in cooker.status.pkg_fn: print key
477 elif what == "providers": 475 elif what == "providers":
478 self._checkParsed() 476 self._checkParsed()
479 for key in cooker.status.providers.keys(): print key 477 for key in cooker.status.providers: print key
480 else: 478 else:
481 print "Usage: print %s" % self.print_.usage 479 print "Usage: print %s" % self.print_.usage
482 print_.usage = "<files|providers>" 480 print_.usage = "<files|providers>"
@@ -571,7 +569,7 @@ def completeFilePath( bbfile ):
571 """Get the complete bbfile path""" 569 """Get the complete bbfile path"""
572 if not cooker.status: return bbfile 570 if not cooker.status: return bbfile
573 if not cooker.status.pkg_fn: return bbfile 571 if not cooker.status.pkg_fn: return bbfile
574 for key in cooker.status.pkg_fn.keys(): 572 for key in cooker.status.pkg_fn:
575 if key.endswith( bbfile ): 573 if key.endswith( bbfile ):
576 return key 574 return key
577 return bbfile 575 return bbfile
@@ -615,7 +613,7 @@ def completer( text, state ):
615 allmatches = cooker.configuration.data.keys() 613 allmatches = cooker.configuration.data.keys()
616 elif u == "<bbfile>": 614 elif u == "<bbfile>":
617 if cooker.status.pkg_fn is None: allmatches = [ "(No Matches Available. Parsed yet?)" ] 615 if cooker.status.pkg_fn is None: allmatches = [ "(No Matches Available. Parsed yet?)" ]
618 else: allmatches = [ x.split("/")[-1] for x in cooker.status.pkg_fn.keys() ] 616 else: allmatches = [ x.split("/")[-1] for x in cooker.status.pkg_fn ]
619 elif u == "<providee>": 617 elif u == "<providee>":
620 if cooker.status.pkg_fn is None: allmatches = [ "(No Matches Available. Parsed yet?)" ] 618 if cooker.status.pkg_fn is None: allmatches = [ "(No Matches Available. Parsed yet?)" ]
621 else: allmatches = cooker.status.providers.iterkeys() 619 else: allmatches = cooker.status.providers.iterkeys()