From efb9450e279da47bb73811cf11d0fcfda822668d Mon Sep 17 00:00:00 2001 From: "gspencer@google.com" Date: Fri, 9 Oct 2009 17:57:08 +0000 Subject: [PATCH] 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 --- presubmit_support.py | 16 +++++++++------- tests/presubmit_unittest.py | 19 ++++++++++--------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/presubmit_support.py b/presubmit_support.py index b4ee31197..d26c5370b 100755 --- a/presubmit_support.py +++ b/presubmit_support.py @@ -63,6 +63,10 @@ def normpath(path): path = path.replace(os.sep, '/') 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): """This class (more like a module) gets passed to presubmit scripts so that @@ -102,9 +106,8 @@ class OutputApi(object): self._long_text) if self.ShouldPrompt() and may_prompt: - output_stream.write('Are you sure you want to continue? (y/N): ') - response = input_stream.readline() - if response.strip().lower() != 'y': + if not PromptYesNo(input_stream, output_stream, + 'Are you sure you want to continue? (y/N): '): return False return not self.IsFatal() @@ -953,10 +956,9 @@ def DoPresubmitChecks(change, print "Presubmit checks took %.1fs to calculate." % total_time if not errors and warnings and may_prompt: - output_stream.write( - 'There were presubmit warnings. Sure you want to continue? (y/N): ') - response = input_stream.readline() - if response.strip().lower() != 'y': + if not PromptYesNo(input_stream, output_stream, + 'There were presubmit warnings. ' + 'Are you sure you wish to continue? (y/N): '): error_count += 1 global _ASKED_FOR_FEEDBACK diff --git a/tests/presubmit_unittest.py b/tests/presubmit_unittest.py index 95e49ba6e..132f6aee0 100755 --- a/tests/presubmit_unittest.py +++ b/tests/presubmit_unittest.py @@ -78,15 +78,16 @@ class PresubmitUnittest(PresubmitTestsBase): self.mox.ReplayAll() members = [ 'AffectedFile', 'Change', 'DoGetTrySlaves', 'DoPresubmitChecks', - 'GetTrySlavesExecuter', 'GitChange', 'GitAffectedFile', 'InputApi', - 'ListRelevantPresubmitFiles', 'Main', 'NotImplementedException', - 'OutputApi', 'ParseFiles', 'PresubmitExecuter', 'ScanSubDirs', - 'SvnAffectedFile', 'SvnChange', - 'cPickle', 'cStringIO', 'exceptions', - 'fnmatch', 'gcl', 'gclient_scm', 'glob', 'logging', 'marshal', 'normpath', - 'optparse', 'os', 'pickle', - 'presubmit_canned_checks', 'random', 're', 'subprocess', 'sys', 'time', - 'tempfile', 'traceback', 'types', 'unittest', 'urllib2', 'warnings', + 'GetTrySlavesExecuter', 'GitAffectedFile', 'GitChange', + 'InputApi', 'ListRelevantPresubmitFiles', 'Main', + 'NotImplementedException', 'OutputApi', 'ParseFiles', + 'PresubmitExecuter', 'PromptYesNo', 'ScanSubDirs', + 'SvnAffectedFile', 'SvnChange', 'cPickle', 'cStringIO', + 'exceptions', 'fnmatch', 'gcl', 'gclient_scm', 'glob', + 'logging', 'marshal', 'normpath', 'optparse', 'os', 'pickle', + 'presubmit_canned_checks', 'random', 're', 'subprocess', 'sys', + 'tempfile', 'time', 'traceback', 'types', 'unittest', 'urllib2', + 'warnings', ] # If this test fails, you should add the relevant test. self.compareMembers(presubmit, members)