summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/shell.py
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/lib/bb/shell.py
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/lib/bb/shell.py')
-rw-r--r--bitbake/lib/bb/shell.py18
1 files changed, 8 insertions, 10 deletions
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()