Commit bb79beaa authored by vapier@chromium.org's avatar vapier@chromium.org

gclient: use the print function

This makes the code work both in python2 and python3.

Review URL: https://codereview.chromium.org/1433153003

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@297516 0039d316-1c4b-4281-b951-d872f2087c98
parent 150aa7b9
...@@ -76,6 +76,8 @@ ...@@ -76,6 +76,8 @@
# target_os = [ "ios" ] # target_os = [ "ios" ]
# target_os_only = True # target_os_only = True
from __future__ import print_function
__version__ = '0.7' __version__ = '0.7'
import ast import ast
...@@ -244,7 +246,7 @@ class DependencySettings(GClientKeywords): ...@@ -244,7 +246,7 @@ class DependencySettings(GClientKeywords):
if (self._custom_vars.get('webkit_trunk', '') == if (self._custom_vars.get('webkit_trunk', '') ==
'svn://svn-mirror.golo.chromium.org/webkit-readonly/trunk'): 'svn://svn-mirror.golo.chromium.org/webkit-readonly/trunk'):
new_url = 'svn://svn-mirror.golo.chromium.org/blink/trunk' new_url = 'svn://svn-mirror.golo.chromium.org/blink/trunk'
print 'Overwriting Var("webkit_trunk") with %s' % new_url print('Overwriting Var("webkit_trunk") with %s' % new_url)
self._custom_vars['webkit_trunk'] = new_url self._custom_vars['webkit_trunk'] = new_url
# Post process the url to remove trailing slashes. # Post process the url to remove trailing slashes.
...@@ -884,24 +886,24 @@ class Dependency(gclient_utils.WorkItem, DependencySettings): ...@@ -884,24 +886,24 @@ class Dependency(gclient_utils.WorkItem, DependencySettings):
match = re.match('^Binary file ([^\0]+) matches$', line) match = re.match('^Binary file ([^\0]+) matches$', line)
if match: if match:
print 'Binary file %s matches\n' % mod_path(match.group(1)) print('Binary file %s matches\n' % mod_path(match.group(1)))
return return
items = line.split('\0') items = line.split('\0')
if len(items) == 2 and items[1]: if len(items) == 2 and items[1]:
print '%s : %s' % (mod_path(items[0]), items[1]) print('%s : %s' % (mod_path(items[0]), items[1]))
elif len(items) >= 2: elif len(items) >= 2:
# Multiple null bytes or a single trailing null byte indicate # Multiple null bytes or a single trailing null byte indicate
# git is likely displaying filenames only (such as with -l) # git is likely displaying filenames only (such as with -l)
print '\n'.join(mod_path(path) for path in items if path) print('\n'.join(mod_path(path) for path in items if path))
else: else:
print line print(line)
else: else:
print_stdout = True print_stdout = True
filter_fn = None filter_fn = None
if parsed_url is None: if parsed_url is None:
print >> sys.stderr, 'Skipped omitted dependency %s' % cwd print('Skipped omitted dependency %s' % cwd, file=sys.stderr)
elif os.path.isdir(cwd): elif os.path.isdir(cwd):
try: try:
gclient_utils.CheckCallAndFilter( gclient_utils.CheckCallAndFilter(
...@@ -912,7 +914,7 @@ class Dependency(gclient_utils.WorkItem, DependencySettings): ...@@ -912,7 +914,7 @@ class Dependency(gclient_utils.WorkItem, DependencySettings):
if not options.ignore: if not options.ignore:
raise raise
else: else:
print >> sys.stderr, 'Skipped missing %s' % cwd print('Skipped missing %s' % cwd, file=sys.stderr)
@gclient_utils.lockedmethod @gclient_utils.lockedmethod
...@@ -985,13 +987,13 @@ class Dependency(gclient_utils.WorkItem, DependencySettings): ...@@ -985,13 +987,13 @@ class Dependency(gclient_utils.WorkItem, DependencySettings):
# Use a discrete exit status code of 2 to indicate that a hook action # Use a discrete exit status code of 2 to indicate that a hook action
# failed. Users of this script may wish to treat hook action failures # failed. Users of this script may wish to treat hook action failures
# differently from VC failures. # differently from VC failures.
print >> sys.stderr, 'Error: %s' % str(e) print('Error: %s' % str(e), file=sys.stderr)
sys.exit(2) sys.exit(2)
finally: finally:
elapsed_time = time.time() - start_time elapsed_time = time.time() - start_time
if elapsed_time > 10: if elapsed_time > 10:
print "Hook '%s' took %.2f secs" % ( print("Hook '%s' took %.2f secs" % (
gclient_utils.CommandToStr(hook), elapsed_time) gclient_utils.CommandToStr(hook), elapsed_time))
def RunPreDepsHooks(self): def RunPreDepsHooks(self):
assert self.processed assert self.processed
...@@ -1010,13 +1012,13 @@ class Dependency(gclient_utils.WorkItem, DependencySettings): ...@@ -1010,13 +1012,13 @@ class Dependency(gclient_utils.WorkItem, DependencySettings):
# Use a discrete exit status code of 2 to indicate that a hook action # Use a discrete exit status code of 2 to indicate that a hook action
# failed. Users of this script may wish to treat hook action failures # failed. Users of this script may wish to treat hook action failures
# differently from VC failures. # differently from VC failures.
print >> sys.stderr, 'Error: %s' % str(e) print('Error: %s' % str(e), file=sys.stderr)
sys.exit(2) sys.exit(2)
finally: finally:
elapsed_time = time.time() - start_time elapsed_time = time.time() - start_time
if elapsed_time > 10: if elapsed_time > 10:
print "Hook '%s' took %.2f secs" % ( print("Hook '%s' took %.2f secs" % (
gclient_utils.CommandToStr(hook), elapsed_time) gclient_utils.CommandToStr(hook), elapsed_time))
def subtree(self, include_all): def subtree(self, include_all):
...@@ -1389,13 +1391,14 @@ been automagically updated. The previous version is available at %s.old. ...@@ -1389,13 +1391,14 @@ been automagically updated. The previous version is available at %s.old.
if (options.revisions and if (options.revisions and
len(client.dependencies) > 1 and len(client.dependencies) > 1 and
any('@' not in r for r in options.revisions)): any('@' not in r for r in options.revisions)):
print >> sys.stderr, ( print(
'You must specify the full solution name like --revision %s@%s\n' ('You must specify the full solution name like --revision %s@%s\n'
'when you have multiple solutions setup in your .gclient file.\n' 'when you have multiple solutions setup in your .gclient file.\n'
'Other solutions present are: %s.') % ( 'Other solutions present are: %s.') % (
client.dependencies[0].name, client.dependencies[0].name,
options.revisions[0], options.revisions[0],
', '.join(s.name for s in client.dependencies[1:])) ', '.join(s.name for s in client.dependencies[1:])),
file=sys.stderr)
return client return client
def SetDefaultConfig(self, solution_name, deps_file, solution_url, def SetDefaultConfig(self, solution_name, deps_file, solution_url,
...@@ -1519,8 +1522,8 @@ been automagically updated. The previous version is available at %s.old. ...@@ -1519,8 +1522,8 @@ been automagically updated. The previous version is available at %s.old.
work_queue.enqueue(s) work_queue.enqueue(s)
work_queue.flush(revision_overrides, command, args, options=self._options) work_queue.flush(revision_overrides, command, args, options=self._options)
if revision_overrides: if revision_overrides:
print >> sys.stderr, ('Please fix your script, having invalid ' print('Please fix your script, having invalid --revision flags will soon '
'--revision flags will soon considered an error.') 'considered an error.', file=sys.stderr)
# Once all the dependencies have been processed, it's now safe to run the # Once all the dependencies have been processed, it's now safe to run the
# hooks. # hooks.
...@@ -1763,13 +1766,14 @@ def CMDrecurse(parser, args): ...@@ -1763,13 +1766,14 @@ def CMDrecurse(parser, args):
help='Disable progress bar that shows sub-command updates') help='Disable progress bar that shows sub-command updates')
options, args = parser.parse_args(args) options, args = parser.parse_args(args)
if not args: if not args:
print >> sys.stderr, 'Need to supply a command!' print('Need to supply a command!', file=sys.stderr)
return 1 return 1
root_and_entries = gclient_utils.GetGClientRootAndEntries() root_and_entries = gclient_utils.GetGClientRootAndEntries()
if not root_and_entries: if not root_and_entries:
print >> sys.stderr, ( print(
'You need to run gclient sync at least once to use \'recurse\'.\n' 'You need to run gclient sync at least once to use \'recurse\'.\n'
'This is because .gclient_entries needs to exist and be up to date.') 'This is because .gclient_entries needs to exist and be up to date.',
file=sys.stderr)
return 1 return 1
# Normalize options.scm to a set() # Normalize options.scm to a set()
...@@ -1803,13 +1807,13 @@ def CMDgrep(parser, args): ...@@ -1803,13 +1807,13 @@ def CMDgrep(parser, args):
# We can't use optparse because it will try to parse arguments sent # We can't use optparse because it will try to parse arguments sent
# to git grep and throw an error. :-( # to git grep and throw an error. :-(
if not args or re.match('(-h|--help)$', args[0]): if not args or re.match('(-h|--help)$', args[0]):
print >> sys.stderr, ( print(
'Usage: gclient grep [-j <N>] git-grep-args...\n\n' 'Usage: gclient grep [-j <N>] git-grep-args...\n\n'
'Example: "gclient grep -j10 -A2 RefCountedBase" runs\n"git grep ' 'Example: "gclient grep -j10 -A2 RefCountedBase" runs\n"git grep '
'-A2 RefCountedBase" on each of gclient\'s git\nrepos with up to ' '-A2 RefCountedBase" on each of gclient\'s git\nrepos with up to '
'10 jobs.\n\nBonus: page output by appending "|& less -FRSX" to the' '10 jobs.\n\nBonus: page output by appending "|& less -FRSX" to the'
' end of your query.' ' end of your query.',
) file=sys.stderr)
return 1 return 1
jobs_arg = ['--jobs=1'] jobs_arg = ['--jobs=1']
...@@ -2177,7 +2181,7 @@ def CMDhookinfo(parser, args): ...@@ -2177,7 +2181,7 @@ def CMDhookinfo(parser, args):
if not client: if not client:
raise gclient_utils.Error('client not configured; see \'gclient config\'') raise gclient_utils.Error('client not configured; see \'gclient config\'')
client.RunOnDeps(None, []) client.RunOnDeps(None, [])
print '; '.join(' '.join(hook) for hook in client.GetHooks(options)) print('; '.join(' '.join(hook) for hook in client.GetHooks(options)))
return 0 return 0
...@@ -2193,10 +2197,10 @@ def CMDverify(parser, args): ...@@ -2193,10 +2197,10 @@ def CMDverify(parser, args):
bad_deps = dep.findDepsFromNotAllowedHosts() bad_deps = dep.findDepsFromNotAllowedHosts()
if not bad_deps: if not bad_deps:
continue continue
print "There are deps from not allowed hosts in file %s" % dep.deps_file print("There are deps from not allowed hosts in file %s" % dep.deps_file)
for bad_dep in bad_deps: for bad_dep in bad_deps:
print "\t%s at %s" % (bad_dep.name, bad_dep.url) print("\t%s at %s" % (bad_dep.name, bad_dep.url))
print "allowed_hosts:", ', '.join(dep.allowed_hosts) print("allowed_hosts:", ', '.join(dep.allowed_hosts))
sys.stdout.flush() sys.stdout.flush()
raise gclient_utils.Error( raise gclient_utils.Error(
'dependencies from disallowed hosts; check your DEPS file.') 'dependencies from disallowed hosts; check your DEPS file.')
...@@ -2289,13 +2293,15 @@ def main(argv): ...@@ -2289,13 +2293,15 @@ def main(argv):
"""Doesn't parse the arguments here, just find the right subcommand to """Doesn't parse the arguments here, just find the right subcommand to
execute.""" execute."""
if sys.hexversion < 0x02060000: if sys.hexversion < 0x02060000:
print >> sys.stderr, ( print(
'\nYour python version %s is unsupported, please upgrade.\n' % '\nYour python version %s is unsupported, please upgrade.\n' %
sys.version.split(' ', 1)[0]) sys.version.split(' ', 1)[0],
file=sys.stderr)
return 2 return 2
if not sys.executable: if not sys.executable:
print >> sys.stderr, ( print(
'\nPython cannot find the location of it\'s own executable.\n') '\nPython cannot find the location of it\'s own executable.\n',
file=sys.stderr)
return 2 return 2
fix_encoding.fix_encoding() fix_encoding.fix_encoding()
disable_buffering() disable_buffering()
...@@ -2307,7 +2313,7 @@ def main(argv): ...@@ -2307,7 +2313,7 @@ def main(argv):
gclient_utils.GClientChildren.KillAllRemainingChildren() gclient_utils.GClientChildren.KillAllRemainingChildren()
raise raise
except (gclient_utils.Error, subprocess2.CalledProcessError), e: except (gclient_utils.Error, subprocess2.CalledProcessError), e:
print >> sys.stderr, 'Error: %s' % str(e) print('Error: %s' % str(e), file=sys.stderr)
return 1 return 1
finally: finally:
gclient_utils.PrintWarnings() gclient_utils.PrintWarnings()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment