Commit efb9450e authored by gspencer@google.com's avatar gspencer@google.com

This makes presubmit queries accept "yes" as well as "y"

as an answer.
Review URL: http://codereview.chromium.org/268023

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@28557 0039d316-1c4b-4281-b951-d872f2087c98
parent 7658eb3c
...@@ -63,6 +63,10 @@ def normpath(path): ...@@ -63,6 +63,10 @@ def normpath(path):
path = path.replace(os.sep, '/') path = path.replace(os.sep, '/')
return os.path.normpath(path) return os.path.normpath(path)
def PromptYesNo(input_stream, output_stream, prompt):
output_stream.write(prompt)
response = input_stream.readline().strip().lower()
return response == 'y' or response == 'yes'
class OutputApi(object): class OutputApi(object):
"""This class (more like a module) gets passed to presubmit scripts so that """This class (more like a module) gets passed to presubmit scripts so that
...@@ -102,9 +106,8 @@ class OutputApi(object): ...@@ -102,9 +106,8 @@ class OutputApi(object):
self._long_text) self._long_text)
if self.ShouldPrompt() and may_prompt: if self.ShouldPrompt() and may_prompt:
output_stream.write('Are you sure you want to continue? (y/N): ') if not PromptYesNo(input_stream, output_stream,
response = input_stream.readline() 'Are you sure you want to continue? (y/N): '):
if response.strip().lower() != 'y':
return False return False
return not self.IsFatal() return not self.IsFatal()
...@@ -953,10 +956,9 @@ def DoPresubmitChecks(change, ...@@ -953,10 +956,9 @@ def DoPresubmitChecks(change,
print "Presubmit checks took %.1fs to calculate." % total_time print "Presubmit checks took %.1fs to calculate." % total_time
if not errors and warnings and may_prompt: if not errors and warnings and may_prompt:
output_stream.write( if not PromptYesNo(input_stream, output_stream,
'There were presubmit warnings. Sure you want to continue? (y/N): ') 'There were presubmit warnings. '
response = input_stream.readline() 'Are you sure you wish to continue? (y/N): '):
if response.strip().lower() != 'y':
error_count += 1 error_count += 1
global _ASKED_FOR_FEEDBACK global _ASKED_FOR_FEEDBACK
......
...@@ -78,15 +78,16 @@ class PresubmitUnittest(PresubmitTestsBase): ...@@ -78,15 +78,16 @@ class PresubmitUnittest(PresubmitTestsBase):
self.mox.ReplayAll() self.mox.ReplayAll()
members = [ members = [
'AffectedFile', 'Change', 'DoGetTrySlaves', 'DoPresubmitChecks', 'AffectedFile', 'Change', 'DoGetTrySlaves', 'DoPresubmitChecks',
'GetTrySlavesExecuter', 'GitChange', 'GitAffectedFile', 'InputApi', 'GetTrySlavesExecuter', 'GitAffectedFile', 'GitChange',
'ListRelevantPresubmitFiles', 'Main', 'NotImplementedException', 'InputApi', 'ListRelevantPresubmitFiles', 'Main',
'OutputApi', 'ParseFiles', 'PresubmitExecuter', 'ScanSubDirs', 'NotImplementedException', 'OutputApi', 'ParseFiles',
'SvnAffectedFile', 'SvnChange', 'PresubmitExecuter', 'PromptYesNo', 'ScanSubDirs',
'cPickle', 'cStringIO', 'exceptions', 'SvnAffectedFile', 'SvnChange', 'cPickle', 'cStringIO',
'fnmatch', 'gcl', 'gclient_scm', 'glob', 'logging', 'marshal', 'normpath', 'exceptions', 'fnmatch', 'gcl', 'gclient_scm', 'glob',
'optparse', 'os', 'pickle', 'logging', 'marshal', 'normpath', 'optparse', 'os', 'pickle',
'presubmit_canned_checks', 'random', 're', 'subprocess', 'sys', 'time', 'presubmit_canned_checks', 'random', 're', 'subprocess', 'sys',
'tempfile', 'traceback', 'types', 'unittest', 'urllib2', 'warnings', 'tempfile', 'time', 'traceback', 'types', 'unittest', 'urllib2',
'warnings',
] ]
# If this test fails, you should add the relevant test. # If this test fails, you should add the relevant test.
self.compareMembers(presubmit, members) self.compareMembers(presubmit, members)
......
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