tweak raise/dict syntax for Python 3 compat
Use the `raise` statement directly.
Switch to using .items() instead of .iteritems(). Python 3 doesn't
have .iteritems() as .items() is a generator, and these are small
enough that the Python 2 overhead should be negligible.
We have to run .keys() through list() in a few places as Python 3
uses a generator and we sometimes want to iterate more than once.
That's why we don't change all .keys() or .items() calls -- most
are in places where generators are fine.
Bug: https://crbug.com/gerrit/10418
Change-Id: I469899d9b77ffd77ccabb831bc4b217407fefe6f
diff --git a/gitc_utils.py b/gitc_utils.py
index 0d4a5c3..f49f7be 100644
--- a/gitc_utils.py
+++ b/gitc_utils.py
@@ -58,8 +58,8 @@
sys.exit(1)
revisionExpr = gitcmd.stdout.split('\t')[0]
if not revisionExpr:
- raise(ManifestParseError('Invalid SHA-1 revision project %s (%s)' %
- (proj.remote.url, proj.revisionExpr)))
+ raise ManifestParseError('Invalid SHA-1 revision project %s (%s)' %
+ (proj.remote.url, proj.revisionExpr))
proj.revisionExpr = revisionExpr
def _manifest_groups(manifest):
@@ -87,7 +87,7 @@
print('Generating GITC Manifest by fetching revision SHAs for each '
'project.')
if paths is None:
- paths = manifest.paths.keys()
+ paths = list(manifest.paths.keys())
groups = [x for x in re.split(r'[,\s]+', _manifest_groups(manifest)) if x]
@@ -96,7 +96,7 @@
projects = [p for p in projects if p.MatchesGroups(groups)]
if gitc_manifest is not None:
- for path, proj in manifest.paths.iteritems():
+ for path, proj in manifest.paths.items():
if not proj.MatchesGroups(groups):
continue
@@ -124,7 +124,7 @@
index += NUM_BATCH_RETRIEVE_REVISIONID
if gitc_manifest is not None:
- for path, proj in gitc_manifest.paths.iteritems():
+ for path, proj in gitc_manifest.paths.items():
if proj.old_revision and path in paths:
# If we updated a project that has been started, keep the old-revision
# updated.
@@ -133,7 +133,7 @@
repo_proj.revisionExpr = None
# Convert URLs from relative to absolute.
- for _name, remote in manifest.remotes.iteritems():
+ for _name, remote in manifest.remotes.items():
remote.fetchUrl = remote.resolvedFetchUrl
# Save the manifest.