make exception handling syntax consistent
Update exception handling syntax to use the modern style: except ExcType as localvar (Bitbake rev: dbf5f42b06bef81749b13aa99945cc1292a6676d) Signed-off-by: Scott Garman <scott.a.garman@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
parent
039798a4d2
commit
62d538fbe6
|
@ -32,7 +32,7 @@ import warnings
|
|||
from traceback import format_exception
|
||||
try:
|
||||
import bb
|
||||
except RuntimeError, exc:
|
||||
except RuntimeError as exc:
|
||||
sys.exit(str(exc))
|
||||
from bb import event
|
||||
import bb.msg
|
||||
|
|
|
@ -100,7 +100,7 @@ class BBCooker:
|
|||
name_array = (getattr(module, configuration.ui)).extraCaches
|
||||
for recipeInfoName in name_array:
|
||||
caches_name_array.append(recipeInfoName)
|
||||
except ImportError, exc:
|
||||
except ImportError as exc:
|
||||
# bb.ui.XXX is not defined and imported. It's an error!
|
||||
logger.critical("Unable to import '%s' interface from bb.ui: %s" % (configuration.ui, exc))
|
||||
sys.exit("FATAL: Failed to import '%s' interface." % configuration.ui)
|
||||
|
@ -117,7 +117,7 @@ class BBCooker:
|
|||
module_name, cache_name = var.split(':')
|
||||
module = __import__(module_name, fromlist=(cache_name,))
|
||||
self.caches_array.append(getattr(module, cache_name))
|
||||
except ImportError, exc:
|
||||
except ImportError as exc:
|
||||
logger.critical("Unable to import extra RecipeInfo '%s' from '%s': %s" % (cache_name, module_name, exc))
|
||||
sys.exit("FATAL: Failed to import extra cache class '%s'." % cache_name)
|
||||
|
||||
|
@ -280,7 +280,7 @@ class BBCooker:
|
|||
if fn:
|
||||
try:
|
||||
envdata = bb.cache.Cache.loadDataFull(fn, self.get_file_appends(fn), self.configuration.data)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
parselog.exception("Unable to read %s", fn)
|
||||
raise
|
||||
|
||||
|
@ -1159,7 +1159,7 @@ def parse_file(task):
|
|||
filename, appends, caches_array = task
|
||||
try:
|
||||
return True, bb.cache.Cache.parse(filename, appends, parse_file.cfg, caches_array)
|
||||
except Exception, exc:
|
||||
except Exception as exc:
|
||||
tb = sys.exc_info()[2]
|
||||
exc.recipe = filename
|
||||
exc.traceback = list(bb.exceptions.extract_traceback(tb, context=3))
|
||||
|
@ -1167,7 +1167,7 @@ def parse_file(task):
|
|||
# Need to turn BaseExceptions into Exceptions here so we gracefully shutdown
|
||||
# and for example a worker thread doesn't just exit on its own in response to
|
||||
# a SystemExit event for example.
|
||||
except BaseException, exc:
|
||||
except BaseException as exc:
|
||||
raise ParsingFailure(exc, filename)
|
||||
|
||||
class CookerParser(object):
|
||||
|
|
|
@ -187,7 +187,7 @@ def emit_var(var, o=sys.__stdout__, d = init(), all=False):
|
|||
val = getVar(var, d, 1)
|
||||
except (KeyboardInterrupt, bb.build.FuncFailed):
|
||||
raise
|
||||
except Exception, exc:
|
||||
except Exception as exc:
|
||||
o.write('# expansion of %s threw %s: %s\n' % (var, exc.__class__.__name__, str(exc)))
|
||||
return 0
|
||||
|
||||
|
|
|
@ -663,7 +663,7 @@ class FetchMethod(object):
|
|||
|
||||
try:
|
||||
unpack = bb.utils.to_boolean(urldata.parm.get('unpack'), True)
|
||||
except ValueError, exc:
|
||||
except ValueError as exc:
|
||||
bb.fatal("Invalid value for 'unpack' parameter for %s: %s" %
|
||||
(file, urldata.parm.get('unpack')))
|
||||
|
||||
|
@ -692,7 +692,7 @@ class FetchMethod(object):
|
|||
elif file.endswith('.zip') or file.endswith('.jar'):
|
||||
try:
|
||||
dos = bb.utils.to_boolean(urldata.parm.get('dos'), False)
|
||||
except ValueError, exc:
|
||||
except ValueError as exc:
|
||||
bb.fatal("Invalid value for 'dos' parameter for %s: %s" %
|
||||
(file, urldata.parm.get('dos')))
|
||||
cmd = 'unzip -q -o'
|
||||
|
|
|
@ -93,7 +93,7 @@ def run(cmd, input=None, log=None, **options):
|
|||
|
||||
try:
|
||||
pipe = Popen(cmd, **options)
|
||||
except OSError, exc:
|
||||
except OSError as exc:
|
||||
if exc.errno == 2:
|
||||
raise NotFoundError(cmd)
|
||||
else:
|
||||
|
|
|
@ -151,7 +151,7 @@ def builtin_trap(name, args, interp, env, stdin, stdout, stderr, debugflags):
|
|||
for sig in args[1:]:
|
||||
try:
|
||||
env.traps[sig] = action
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
stderr.write('trap: %s\n' % str(e))
|
||||
return 0
|
||||
|
||||
|
@ -214,7 +214,7 @@ def utility_cat(name, args, interp, env, stdin, stdout, stderr, debugflags):
|
|||
data = f.read()
|
||||
finally:
|
||||
f.close()
|
||||
except IOError, e:
|
||||
except IOError as e:
|
||||
if e.errno != errno.ENOENT:
|
||||
raise
|
||||
status = 1
|
||||
|
@ -433,7 +433,7 @@ def utility_mkdir(name, args, interp, env, stdin, stdout, stderr, debugflags):
|
|||
if option.has_p:
|
||||
try:
|
||||
os.makedirs(path)
|
||||
except IOError, e:
|
||||
except IOError as e:
|
||||
if e.errno != errno.EEXIST:
|
||||
raise
|
||||
else:
|
||||
|
@ -561,7 +561,7 @@ def utility_sort(name, args, interp, env, stdin, stdout, stderr, debugflags):
|
|||
lines = f.readlines()
|
||||
finally:
|
||||
f.close()
|
||||
except IOError, e:
|
||||
except IOError as e:
|
||||
stderr.write(str(e) + '\n')
|
||||
return 1
|
||||
|
||||
|
@ -679,7 +679,7 @@ def run_command(name, args, interp, env, stdin, stdout,
|
|||
p = subprocess.Popen([name] + args, cwd=env['PWD'], env=exec_env,
|
||||
stdin=stdin, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||
out, err = p.communicate()
|
||||
except WindowsError, e:
|
||||
except WindowsError as e:
|
||||
raise UtilityError(str(e))
|
||||
|
||||
if not unixoutput:
|
||||
|
|
|
@ -248,7 +248,7 @@ class Redirections:
|
|||
raise NotImplementedError('cannot open absolute path %s' % repr(filename))
|
||||
else:
|
||||
f = file(filename, mode+'b')
|
||||
except IOError, e:
|
||||
except IOError as e:
|
||||
raise RedirectionError(str(e))
|
||||
|
||||
wrapper = None
|
||||
|
@ -368,7 +368,7 @@ def resolve_shebang(path, ignoreshell=False):
|
|||
if arg is None:
|
||||
return [cmd, win32_to_unix_path(path)]
|
||||
return [cmd, arg, win32_to_unix_path(path)]
|
||||
except IOError, e:
|
||||
except IOError as e:
|
||||
if e.errno!=errno.ENOENT and \
|
||||
(e.errno!=errno.EPERM and not os.path.isdir(path)): # Opening a directory raises EPERM
|
||||
raise
|
||||
|
@ -747,7 +747,7 @@ class Interpreter:
|
|||
for cmd in cmds:
|
||||
try:
|
||||
status = self.execute(cmd)
|
||||
except ExitSignal, e:
|
||||
except ExitSignal as e:
|
||||
if sourced:
|
||||
raise
|
||||
status = int(e.args[0])
|
||||
|
@ -758,13 +758,13 @@ class Interpreter:
|
|||
if 'debug-utility' in self._debugflags or 'debug-cmd' in self._debugflags:
|
||||
self.log('returncode ' + str(status)+ '\n')
|
||||
return status
|
||||
except CommandNotFound, e:
|
||||
except CommandNotFound as e:
|
||||
print >>self._redirs.stderr, str(e)
|
||||
self._redirs.stderr.flush()
|
||||
# Command not found by non-interactive shell
|
||||
# return 127
|
||||
raise
|
||||
except RedirectionError, e:
|
||||
except RedirectionError as e:
|
||||
# TODO: should be handled depending on the utility status
|
||||
print >>self._redirs.stderr, str(e)
|
||||
self._redirs.stderr.flush()
|
||||
|
@ -948,7 +948,7 @@ class Interpreter:
|
|||
status = self.execute(func, redirs)
|
||||
finally:
|
||||
redirs.close()
|
||||
except ReturnSignal, e:
|
||||
except ReturnSignal as e:
|
||||
status = int(e.args[0])
|
||||
env['?'] = status
|
||||
return status
|
||||
|
@ -1044,7 +1044,7 @@ class Interpreter:
|
|||
|
||||
except ReturnSignal:
|
||||
raise
|
||||
except ShellError, e:
|
||||
except ShellError as e:
|
||||
if is_special or isinstance(e, (ExitSignal,
|
||||
ShellSyntaxError, ExpansionError)):
|
||||
raise e
|
||||
|
|
|
@ -1228,7 +1228,7 @@ class RunQueueExecuteTasks(RunQueueExecute):
|
|||
modname, name = sched.rsplit(".", 1)
|
||||
try:
|
||||
module = __import__(modname, fromlist=(name,))
|
||||
except ImportError, exc:
|
||||
except ImportError as exc:
|
||||
logger.critical("Unable to import scheduler '%s' from '%s': %s" % (name, modname, exc))
|
||||
raise SystemExit(1)
|
||||
else:
|
||||
|
|
|
@ -64,7 +64,7 @@ class EventAdapter():
|
|||
def send(self, event):
|
||||
try:
|
||||
self.queue.put(event)
|
||||
except Exception, err:
|
||||
except Exception as err:
|
||||
print("EventAdapter puked: %s" % str(err))
|
||||
|
||||
|
||||
|
@ -168,7 +168,7 @@ class ProcessServer(Process):
|
|||
exitcode = 0
|
||||
finally:
|
||||
util._exit_function()
|
||||
except SystemExit, e:
|
||||
except SystemExit as e:
|
||||
if not e.args:
|
||||
exitcode = 1
|
||||
elif type(e.args[0]) is int:
|
||||
|
|
|
@ -88,7 +88,7 @@ class PRServer(SimpleXMLRPCServer):
|
|||
pid = os.fork()
|
||||
if pid > 0:
|
||||
sys.exit(0)
|
||||
except OSError,e:
|
||||
except OSError as e:
|
||||
sys.stderr.write("1st fork failed: %d %s\n" % (e.errno, e.strerror))
|
||||
sys.exit(1)
|
||||
|
||||
|
@ -101,7 +101,7 @@ class PRServer(SimpleXMLRPCServer):
|
|||
pid = os.fork()
|
||||
if pid > 0: #parent
|
||||
sys.exit(0)
|
||||
except OSError,e:
|
||||
except OSError as e:
|
||||
sys.stderr.write("2nd fork failed: %d %s\n" % (e.errno, e.strerror))
|
||||
sys.exit(1)
|
||||
|
||||
|
@ -187,7 +187,7 @@ def stop_daemon():
|
|||
while 1:
|
||||
os.kill(pid,signal.SIGTERM)
|
||||
time.sleep(0.1)
|
||||
except OSError, err:
|
||||
except OSError as err:
|
||||
err = str(err)
|
||||
if err.find("No such process") > 0:
|
||||
if os.path.exists(PRServer.pidfile):
|
||||
|
|
Loading…
Reference in New Issue