]> code.ossystems Code Review - openembedded-core.git/commitdiff
Apply some 2to3 refactorings
authorChris Larson <chris_larson@mentor.com>
Sun, 20 Jun 2010 19:08:07 +0000 (12:08 -0700)
committerRichard Purdie <rpurdie@linux.intel.com>
Fri, 2 Jul 2010 14:41:37 +0000 (15:41 +0100)
Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
bitbake/bin/bitbake
bitbake/bin/bitdoc
bitbake/lib/bb/COW.py
bitbake/lib/bb/cooker.py
bitbake/lib/bb/fetch/__init__.py
bitbake/lib/bb/parse/ast.py
bitbake/lib/bb/runqueue.py
bitbake/lib/bb/shell.py
bitbake/lib/bb/ui/knotty.py
bitbake/lib/bb/ui/ncurses.py
bitbake/lib/bb/utils.py

index 34cfadb986cebc18dda21380cb2dfcb7da9982b1..fdf1e20f84167a3e754039d8cac89a455a025468 100755 (executable)
@@ -200,7 +200,7 @@ Default BBFILES are the .bb files in the current directory.""")
     else:
         try:
             return_value = ui_init(serverConnection.connection, serverConnection.events)
-        except Exception, e:
+        except Exception as e:
             print "FATAL: Unable to start to '%s' UI: %s" % (ui, e)
             raise
     finally:
index 4940f660a6c2063d2d73765eb5eeff0384562f87..8043b2bd1c38fb78c6ebfaa4c50235acdc78454b 100755 (executable)
@@ -48,7 +48,7 @@ class HTMLFormatter:
         From pydoc... almost identical at least
         """
         while pairs:
-            (a,b) = pairs[0]
+            (a, b) = pairs[0]
             text = join(split(text, a), b)
             pairs = pairs[1:]
         return text
@@ -87,7 +87,7 @@ class HTMLFormatter:
 
         return txt + ",".join(txts)
 
-    def groups(self,item):
+    def groups(self, item):
         """
         Create HTML to link to related groups
         """
@@ -99,12 +99,12 @@ class HTMLFormatter:
         txt = "<p><b>See also:</b><br>"
         txts = []
         for group in item.groups():
-            txts.append( """<a href="group%s.html">%s</a> """ % (group,group) )
+            txts.append( """<a href="group%s.html">%s</a> """ % (group, group) )
 
         return txt + ",".join(txts)
 
 
-    def createKeySite(self,item):
+    def createKeySite(self, item):
         """
         Create a site for a key. It contains the header/navigator, a heading,
         the description, links to related keys and to the groups.
@@ -149,8 +149,7 @@ class HTMLFormatter:
         """
 
         groups = ""
-        sorted_groups = doc.groups()
-        sorted_groups.sort()
+        sorted_groups = sorted(doc.groups())
         for group in sorted_groups:
             groups += """<a href="group%s.html">%s</a><br>""" % (group, group)
 
@@ -185,8 +184,7 @@ class HTMLFormatter:
         Create Overview of all avilable keys
         """
         keys = ""
-        sorted_keys = doc.doc_keys()
-        sorted_keys.sort()
+        sorted_keys = sorted(doc.doc_keys())
         for key in sorted_keys:
             keys += """<a href="key%s.html">%s</a><br>""" % (key, key)
 
@@ -214,7 +212,7 @@ class HTMLFormatter:
             description  += "<h2 Description of Grozp %s</h2>" % gr
             description  += _description
 
-        items.sort(lambda x,y:cmp(x.name(),y.name()))
+        items.sort(lambda x, y:cmp(x.name(), y.name()))
         for group in items:
             groups += """<a href="key%s.html">%s</a><br>""" % (group.name(), group.name())
 
@@ -343,7 +341,7 @@ class DocumentationItem:
     def addGroup(self, group):
         self._groups.append(group)
 
-    def addRelation(self,relation):
+    def addRelation(self, relation):
         self._related.append(relation)
 
     def sort(self):
@@ -396,7 +394,7 @@ class Documentation:
         """
         return self.__groups.keys()
 
