OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2010 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.4' | 9 __version__ = '1.4' |
10 | 10 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 # sure loads exists. | 43 # sure loads exists. |
44 # Statement seems to have no effect | 44 # Statement seems to have no effect |
45 # pylint: disable=W0104 | 45 # pylint: disable=W0104 |
46 json.loads | 46 json.loads |
47 except (ImportError, AttributeError): | 47 except (ImportError, AttributeError): |
48 # Import the one included in depot_tools. | 48 # Import the one included in depot_tools. |
49 sys.path.append(os.path.join(os.path.dirname(__file__), 'third_party')) | 49 sys.path.append(os.path.join(os.path.dirname(__file__), 'third_party')) |
50 import simplejson as json # pylint: disable=F0401 | 50 import simplejson as json # pylint: disable=F0401 |
51 | 51 |
52 # Local imports. | 52 # Local imports. |
53 import fix_encoding | |
54 import gclient_utils | 53 import gclient_utils |
55 import owners | 54 import owners |
56 import presubmit_canned_checks | 55 import presubmit_canned_checks |
57 import scm | 56 import scm |
58 | 57 |
59 | 58 |
60 # Ask for feedback only once in program lifetime. | 59 # Ask for feedback only once in program lifetime. |
61 _ASKED_FOR_FEEDBACK = False | 60 _ASKED_FOR_FEEDBACK = False |
62 | 61 |
63 | 62 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 """ | 135 """ |
137 self._message = message | 136 self._message = message |
138 self._items = [] | 137 self._items = [] |
139 if items: | 138 if items: |
140 self._items = items | 139 self._items = items |
141 self._long_text = long_text.rstrip() | 140 self._long_text = long_text.rstrip() |
142 | 141 |
143 def handle(self, output): | 142 def handle(self, output): |
144 output.write(self._message) | 143 output.write(self._message) |
145 output.write('\n') | 144 output.write('\n') |
146 for index, item in enumerate(self._items): | 145 if len(self._items) > 0: |
147 output.write(' ') | 146 output.write(' ' + ' \\\n '.join(map(str, self._items)) + '\n') |
148 # Write separately in case it's unicode. | |
149 output.write(item) | |
150 if index < len(self._items) - 1: | |
151 output.write(' \\') | |
152 output.write('\n') | |
153 if self._long_text: | 147 if self._long_text: |
154 output.write('\n***************\n') | 148 # Sometimes self._long_text is a ascii string, a codepage string |
155 # Write separately in case it's unicode. | 149 # (on windows), or a unicode object. |
156 output.write(self._long_text) | 150 try: |
157 output.write('\n***************\n') | 151 long_text = self._long_text.decode() |
| 152 except UnicodeDecodeError: |
| 153 long_text = self._long_text.decode('ascii', 'replace') |
| 154 |
| 155 output.write('\n***************\n%s\n***************\n' % |
| 156 long_text) |
158 if self.fatal: | 157 if self.fatal: |
159 output.fail() | 158 output.fail() |
160 | 159 |
161 class PresubmitAddReviewers(PresubmitResult): | 160 class PresubmitAddReviewers(PresubmitResult): |
162 """Add some suggested reviewers to the change.""" | 161 """Add some suggested reviewers to the change.""" |
163 def __init__(self, reviewers): | 162 def __init__(self, reviewers): |
164 super(OutputApi.PresubmitAddReviewers, self).__init__('') | 163 super(OutputApi.PresubmitAddReviewers, self).__init__('') |
165 self.reviewers = reviewers | 164 self.reviewers = reviewers |
166 | 165 |
167 def handle(self, output): | 166 def handle(self, output): |
(...skipping 1018 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1186 options.commit, | 1185 options.commit, |
1187 options.verbose, | 1186 options.verbose, |
1188 sys.stdout, | 1187 sys.stdout, |
1189 sys.stdin, | 1188 sys.stdin, |
1190 options.default_presubmit, | 1189 options.default_presubmit, |
1191 options.may_prompt) | 1190 options.may_prompt) |
1192 return not results.should_continue() | 1191 return not results.should_continue() |
1193 | 1192 |
1194 | 1193 |
1195 if __name__ == '__main__': | 1194 if __name__ == '__main__': |
1196 fix_encoding.fix_encoding() | |
1197 sys.exit(Main(None)) | 1195 sys.exit(Main(None)) |
OLD | NEW |