Commit 899e1c1a authored by maruel@chromium.org's avatar maruel@chromium.org

Add verbose support throught presubmit checks

Add propagation of verbose flag from git cl to presubmit_support

Rename NotImplementedException to standard NotImplementError.

R=dpranke@chromium.org
BUG=
TEST=

Review URL: http://codereview.chromium.org/6810012

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@80798 0039d316-1c4b-4281-b951-d872f2087c98
parent ade9c595
......@@ -37,18 +37,16 @@ def CommonChecks(input_api, output_api):
# TODO(maruel): Make sure at least one file is modified first.
# TODO(maruel): If only tests are modified, only run them.
verbose = False
results.extend(input_api.canned_checks.RunUnitTestsInDirectory(
input_api,
output_api,
'tests',
whitelist=[r'.*test\.py$'],
verbose=verbose))
results.extend(RunGitClTests(input_api, output_api, verbose=verbose))
whitelist=[r'.*test\.py$']))
results.extend(RunGitClTests(input_api, output_api))
return results
def RunGitClTests(input_api, output_api, verbose):
def RunGitClTests(input_api, output_api):
"""Run all the shells scripts in the directory test.
"""
if input_api.platform == 'win32':
......@@ -81,7 +79,7 @@ def RunGitClTests(input_api, output_api, verbose):
print('Running %s' % test)
try:
if verbose:
if input_api.verbose:
input_api.subprocess.check_call(
[input_api.os_path.join(test_path, test)], cwd=test_path)
else:
......
......@@ -56,7 +56,7 @@ def DieWithError(message):
def Popen(cmd, **kwargs):
"""Wrapper for subprocess.Popen() that logs and watch for cygwin issues"""
logging.info('Popen: ' + ' '.join(cmd))
logging.debug('Popen: ' + ' '.join(cmd))
try:
return subprocess.Popen(cmd, **kwargs)
except OSError, e:
......@@ -810,7 +810,8 @@ def ConvertToInteger(inputval):
return None
def RunHook(committing, upstream_branch, rietveld_server, tbr, may_prompt):
def RunHook(committing, upstream_branch, rietveld_server, tbr, may_prompt,
verbose):
"""Calls sys.exit() if the hook fails; returns a HookResults otherwise."""
root = RunCommand(['git', 'rev-parse', '--show-cdup']).strip()
if not root:
......@@ -843,10 +844,15 @@ def RunHook(committing, upstream_branch, rietveld_server, tbr, may_prompt):
files = [f.LocalPath() for f in change.AffectedFiles()]
cl.SetWatchers(watchlist.GetWatchersForPaths(files))
output = presubmit_support.DoPresubmitChecks(change, committing,
verbose=False, output_stream=sys.stdout, input_stream=sys.stdin,
default_presubmit=None, may_prompt=may_prompt, tbr=tbr,
host_url=cl.GetRietveldServer())
try:
output = presubmit_support.DoPresubmitChecks(change, committing,
verbose=verbose, output_stream=sys.stdout, input_stream=sys.stdin,
default_presubmit=None, may_prompt=may_prompt, tbr=tbr,
host_url=cl.GetRietveldServer())
except presubmit_support.PresubmitFailure, e:
DieWithError(
('%s\nMaybe your depot_tools is out of date?\n'
'If all fails, contact maruel@') % e)
# TODO(dpranke): We should propagate the error out instead of calling exit().
if not output.should_continue():
......@@ -877,7 +883,7 @@ def CMDpresubmit(parser, args):
RunHook(committing=not options.upload, upstream_branch=base_branch,
rietveld_server=cl.GetRietveldServer(), tbr=False,
may_prompt=False)
may_prompt=False, verbose=options.verbose)
return 0
......@@ -921,7 +927,7 @@ def CMDupload(parser, args):
if not options.bypass_hooks and not options.force:
hook_results = RunHook(committing=False, upstream_branch=base_branch,
rietveld_server=cl.GetRietveldServer(), tbr=False,
may_prompt=True)
may_prompt=True, verbose=options.verbose)
if not options.reviewers and hook_results.reviewers:
options.reviewers = hook_results.reviewers
......@@ -1074,7 +1080,7 @@ def SendUpstream(parser, args, cmd):
if not options.bypass_hooks and not options.force:
RunHook(committing=True, upstream_branch=base_branch,
rietveld_server=cl.GetRietveldServer(), tbr=options.tbr,
may_prompt=True)
may_prompt=True, verbose=options.verbose)
if cmd == 'dcommit':
# Check the tree status if the tree status URL is set.
......@@ -1407,12 +1413,16 @@ def main(argv):
# Create the option parse and add --verbose support.
parser = optparse.OptionParser()
parser.add_option('-v', '--verbose', action='store_true')
parser.add_option(
'-v', '--verbose', action='count', default=0,
help='Use 2 times for more debugging info')
old_parser_args = parser.parse_args
def Parse(args):
options, args = old_parser_args(args)
if options.verbose:
if options.verbose >= 2:
logging.basicConfig(level=logging.DEBUG)
elif options.verbose:
logging.basicConfig(level=logging.INFO)
else:
logging.basicConfig(level=logging.WARNING)
return options, args
......
......@@ -411,8 +411,7 @@ def CheckTreeIsOpen(input_api, output_api,
def RunUnitTestsInDirectory(
input_api, output_api, directory, whitelist=None, blacklist=None,
verbose=False):
input_api, output_api, directory, whitelist=None, blacklist=None):
"""Lists all files in a directory and runs them. Doesn't recurse.
It's mainly a wrapper for RunUnitTests. USe whitelist and blacklist to filter
......@@ -434,10 +433,10 @@ def RunUnitTestsInDirectory(
if blacklist and check(filename, blacklist):
continue
unit_tests.append(input_api.os_path.join(directory, filename))
return RunUnitTests(input_api, output_api, unit_tests, verbose)
return RunUnitTests(input_api, output_api, unit_tests)
def RunUnitTests(input_api, output_api, unit_tests, verbose=False):
def RunUnitTests(input_api, output_api, unit_tests):
"""Runs all unit tests in a directory.
On Windows, sys.executable is used for unit tests ending with ".py".
......@@ -455,10 +454,10 @@ def RunUnitTests(input_api, output_api, unit_tests, verbose=False):
# Windows needs some help.
cmd = [input_api.python_executable]
cmd.append(unit_test)
if verbose:
if input_api.verbose:
print('Running %s' % unit_test)
try:
if verbose:
if input_api.verbose:
input_api.subprocess.check_call(cmd, cwd=input_api.PresubmitLocalPath())
else:
input_api.subprocess.check_output(
......@@ -544,7 +543,6 @@ def RunPylint(input_api, output_api, white_list=None, black_list=None):
The default white_list enforces looking only a *.py files.
"""
verbose = False
white_list = white_list or ['.*\.py$']
black_list = black_list or input_api.DEFAULT_BLACK_LIST
if input_api.is_committing:
......@@ -590,7 +588,7 @@ def RunPylint(input_api, output_api, white_list=None, black_list=None):
return e.code
result = None
if not verbose:
if not input_api.verbose:
result = run_lint(sorted(files))
else:
for filename in sorted(files):
......
This diff is collapsed.
This diff is collapsed.
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