-    def group_content(self,group_name):
+    def group_content(self, group_name):
         """
         Return a list of keys/names that are in a specefic
         group or the empty list
@@ -412,7 +410,7 @@ def parse_cmdline(args):
     Parse the CMD line and return the result as a n-tuple
     """
 
-    parser = optparse.OptionParser( version = "Bitbake Documentation Tool Core version %s, %%prog version %s" % (bb.__version__,__version__))
+    parser = optparse.OptionParser( version = "Bitbake Documentation Tool Core version %s, %%prog version %s" % (bb.__version__, __version__))
     usage  = """%prog [options]
 
 Create a set of html pages (documentation) for a bitbake.conf....
@@ -428,7 +426,7 @@ Create a set of html pages (documentation) for a bitbake.conf....
     parser.add_option( "-D",  "--debug", help = "Increase the debug level",
                        action = "count", dest = "debug", default = 0 )
 
-    parser.add_option( "-v","--verbose", help = "output more chit-char to the terminal",
+    parser.add_option( "-v", "--verbose", help = "output more chit-char to the terminal",
                        action = "store_true", dest = "verbose", default = False )
 
     options, args = parser.parse_args( sys.argv )
@@ -443,7 +441,7 @@ def main():
     The main Method
     """
 
-    (config_file,output_dir) = parse_cmdline( sys.argv )
+    (config_file, output_dir) = parse_cmdline( sys.argv )
 
     # right to let us load the file now
     try:
index 23a2cae2b43a1fe6c9916bfbe0d097da3400a938..6917ec378a37bd10d0d020079388f71a7cac4d60 100644 (file)
@@ -82,7 +82,7 @@ class COWDictMeta(COWMeta):
             print("Warning: Doing a copy because %s is a mutable type." % key, file=cls.__warn__)
         try:
             value = value.copy()
-        except AttributeError, e:
+        except AttributeError as e:
             value = copy.copy(value)
         setattr(cls, nkey, value)
         return value
@@ -106,7 +106,7 @@ class COWDictMeta(COWMeta):
                 raise AttributeError("key %s does not exist." % key)
 
             return value
-        except AttributeError, e:
+        except AttributeError as e:
             if not default is cls.__getmarker__:
                 return default
 
@@ -239,7 +239,7 @@ if __name__ == "__main__":
 
     try:
         b['dict2']
-    except KeyError, e:
+    except KeyError as e:
         print("Okay!")
 
     a['set'] = COWSetBase()
index 2b3dfb0cb4dc23ed54f0f5d66820a089a70e979f..6884e9a5545aa7a582c2047fecd8353b422bb142 100644 (file)
@@ -173,7 +173,7 @@ class BBCooker:
         except bb.build.FuncFailed:
             bb.msg.error(bb.msg.domain.Build, "task stack execution failed")
             raise
-        except bb.build.EventException, e:
+        except bb.build.EventException as e:
             event = e.args[1]
             bb.msg.error(bb.msg.domain.Build, "%s event exception, aborting" % bb.event.getName(event))
             raise
@@ -259,10 +259,10 @@ class BBCooker:
         if fn:
             try:
                 envdata = self.bb_cache.loadDataFull(fn, self.configuration.data)
-            except IOError, e:
+            except IOError as e:
                 bb.msg.error(bb.msg.domain.Parsing, "Unable to read %s: %s" % (fn, e))
                 raise
-            except Exception, e:
+            except Exception as e:
                 bb.msg.error(bb.msg.domain.Parsing, "%s" % e)
                 raise
 
@@ -272,7 +272,7 @@ class BBCooker:
             with closing(StringIO()) as env:
                 data.emit_env(env, envdata, True)
                 bb.msg.plain(env.getvalue())
-        except Exception, e:
+        except Exception as e:
             bb.msg.fatal(bb.msg.domain.Parsing, "%s" % e)
 
         # emit the metadata which isnt valid shell
@@ -499,7 +499,7 @@ class BBCooker:
         """Drop off into a shell"""
         try:
             from bb import shell
-        except ImportError, details:
+        except ImportError as details:
             bb.msg.fatal(bb.msg.domain.Parsing, "Sorry, shell not available (%s)" % details )
         else:
             shell.start( self )
