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