Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(635)

Side by Side Diff: depot_tools/presubmit_support.py

Issue 268023: This makes presubmit queries accept "yes" as well as "y" (Closed) Base URL: svn://chrome-svn/chrome/trunk/tools/
Patch Set: '' Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | depot_tools/tests/presubmit_unittest.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Enables directory-specific presubmit checks to run at upload and/or commit. 6 """Enables directory-specific presubmit checks to run at upload and/or commit.
7 """ 7 """
8 8
9 __version__ = '1.3.3' 9 __version__ = '1.3.3'
10 10
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 56
57 def normpath(path): 57 def normpath(path):
58 '''Version of os.path.normpath that also changes backward slashes to 58 '''Version of os.path.normpath that also changes backward slashes to
59 forward slashes when not running on Windows. 59 forward slashes when not running on Windows.
60 ''' 60 '''
61 # This is safe to always do because the Windows version of os.path.normpath 61 # This is safe to always do because the Windows version of os.path.normpath
62 # will replace forward slashes with backward slashes. 62 # will replace forward slashes with backward slashes.
63 path = path.replace(os.sep, '/') 63 path = path.replace(os.sep, '/')
64 return os.path.normpath(path) 64 return os.path.normpath(path)
65 65
66 def PromptYesNo(input_stream, output_stream, prompt):
67 output_stream.write(prompt)
68 response = input_stream.readline().strip().lower()
69 return response == 'y' or response == 'yes'
66 70
67 class OutputApi(object): 71 class OutputApi(object):
68 """This class (more like a module) gets passed to presubmit scripts so that 72 """This class (more like a module) gets passed to presubmit scripts so that
69 they can specify various types of results. 73 they can specify various types of results.
70 """ 74 """
71 75
72 class PresubmitResult(object): 76 class PresubmitResult(object):
73 """Base class for result objects.""" 77 """Base class for result objects."""
74 78
75 def __init__(self, message, items=None, long_text=''): 79 def __init__(self, message, items=None, long_text=''):
(...skipping 19 matching lines...) Expand all
95 """ 99 """
96 output_stream.write(self._message) 100 output_stream.write(self._message)
97 output_stream.write('\n') 101 output_stream.write('\n')
98 for item in self._items: 102 for item in self._items:
99 output_stream.write(' %s\n' % str(item)) 103 output_stream.write(' %s\n' % str(item))
100 if self._long_text: 104 if self._long_text:
101 output_stream.write('\n***************\n%s\n***************\n' % 105 output_stream.write('\n***************\n%s\n***************\n' %
102 self._long_text) 106 self._long_text)
103 107
104 if self.ShouldPrompt() and may_prompt: 108 if self.ShouldPrompt() and may_prompt:
105 output_stream.write('Are you sure you want to continue? (y/N): ') 109 if not PromptYesNo(input_stream, output_stream,
106 response = input_stream.readline() 110 'Are you sure you want to continue? (y/N): '):
107 if response.strip().lower() != 'y':
108 return False 111 return False
109 112
110 return not self.IsFatal() 113 return not self.IsFatal()
111 114
112 def IsFatal(self): 115 def IsFatal(self):
113 """An error that is fatal stops g4 mail/submit immediately, i.e. before 116 """An error that is fatal stops g4 mail/submit immediately, i.e. before
114 other presubmit scripts are run. 117 other presubmit scripts are run.
115 """ 118 """
116 return False 119 return False
117 120
(...skipping 828 matching lines...) Expand 10 before | Expand all | Expand 10 after
946 if not item._Handle(output_stream, input_stream, 949 if not item._Handle(output_stream, input_stream,
947 may_prompt=False): 950 may_prompt=False):
948 error_count += 1 951 error_count += 1
949 output_stream.write('\n') 952 output_stream.write('\n')
950 953
951 total_time = time.time() - start_time 954 total_time = time.time() - start_time
952 if total_time > 1.0: 955 if total_time > 1.0:
953 print "Presubmit checks took %.1fs to calculate." % total_time 956 print "Presubmit checks took %.1fs to calculate." % total_time
954 957
955 if not errors and warnings and may_prompt: 958 if not errors and warnings and may_prompt:
956 output_stream.write( 959 if not PromptYesNo(input_stream, output_stream,
957 'There were presubmit warnings. Sure you want to continue? (y/N): ') 960 'There were presubmit warnings. '
958 response = input_stream.readline() 961 'Are you sure you wish to continue? (y/N): '):
959 if response.strip().lower() != 'y':
960 error_count += 1 962 error_count += 1
961 963
962 global _ASKED_FOR_FEEDBACK 964 global _ASKED_FOR_FEEDBACK
963 # Ask for feedback one time out of 5. 965 # Ask for feedback one time out of 5.
964 if (len(results) and random.randint(0, 4) == 0 and not _ASKED_FOR_FEEDBACK): 966 if (len(results) and random.randint(0, 4) == 0 and not _ASKED_FOR_FEEDBACK):
965 output_stream.write("Was the presubmit check useful? Please send feedback " 967 output_stream.write("Was the presubmit check useful? Please send feedback "
966 "& hate mail to maruel@chromium.org!\n") 968 "& hate mail to maruel@chromium.org!\n")
967 _ASKED_FOR_FEEDBACK = True 969 _ASKED_FOR_FEEDBACK = True
968 return (error_count == 0) 970 return (error_count == 0)
969 971
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1046 options.commit, 1048 options.commit,
1047 options.verbose, 1049 options.verbose,
1048 sys.stdout, 1050 sys.stdout,
1049 sys.stdin, 1051 sys.stdin,
1050 options.default_presubmit, 1052 options.default_presubmit,
1051 options.may_prompt) 1053 options.may_prompt)
1052 1054
1053 1055
1054 if __name__ == '__main__': 1056 if __name__ == '__main__':
1055 sys.exit(Main(sys.argv)) 1057 sys.exit(Main(sys.argv))
OLDNEW
« no previous file with comments | « no previous file | depot_tools/tests/presubmit_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698