@@ -569,9 +569,9 @@ class BBCooker:
             bb.event.fire(bb.event.ConfigParsed(), self.configuration.data)
 
 
-        except IOError, e:
+        except IOError as e:
             bb.msg.fatal(bb.msg.domain.Parsing, "Error when parsing %s: %s" % (files, str(e)))
-        except bb.parse.ParseError, details:
+        except bb.parse.ParseError as details:
             bb.msg.fatal(bb.msg.domain.Parsing, "Unable to parse %s (%s)" % (files, details) )
 
     def handleCollections( self, collections ):
@@ -978,7 +978,7 @@ class CookerParser:
                 self.skipped += skipped
                 self.virtuals += virtuals
 
-            except IOError, e:
+            except IOError as e:
                 self.error += 1
                 cooker.bb_cache.remove(f)
                 bb.msg.error(bb.msg.domain.Collection, "opening %s: %s" % (f, e))
@@ -987,7 +987,7 @@ class CookerParser:
                 cooker.bb_cache.remove(f)
                 cooker.bb_cache.sync()
                 raise
-            except Exception, e:
+            except Exception as e:
                 self.error += 1
                 cooker.bb_cache.remove(f)
                 bb.msg.error(bb.msg.domain.Collection, "%s while parsing %s" % (e, f))
index e87223ad6b9cacb72c6eac5755aa281eb0aa3b88..651fea88735b567f938cf98c1ce62c5113677147 100644 (file)
@@ -409,7 +409,7 @@ def runfetchcmd(cmd, d, quiet = False):
     stdout_handle = os.popen(cmd + " 2>&1", "r")
     output = ""
 
-    while 1:
+    while True:
         line = stdout_handle.readline()
         if not line:
             break
index 4eabe5f2a18b4e3632840c9be5bcbc79f4889563..02d682d88f289cfb3bc00a126ac48d398633e294 100644 (file)
@@ -23,7 +23,7 @@
 
 import bb, re, string
 from bb import methodpool
-from itertools import chain
+import itertools
 
 __word__ = re.compile(r"\S+")
 __parsed_methods__ = bb.methodpool.get_parsed_dict()
@@ -31,7 +31,8 @@ _bbversions_re = re.compile(r"\[(?P<from>[0-9]+)-(?P<to>[0-9]+)\]")
 
 class StatementGroup(list):
     def eval(self, data):
-        map(lambda x: x.eval(data), self)
+        for statement in self:
+            statement.eval(data)
 
 class AstNode(object):
     pass
@@ -341,7 +342,7 @@ def _expand_versions(versions):
     versions = iter(versions)
     while True:
         try:
-            version = versions.next()
+            version = next(versions)
         except StopIteration:
             break
 
@@ -351,7 +352,7 @@ def _expand_versions(versions):
         else:
             newversions = expand_one(version, int(range_ver.group("from")),
                                      int(range_ver.group("to")))
-            versions = chain(newversions, versions)
+            versions = itertools.chain(newversions, versions)
 
 def multi_finalize(fn, d):
     safe_d = d
@@ -417,7 +418,7 @@ def multi_finalize(fn, d):
         safe_d.setVar("BBCLASSEXTEND", extended)
         _create_variants(datastores, extended.split(), extendfunc)
 
-    for variant, variant_d in datastores.items():
+    for variant, variant_d in datastores.iteritems():
         if variant:
             try:
                 finalize(fn, variant_d)
@@ -425,7 +426,7 @@ def multi_finalize(fn, d):
                 bb.data.setVar("__SKIPPED", True, variant_d)
 
     if len(datastores) > 1:
-        variants = filter(None, datastores.keys())
+        variants = filter(None, datastores.iterkeys())
         safe_d.setVar("__VARIANTS", " ".join(variants))
 
     datastores[""] = d
index 93fff5d27b1c40bfaf89b6785146559db42c41c8..a4aea6c00496188de24bf0b3e3494c106622868f 100644 (file)
@@ -928,7 +928,7 @@ class RunQueue:
         while True:
             task = None
             if self.stats.active < self.number_tasks:
