Convert print statements to Python 3 style
Ran "2to3 -w -n -f print ./" and manually added imports.
Ran "^\s*print " and "\s+print " to find batch/shell scripts, comments and the like with embedded code, and updated them manually.
Also manually added imports to files, which used print as a function, but were missing the import.
The scripts still work with Python 2.
There are no intended behaviour changes.
Bug: 942522
Change-Id: Id777e4d4df4adcdfdab1b18bde89f235ef491b9f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1595684
Reviewed-by: Dirk Pranke <dpranke@chromium.org>
Commit-Queue: Dirk Pranke <dpranke@chromium.org>
Auto-Submit: Raul Tambre <raul@tambre.ee>
diff --git a/roll_dep_svn.py b/roll_dep_svn.py
index d564b85..a7c9a28 100755
--- a/roll_dep_svn.py
+++ b/roll_dep_svn.py
@@ -19,6 +19,8 @@
$ git commit
"""
+from __future__ import print_function
+
import ast
import optparse
import os
@@ -134,8 +136,8 @@
try:
svn_rev = int(line.split()[1].partition('@')[2])
except (IndexError, ValueError):
- print >> sys.stderr, (
- 'WARNING: Could not parse svn revision out of "%s"' % line)
+ print('WARNING: Could not parse svn revision out of "%s"' % line,
+ file=sys.stderr)
continue
if not latest_svn_rev or int(svn_rev) > int(latest_svn_rev):
latest_svn_rev = svn_rev
@@ -357,15 +359,15 @@
commit_msg = generate_commit_message(
deps_locals['deps_os'][os_name.s], dep_path, dep_name, new_rev)
if not commit_msg:
- print 'Could not find an entry in %s to update.' % deps_file
+ print('Could not find an entry in %s to update.' % deps_file)
return 1
- print 'Pinning %s' % dep_name
- print 'to revision %s' % new_rev
- print 'in %s' % deps_file
+ print('Pinning %s' % dep_name)
+ print('to revision %s' % new_rev)
+ print('in %s' % deps_file)
with open(deps_file, 'w') as fh:
for line in deps_lines:
- print >> fh, line
+ print(line, file=fh)
deps_file_dir = os.path.normpath(os.path.dirname(deps_file))
deps_file_root = Popen(
['git', 'rev-parse', '--show-toplevel'],
@@ -396,7 +398,7 @@
# Only require the path to exist if the revision should be verified. A path
# to e.g. os deps might not be checked out.
if not os.path.isdir(dep_path):
- print >> sys.stderr, 'No such directory: %s' % arg_dep_path
+ print('No such directory: %s' % arg_dep_path, file=sys.stderr)
return 1
if len(args) > 2:
deps_file = args[2]
@@ -407,9 +409,9 @@
dep_name = posix_path(os.path.relpath(dep_path, gclient_root))
if options.no_verify_revision:
if not is_git_hash(revision):
- print >> sys.stderr, (
+ print(
'The passed revision %s must be a git hash when skipping revision '
- 'verification.' % revision)
+ 'verification.' % revision, file=sys.stderr)
return 1
git_rev = revision
comment = None
@@ -417,7 +419,8 @@
git_rev, svn_rev = get_git_revision(dep_path, revision)
comment = ('from svn revision %s' % svn_rev) if svn_rev else None
if not git_rev:
- print >> sys.stderr, 'Could not find git revision matching %s.' % revision
+ print('Could not find git revision matching %s.' % revision,
+ file=sys.stderr)
return 1
return update_deps(deps_file, dep_path, dep_name, git_rev, comment)