Apply some 2to3 refactorings

Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
This commit is contained in:
Chris Larson 2010-06-20 12:08:07 -07:00 committed by Richard Purdie
parent 20dc452614
commit ef1de9ecaf
11 changed files with 43 additions and 43 deletions

View File

@ -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:

View File

@ -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:

View 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()

View 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))

View 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

View 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

View 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]]

View 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

View 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:

View 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):

View 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)