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 |
53 import gclient_utils | 54 import gclient_utils |
54 import owners | 55 import owners |
55 import presubmit_canned_checks | 56 import presubmit_canned_checks |
56 import scm | 57 import scm |
57 | 58 |
58 | 59 |
59 # Ask for feedback only once in program lifetime. | 60 # Ask for feedback only once in program lifetime. |
60 _ASKED_FOR_FEEDBACK = False | 61 _ASKED_FOR_FEEDBACK = False |
61 | 62 |
62 | 63 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 """ | 136 """ |
136 self._message = message | 137 self._message = message |
137 self._items = [] | 138 self._items = [] |
138 if items: | 139 if items: |
139 self._items = items | 140 self._items = items |
140 self._long_text = long_text.rstrip() | 141 self._long_text = long_text.rstrip() |
141 | 142 |
142 def handle(self, output): | 143 def handle(self, output): |
143 output.write(self._message) | 144 output.write(self._message) |
144 output.write('\n') | 145 output.write('\n') |
145 if len(self._items) > 0: | 146 for index, item in enumerate(self._items): |
146 output.write(' ' + ' \\\n '.join(map(str, self._items)) + '\n') | 147 output.write(' ') |
| 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') |
147 if self._long_text: | 153 if self._long_text: |
148 # Sometimes self._long_text is a ascii string, a codepage string | 154 output.write('\n***************\n') |
149 # (on windows), or a unicode object. | 155 # Write separately in case it's unicode. |
150 try: | 156 output.write(self._long_text) |
151 long_text = self._long_text.decode() | 157 output.write('\n***************\n') |
152 except UnicodeDecodeError: | |
153 long_text = self._long_text.decode('ascii', 'replace') | |
154 | |
155 output.write('\n***************\n%s\n***************\n' % | |
156 long_text) | |
157 if self.fatal: | 158 if self.fatal: |
158 output.fail() | 159 output.fail() |
159 | 160 |
160 class PresubmitAddReviewers(PresubmitResult): | 161 class PresubmitAddReviewers(PresubmitResult): |
161 """Add some suggested reviewers to the change.""" | 162 """Add some suggested reviewers to the change.""" |
162 def __init__(self, reviewers): | 163 def __init__(self, reviewers): |
163 super(OutputApi.PresubmitAddReviewers, self).__init__('') | 164 super(OutputApi.PresubmitAddReviewers, self).__init__('') |
164 self.reviewers = reviewers | 165 self.reviewers = reviewers |
165 | 166 |
166 def handle(self, output): | 167 def handle(self, output): |
(...skipping 1018 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1185 options.commit, | 1186 options.commit, |
1186 options.verbose, | 1187 options.verbose, |
1187 sys.stdout, | 1188 sys.stdout, |
1188 sys.stdin, | 1189 sys.stdin, |
1189 options.default_presubmit, | 1190 options.default_presubmit, |
1190 options.may_prompt) | 1191 options.may_prompt) |
1191 return not results.should_continue() | 1192 return not results.should_continue() |
1192 | 1193 |
1193 | 1194 |
1194 if __name__ == '__main__': | 1195 if __name__ == '__main__': |
| 1196 fix_encoding.fix_encoding() |
1195 sys.exit(Main(None)) | 1197 sys.exit(Main(None)) |
OLD | NEW |