tweak exception style to work with python-3
BUG=None
TEST=`./run_tests` passed
Change-Id: I02456eaa72eff2dceab9a2d6040bf46dd6f32aa9
Reviewed-on: https://chromium-review.googlesource.com/173728
Reviewed-by: David James <davidjames@chromium.org>
Commit-Queue: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
diff --git a/appengine/chromiumos-build-stats/stats.py b/appengine/chromiumos-build-stats/stats.py
index 995ae02..083ba95 100644
--- a/appengine/chromiumos-build-stats/stats.py
+++ b/appengine/chromiumos-build-stats/stats.py
@@ -116,7 +116,7 @@
error_msg = None
try:
stat_entries = model.Statistics.gql(query, DATASTORE_KEY)
- except datastore_errors.BadQueryError, ex:
+ except datastore_errors.BadQueryError as ex:
error_msg = '<p>%s.</p><p>Actual GCL query used: "%s"</p>' % (ex, query)
results_html_table = self._PrepareResultsTable(stat_entries, columns,
diff --git a/buildbot/cbuildbot_commands.py b/buildbot/cbuildbot_commands.py
index ef81e4f..9a1cba2 100644
--- a/buildbot/cbuildbot_commands.py
+++ b/buildbot/cbuildbot_commands.py
@@ -167,7 +167,7 @@
try:
if os.path.isdir(cwd):
git.CleanAndCheckoutUpstream(cwd, False)
- except cros_build_lib.RunCommandError, e:
+ except cros_build_lib.RunCommandError as e:
result = e.result
logging.warn('\n%s', result.error)
logging.warn('Deleting %s because %s failed', cwd, e.result.cmd)
diff --git a/buildbot/cbuildbot_stages.py b/buildbot/cbuildbot_stages.py
index a817a45..78dd480 100644
--- a/buildbot/cbuildbot_stages.py
+++ b/buildbot/cbuildbot_stages.py
@@ -423,7 +423,7 @@
manifest = git.ManifestCheckout.Cached(self._build_root, search=False)
except (KeyboardInterrupt, MemoryError, SystemExit):
raise
- except Exception, e:
+ except Exception as e:
# Either there is no repo there, or the manifest isn't usable. If the
# directory exists, log the exception for debugging reasons. Either
# way, the checkout needs to be wiped since it's in an unknown
diff --git a/buildbot/repository.py b/buildbot/repository.py
index 7f53e7f..b79ef25 100755
--- a/buildbot/repository.py
+++ b/buildbot/repository.py
@@ -350,7 +350,7 @@
self._EnsureMirroring(True)
self._DoCleanup()
- except cros_build_lib.RunCommandError, e:
+ except cros_build_lib.RunCommandError as e:
err_msg = e.Stringify(error=False, output=False)
logging.error(err_msg)
raise SrcCheckOutException(err_msg)
diff --git a/buildbot/tee.py b/buildbot/tee.py
index 3641d31..a432070 100644
--- a/buildbot/tee.py
+++ b/buildbot/tee.py
@@ -133,7 +133,7 @@
failed = False
except ToldToDie:
failed = False
- except Exception, e:
+ except Exception as e:
tb = traceback.format_exc()
cros_build_lib.PrintBuildbotStepFailure(self._error_handle)
self._error_handle.write(
@@ -148,7 +148,7 @@
if failed:
try:
os.kill(self.master_pid, signal.SIGTERM)
- except Exception, e:
+ except Exception as e:
self._error_handle.write("\nTee failed signaling %s\n" % e)
# Finally, kill ourself.
diff --git a/buildbot/validation_pool.py b/buildbot/validation_pool.py
index 2b4fb5e..f1ab321 100644
--- a/buildbot/validation_pool.py
+++ b/buildbot/validation_pool.py
@@ -205,13 +205,13 @@
def f(self, parent, *args, **kwds):
try:
return functor(self, parent, *args, **kwds)
- except gerrit.GerritException, e:
+ except gerrit.GerritException as e:
if isinstance(e, gerrit.QueryNotSpecific):
e = ("%s\nSuggest you use gerrit numbers instead (prefixed with a * "
"if it's an internal change)." % e)
new_exc = cros_patch.PatchException(parent, e)
raise new_exc.__class__, new_exc, sys.exc_info()[2]
- except cros_patch.PatchException, e:
+ except cros_patch.PatchException as e:
if e.patch.id == parent.id:
raise
new_exc = cros_patch.DependencyError(parent, e)
@@ -590,7 +590,7 @@
continue
try:
self._ResolveChange(dep, plan, stack, limit_to=limit_to)
- except cros_patch.PatchException, e:
+ except cros_patch.PatchException as e:
raise cros_patch.DependencyError, \
cros_patch.DependencyError(change, e), \
sys.exc_info()[2]
@@ -715,7 +715,7 @@
', '.join(map(str, transaction_changes)))
self._ApplyChanges(inducing_change, transaction_changes,
dryrun=dryrun)
- except cros_patch.PatchException, e:
+ except cros_patch.PatchException as e:
logging.info("Failed applying transaction for %s: %s",
inducing_change, e)
failed.append(e)
@@ -827,7 +827,7 @@
try:
self.ApplyChange(change, dryrun=dryrun)
- except cros_patch.PatchException, e:
+ except cros_patch.PatchException as e:
if not e.inflight:
self.failed_tot[change.id] = e
raise
@@ -1366,7 +1366,7 @@
self.changes, dryrun=self.dryrun, manifest=manifest)
except (KeyboardInterrupt, RuntimeError, SystemExit):
raise
- except Exception, e:
+ except Exception as e:
if mox is not None and isinstance(e, mox.Error):
raise
@@ -1383,7 +1383,7 @@
try:
self._HandleApplyFailure(
[InternalCQError(patch, msg) for patch in self.changes])
- except Exception, e:
+ except Exception as e:
if mox is None or not isinstance(e, mox.Error):
# If it's not a mox error, let it fly.
raise
@@ -1622,7 +1622,7 @@
d = dict(build_log=self.build_log, queue=self.queue, **kwargs)
try:
msg %= d
- except (TypeError, ValueError), e:
+ except (TypeError, ValueError) as e:
logging.error(
"Generation of message %s for change %s failed: dict was %r, "
"exception %s", msg, change, d, e)
diff --git a/lib/cgroups.py b/lib/cgroups.py
index be1fc13..f64e2a4 100644
--- a/lib/cgroups.py
+++ b/lib/cgroups.py
@@ -261,7 +261,7 @@
try:
targets = [x for x in os.listdir(path)
if os.path.isdir(os.path.join(path, x))]
- except EnvironmentError, e:
+ except EnvironmentError as e:
if e.errno != errno.ENOENT:
raise
@@ -307,7 +307,7 @@
If the file doesn't exist, return the given default."""
try:
return osutils.ReadFile(os.path.join(self.path, key))
- except EnvironmentError, e:
+ except EnvironmentError as e:
if e.errno != errno.ENOENT:
raise
return default
@@ -402,7 +402,7 @@
name = self._LimitName(key, True)
try:
return sudo.SetFileContents(name, value, cwd=os.path.dirname(name))
- except cros_build_lib.RunCommandError, e:
+ except cros_build_lib.RunCommandError as e:
if e.exception is not None:
# Command failed before the exec itself; convert ENOENT
# appropriately.
@@ -653,7 +653,7 @@
# w/ procfs, and keep in mind that we have to work across multiple kernel
# versions.
cpuset = osutils.ReadFile('/proc/%s/cpuset' % (pid,)).rstrip('\n')
- except EnvironmentError, e:
+ except EnvironmentError as e:
if e.errno != errno.ENOENT:
raise
with open('/proc/%s/cgroup' % pid) as f:
diff --git a/lib/cleanup.py b/lib/cleanup.py
index a868221..956550b 100644
--- a/lib/cleanup.py
+++ b/lib/cleanup.py
@@ -75,7 +75,7 @@
self._is_child = True
try:
self._lock.write_lock()
- except BaseException, e:
+ except BaseException as e:
print >> sys.stderr, ("EnforcedCleanupSection %s excepted(%r) attempting "
"to take the write lock; hard exiting." % (self, e))
sys.stderr.flush()
diff --git a/lib/commandline.py b/lib/commandline.py
index 80c11b7..662a2c9 100644
--- a/lib/commandline.py
+++ b/lib/commandline.py
@@ -459,16 +459,16 @@
ret = 1
try:
ret = target(argv[1:])
- except _ShutDownException, e:
+ except _ShutDownException as e:
sys.stdout.flush()
print >> sys.stderr, ("%s: Signaled to shutdown: caught %i signal." %
(name, e.signal,))
sys.stderr.flush()
- except SystemExit, e:
+ except SystemExit as e:
# Right now, let this crash through- longer term, we'll update the scripts
# in question to not use sys.exit, and make this into a flagged error.
raise
- except Exception, e:
+ except Exception as e:
sys.stdout.flush()
print >> sys.stderr, ("%s: Unhandled exception:" % (name,))
sys.stderr.flush()
diff --git a/lib/cros_build_lib.py b/lib/cros_build_lib.py
index 3e67f1d..f5d74f3 100644
--- a/lib/cros_build_lib.py
+++ b/lib/cros_build_lib.py
@@ -190,7 +190,7 @@
if proc.poll() is None:
# Still doesn't want to die. Too bad, so sad, time to die.
proc.kill()
- except EnvironmentError, e:
+ except EnvironmentError as e:
Warning('Ignoring unhandled exception in _KillChildProcess: %s', e)
# Ensure our child process has been reaped.
@@ -228,7 +228,7 @@
try:
os.kill(self.pid, signum)
- except EnvironmentError, e:
+ except EnvironmentError as e:
if e.errno == errno.EPERM:
# Kill returns either 0 (signal delivered), or 1 (signal wasn't
# delivered). This isn't particularly informative, but we still
@@ -323,7 +323,7 @@
def _get_tempfile():
try:
return tempfile.TemporaryFile(bufsize=0)
- except EnvironmentError, e:
+ except EnvironmentError as e:
if e.errno != errno.ENOENT:
raise
# This can occur if we were pointed at a specific location for our
@@ -453,7 +453,7 @@
if error_message:
msg += '\n%s' % error_message
raise RunCommandError(msg, cmd_result)
- except OSError, e:
+ except OSError as e:
estr = str(e)
if e.errno == errno.EACCES:
estr += '; does the program need `chmod a+x`?'
@@ -1243,7 +1243,7 @@
try:
return RunCommandWithRetries(5, cmd, sleep=3, retry_on=retriable_exits,
**kwargs)
- except RunCommandError, e:
+ except RunCommandError as e:
code = e.result.returncode
if code in (51, 58, 60):
# These are the return codes of failing certs as per 'man curl'.
@@ -1252,7 +1252,7 @@
try:
return RunCommandWithRetries(5, cmd, sleep=60, retry_on=retriable_exits,
**kwargs)
- except RunCommandError, e:
+ except RunCommandError as e:
Die("Curl failed w/ exit code %i", code)
@@ -1488,7 +1488,7 @@
# Only strip quotes if the first & last one match.
val = val[1:-1]
d[chunks[0].strip()] = val
- except EnvironmentError, e:
+ except EnvironmentError as e:
if not (ignore_missing and e.errno == errno.ENOENT):
raise
diff --git a/lib/cros_build_lib_unittest.py b/lib/cros_build_lib_unittest.py
index 430c978..08e42a8 100755
--- a/lib/cros_build_lib_unittest.py
+++ b/lib/cros_build_lib_unittest.py
@@ -596,7 +596,7 @@
if full_path.endswith('/'):
# we only want to create directories
return
- except OSError, err:
+ except OSError as err:
if err.errno == errno.EEXIST:
# we don't care if the dir already exists
pass
@@ -628,7 +628,7 @@
def testNoSuchDir(self):
try:
cros_build_lib.ListFiles(os.path.join(self.tempdir, 'missing'))
- except OSError, err:
+ except OSError as err:
self.assertEqual(err.errno, errno.ENOENT)
@@ -874,7 +874,7 @@
try:
func(repo_root)
assert "Testing for %s, an exception wasn't thrown." % (message,)
- except OSError, e:
+ except OSError as e:
self.assertEqual(e.errno, errno.ENOENT)
self.assertTrue(message in str(e),
msg="Couldn't find string %r in error message %r"
diff --git a/lib/cros_test_lib.py b/lib/cros_test_lib.py
index 00d228b..283864d 100644
--- a/lib/cros_test_lib.py
+++ b/lib/cros_test_lib.py
@@ -505,7 +505,7 @@
try:
functor(*args, **kwargs)
raise AssertionError(msg)
- except exception, e:
+ except exception as e:
if exact_kls:
self.assertEqual(e.__class__, exception)
bad = []
@@ -1319,7 +1319,7 @@
try:
unittest.main(**kwds)
raise SystemExit(0)
- except SystemExit, e:
+ except SystemExit as e:
if e.__class__ != SystemExit or allow_exit:
raise
# Redo the exit code ourselves- unittest throws True on occasion.
diff --git a/lib/git.py b/lib/git.py
index 1caa4ba..4f8b24b 100644
--- a/lib/git.py
+++ b/lib/git.py
@@ -211,7 +211,7 @@
try:
ret = RunGit(cwd, ['symbolic-ref', '-q', 'HEAD'])
return StripRefsHeads(ret.output.strip(), False)
- except cros_build_lib.RunCommandError, e:
+ except cros_build_lib.RunCommandError as e:
if e.result.returncode != 1:
raise
return None
@@ -391,7 +391,7 @@
with open(source, 'rb') as f:
# pylint: disable=E1101
return hashlib.md5(f.read()).hexdigest()
- except EnvironmentError, e:
+ except EnvironmentError as e:
if e.errno != errno.ENOENT or not ignore_missing:
raise
source.seek(0)
@@ -544,7 +544,7 @@
path = os.path.join(root, '.repo', 'manifests.git')
try:
result = RunGit(path, ['config', '--get', 'manifest.groups'])
- except cros_build_lib.RunCommandError, e:
+ except cros_build_lib.RunCommandError as e:
if e.result.returncode == 1:
# Value wasn't found, which is fine.
return frozenset(['default'])
@@ -664,7 +664,7 @@
result = RunGit(git_repo, ['config', '-f', '/dev/stdin', '--get',
'submit.mergeContent'], input=content.output)
return result.output.strip().lower() == 'true'
- except cros_build_lib.RunCommandError, e:
+ except cros_build_lib.RunCommandError as e:
# If the field isn't set at all, exit code is 1.
# Anything else is a bad invocation or an indecipherable state.
if e.result.returncode != 1:
@@ -878,7 +878,7 @@
return None
return remote, revision
- except EnvironmentError, e:
+ except EnvironmentError as e:
if e.errno != errno.ENOENT:
raise
return None
@@ -1109,7 +1109,7 @@
# Ensure the manifest knows of this checkout.
if manifest.FindProjectFromPath(cwd):
return manifest.manifest_branch
- except EnvironmentError, e:
+ except EnvironmentError as e:
if e.errno != errno.ENOENT:
raise
diff --git a/lib/locking.py b/lib/locking.py
index 3ac2992..848f55c 100644
--- a/lib/locking.py
+++ b/lib/locking.py
@@ -48,7 +48,7 @@
try:
fcntl.lockf(self.fd, flags|fcntl.LOCK_NB)
return
- except EnvironmentError, e:
+ except EnvironmentError as e:
if e.errno == errno.EDEADLOCK:
self.unlock()
elif e.errno != errno.EAGAIN:
@@ -59,7 +59,7 @@
cros_build_lib.Info(message)
try:
fcntl.lockf(self.fd, flags)
- except EnvironmentError, e:
+ except EnvironmentError as e:
if e.errno != errno.EDEADLOCK:
raise
self.unlock()
diff --git a/lib/osutils.py b/lib/osutils.py
index 6bc5cd5..b9b5440 100644
--- a/lib/osutils.py
+++ b/lib/osutils.py
@@ -100,7 +100,7 @@
try:
os.unlink(path)
return True
- except EnvironmentError, e:
+ except EnvironmentError as e:
if e.errno != errno.ENOENT:
raise
return False
@@ -132,7 +132,7 @@
try:
os.makedirs(path, mode)
return True
- except EnvironmentError, e:
+ except EnvironmentError as e:
if e.errno != errno.EEXIST or not os.path.isdir(path):
raise
@@ -152,7 +152,7 @@
['rm', '-r%s' % ('f' if ignore_missing else '',), '--', path],
debug_level=logging.DEBUG,
redirect_stdout=True, redirect_stderr=True)
- except cros_build_lib.RunCommandError, e:
+ except cros_build_lib.RunCommandError as e:
if not ignore_missing or os.path.exists(path):
# If we're not ignoring the rm ENOENT equivalent, throw it;
# if the pathway still exists, something failed, thus throw it.
@@ -160,7 +160,7 @@
else:
try:
shutil.rmtree(path)
- except EnvironmentError, e:
+ except EnvironmentError as e:
if not ignore_missing or e.errno != errno.ENOENT:
raise
@@ -298,7 +298,7 @@
try:
if tempdir is not None:
RmDir(tempdir, ignore_missing=True, sudo=force_sudo)
- except EnvironmentError, e:
+ except EnvironmentError as e:
# Suppress ENOENT since we may be invoked
# in a context where parallel wipes of the tempdir
# may be occuring; primarily during hard shutdowns.
diff --git a/lib/patch.py b/lib/patch.py
index f0f8226..b8c3d44 100644
--- a/lib/patch.py
+++ b/lib/patch.py
@@ -586,7 +586,7 @@
try:
lines = git.RunGit(git_repo, ['diff', '--no-renames', '--name-status',
'%s^..%s' % (self.sha1, self.sha1)])
- except cros_build_lib.RunCommandError, e:
+ except cros_build_lib.RunCommandError as e:
# If we get a 128, that means git couldn't find the the parent of our
# sha1- meaning we're the first commit in the repository (there is no
# parent).
@@ -621,7 +621,7 @@
git.RunGit(git_repo, cmd)
reset_target = None
return
- except cros_build_lib.RunCommandError, error:
+ except cros_build_lib.RunCommandError as error:
ret = error.result.returncode
if ret not in (1, 2):
cros_build_lib.Error(
@@ -1310,7 +1310,7 @@
for patch in patches:
try:
project, original_branch, ref, tracking_branch, tag = patch.split(':')
- except ValueError, e:
+ except ValueError as e:
raise ValueError(
"Unexpected tryjob format. You may be running an "
"older version of chromite. Run 'repo sync "
diff --git a/lib/rewrite_git_alternates.py b/lib/rewrite_git_alternates.py
index 6ad9a42..ceba76e 100755
--- a/lib/rewrite_git_alternates.py
+++ b/lib/rewrite_git_alternates.py
@@ -124,7 +124,7 @@
try:
if long(os.stat(cache_path).st_mtime) == manifest_time:
return osutils.ReadFile(cache_path).split()
- except EnvironmentError, e:
+ except EnvironmentError as e:
if e.errno != errno.ENOENT:
raise
diff --git a/lib/sudo.py b/lib/sudo.py
index 925e198..669b252 100644
--- a/lib/sudo.py
+++ b/lib/sudo.py
@@ -37,7 +37,7 @@
for source in (sys.stdin, sys.stdout, sys.stderr):
try:
return os.ttyname(source.fileno())
- except EnvironmentError, e:
+ except EnvironmentError as e:
if e.errno not in (errno.EINVAL, errno.ENOTTY):
raise
@@ -131,7 +131,7 @@
try:
self._proc.terminate()
self._proc.wait()
- except EnvironmentError, e:
+ except EnvironmentError as e:
if e.errno != errno.ESRCH:
raise
diff --git a/lib/tracker_access.py b/lib/tracker_access.py
index 3357bdb..418f512 100644
--- a/lib/tracker_access.py
+++ b/lib/tracker_access.py
@@ -84,7 +84,7 @@
query = gdata.projecthosting.client.Query(issue_id=issue_id)
try:
feed = self._tracker_client.get_issues(project_name, query=query)
- except gdata.client.RequestError, e:
+ except gdata.client.RequestError as e:
if VERBOSE:
print >> sys.stderr, "ERROR: Unable to access bug %s:%s: %s" % (
project_name, issue_id, str(e))
diff --git a/license-generation/licenses.py b/license-generation/licenses.py
index 02479f8..a74b04a 100755
--- a/license-generation/licenses.py
+++ b/license-generation/licenses.py
@@ -788,7 +788,7 @@
try:
pkg.GetLicenses(package_name)
self.packages[package_name] = pkg
- except PackageSkipped, e:
+ except PackageSkipped as e:
logging.info(e)
except PackageLicenseError:
self.incomplete_packages += [pkg.fullnamerev]
diff --git a/scripts/cros_portage_upgrade_unittest.py b/scripts/cros_portage_upgrade_unittest.py
index e1c5bfd..5ef8c84 100755
--- a/scripts/cros_portage_upgrade_unittest.py
+++ b/scripts/cros_portage_upgrade_unittest.py
@@ -3574,7 +3574,7 @@
"""
try:
cpu.main(args)
- except exceptions.SystemExit, e:
+ except exceptions.SystemExit as e:
if expect_zero:
self.assertEquals(e.args[0], 0,
msg='expected call to main() to exit cleanly, '
@@ -3591,7 +3591,7 @@
# Running with --help should exit with code==0
try:
cpu.main(['--help'])
- except exceptions.SystemExit, e:
+ except exceptions.SystemExit as e:
self.assertEquals(e.args[0], 0)
# Verify that a message beginning with "Usage: " was printed
@@ -3604,7 +3604,7 @@
# Running without --board should exit with code!=0
try:
cpu.main([])
- except exceptions.SystemExit, e:
+ except exceptions.SystemExit as e:
self.assertNotEquals(e.args[0], 0)
# Verify that an error message was printed.
diff --git a/scripts/merge_package_status_unittest.py b/scripts/merge_package_status_unittest.py
index 23cd2b2..8cdccd7 100644
--- a/scripts/merge_package_status_unittest.py
+++ b/scripts/merge_package_status_unittest.py
@@ -227,7 +227,7 @@
# Running with --help should exit with code==0
try:
mps.main(['--help'])
- except exceptions.SystemExit, e:
+ except exceptions.SystemExit as e:
self.assertEquals(e.args[0], 0)
# Verify that a message beginning with "Usage: " was printed
@@ -242,7 +242,7 @@
# Running without --out should exit with code!=0
try:
mps.main([])
- except exceptions.SystemExit, e:
+ except exceptions.SystemExit as e:
self.assertNotEquals(e.args[0], 0)
# Verify that output ends in error.
@@ -254,7 +254,7 @@
# Running without a package should exit with code!=0
try:
mps.main(['--out=any-out'])
- except exceptions.SystemExit, e:
+ except exceptions.SystemExit as e:
self.assertNotEquals(e.args[0], 0)
# Verify that output ends in error.
diff --git a/scripts/upload_package_status_unittest.py b/scripts/upload_package_status_unittest.py
index 5901cee..097486d 100644
--- a/scripts/upload_package_status_unittest.py
+++ b/scripts/upload_package_status_unittest.py
@@ -346,7 +346,7 @@
# Running with --help should exit with code==0
try:
ups.main(['--help'])
- except exceptions.SystemExit, e:
+ except exceptions.SystemExit as e:
self.assertEquals(e.args[0], 0)
# Verify that a message beginning with "Usage: " was printed
@@ -359,7 +359,7 @@
# Running without a package should exit with code!=0
try:
ups.main([])
- except exceptions.SystemExit, e:
+ except exceptions.SystemExit as e:
self.assertNotEquals(e.args[0], 0)
self.AssertOutputEndsInError(check_stdout=True)