-                task = self.sched.next()
+                task = next(self.sched)
             if task is not None:
                 fn = self.taskData.fn_index[self.runq_fnid[task]]
 
index aeead679b2426a38a46b2dba0d1b48ca6b08b553..f9ca9d5bd372a4feedcc0eaa2268effeb3a2a64f 100644 (file)
@@ -53,6 +53,7 @@ PROBLEMS:
 ##########################################################################
 
 from __future__ import print_function
+from functools import reduce
 try:
     set
 except NameError:
@@ -178,12 +179,12 @@ class BitBakeShellCommands:
             print("ERROR: No Provider")
             last_exception = Providers.NoProvider
 
-        except runqueue.TaskFailure, fnids:
+        except runqueue.TaskFailure as fnids:
             for fnid in fnids:
                 print("ERROR: '%s' failed" % td.fn_index[fnid])
             last_exception = runqueue.TaskFailure
 
-        except build.EventException, e:
+        except build.EventException as e:
             print("ERROR: Couldn't build '%s'" % names)
             last_exception = e
 
@@ -246,7 +247,7 @@ class BitBakeShellCommands:
             cooker.buildFile(bf, cmd)
         except parse.ParseError:
             print("ERROR: Unable to open or parse '%s'" % bf)
-        except build.EventException, e:
+        except build.EventException as e:
             print("ERROR: Couldn't build '%s'" % name)
             last_exception = e
 
@@ -644,7 +645,7 @@ def columnize( alist, width = 80 ):
     return reduce(lambda line, word, width=width: '%s%s%s' %
                   (line,
                    ' \n'[(len(line[line.rfind('\n')+1:])
-                         + len(word.split('\n',1)[0]
+                         + len(word.split('\n', 1)[0]
                               ) >= width)],
                    word),
                   alist
index bfdcc5b495e08fbd490d55dfb5e1274c7199329e..f81759abf88329330894f9e8fc35a31c7fd26d99 100644 (file)
@@ -123,7 +123,7 @@ def init(server, eventHandler):
                 x = event.sofar
                 y = event.total
                 if os.isatty(sys.stdout.fileno()):
-                    sys.stdout.write("\rNOTE: Handling BitBake files: %s (%04d/%04d) [%2d %%]" % ( parsespin.next(), x, y, x*100//y ) )
+                    sys.stdout.write("\rNOTE: Handling BitBake files: %s (%04d/%04d) [%2d %%]" % ( next(parsespin), x, y, x*100//y ) )
                     sys.stdout.flush()
                 else:
                     if x == 1:
index e3bca2af8367cef7ad02035e9afe8229b89a248b..81dcb1998c45cc32a9075abeffc8ac76fc9e78a5 100644 (file)
@@ -266,7 +266,7 @@ class NCursesUI:
                         mw.appendText("Parsing finished. %d cached, %d parsed, %d skipped, %d masked."
                                 % ( event.cached, event.parsed, event.skipped, event.masked ))
                     else:
-                        mw.setStatus("Parsing: %s (%04d/%04d) [%2d %%]" % ( parsespin.next(), x, y, x*100/y ) )
+                        mw.setStatus("Parsing: %s (%04d/%04d) [%2d %%]" % ( next(parsespin), x, y, x*100/y ) )
 #                if isinstance(event, bb.build.TaskFailed):
 #                    if event.logfile:
 #                        if data.getVar("BBINCLUDELOGS", d):
index a7fb44d7d2f212668631c0eba88b868dc0e3e920..c0cc9c6ea214dbdcd677b362e4dbabc77d1ba81c 100644 (file)
@@ -326,7 +326,7 @@ def better_exec(code, context, text, realfile):
     """
     import bb.parse
     try:
-        exec code in _context, context
+        exec(code, _context, context)
     except:
         (t, value, tb) = sys.exc_info()
 
@@ -349,7 +349,7 @@ def better_exec(code, context, text, realfile):
         raise
 
 def simple_exec(code, context):
-    exec code in _context, context
+    exec(code, _context, context)
 
 def better_eval(source, locals):
     return eval(source, _context, locals)