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

Side by Side Diff: presubmit_canned_checks.py

Issue 131056: Add svn:mime-type canned checks. (Closed)
Patch Set: . Created 11 years, 6 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
« no previous file with comments | « no previous file | 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/env python 1 #!/usr/bin/env 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 """Generic presubmit checks that can be reused by other presubmit checks.""" 6 """Generic presubmit checks that can be reused by other presubmit checks."""
7 7
8 8
9 ### Description checks 9 ### Description checks
10 10
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 182
183 if bad: 183 if bad:
184 msg = "Found lines longer than %s characters (first 5 shown)." % maxlen 184 msg = "Found lines longer than %s characters (first 5 shown)." % maxlen
185 return [output_api.PresubmitPromptWarning(msg, items=bad)] 185 return [output_api.PresubmitPromptWarning(msg, items=bad)]
186 else: 186 else:
187 return [] 187 return []
188 188
189 189
190 def CheckChangeSvnEolStyle(input_api, output_api, source_file_filter=None): 190 def CheckChangeSvnEolStyle(input_api, output_api, source_file_filter=None):
191 """Checks that the source files have svn:eol-style=LF.""" 191 """Checks that the source files have svn:eol-style=LF."""
192 bad = filter(lambda f: f.scm == 'svn' and f.Property('svn:eol-style') != 'LF', 192 return CheckSvnProperty(input_api, output_api,
193 input_api.AffectedSourceFiles(source_file_filter)) 193 'svn:eol-style', 'LF',
194 input_api.AffectedSourceFiles(source_file_filter))
195
196
197 def CheckSvnForCommonMimeTypes(input_api, output_api):
198 """Checks that common binary file types have the correct svn:mime-type."""
199 output = []
200 files = input_api.AffectedFiles(include_deletes=False)
201 def FilterFiles(extension):
202 return filter(lambda x: x.endswith(extension), files)
203 def JpegFiles():
204 return filter(lambda x: (x.endswith('.jpg') or x.endswith('.jpeg') or
205 x.endswith('.jpe')),
206 files)
207 def RunCheck(mime_type, files):
208 output.extend(CheckSvnProperty(input_api, output_api, 'svn:mime-type',
209 mime_type, files))
210 RunCheck('application/pdf', FilterFiles('.pdf'))
211 RunCheck('image/bmp', FilterFiles('.bmp'))
212 RunCheck('image/gif', FilterFiles('.gif'))
213 RunCheck('image/png', FilterFiles('.png'))
214 RunCheck('image/jpeg', JpegFiles())
215 RunCheck('image/vnd.microsoft.icon', FilterFiles('.ico'))
216 return output
217
218
219 def CheckSvnProperty(input_api, output_api, prop, expected, affected_files):
220 """Checks that affected_files files have prop=expected."""
221 bad = filter(lambda f: f.scm == 'svn' and f.Property(prop) != expected,
222 affected_files)
194 if bad: 223 if bad:
195 if input_api.is_committing: 224 if input_api.is_committing:
196 return [output_api.PresubmitError( 225 type = output_api.PresubmitError
197 "Run `svn pset svn:eol-style LF <item>` on these files:",
198 items=bad)]
199 else: 226 else:
200 return [output_api.PresubmitNotifyResult( 227 type = output_api.PresubmitNotifyResult
201 "Run `svn pset svn:eol-style LF <item>` on these files:", 228 message = "Run `svn pset %s %s <item>` on these files:" % (prop, expected)
202 items=bad)] 229 return [type(message, items=bad)]
203 return [] 230 return []
204 231
205 232
206 ### Other checks 233 ### Other checks
207 234
208 def CheckDoNotSubmit(input_api, output_api): 235 def CheckDoNotSubmit(input_api, output_api):
209 return ( 236 return (
210 CheckDoNotSubmitInDescription(input_api, output_api) + 237 CheckDoNotSubmitInDescription(input_api, output_api) +
211 CheckDoNotSubmitInFiles(input_api, output_api) 238 CheckDoNotSubmitInFiles(input_api, output_api)
212 ) 239 )
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 long_text=input_api.traceback.format_exc())) 281 long_text=input_api.traceback.format_exc()))
255 282
256 buffer = input_api.cStringIO.StringIO() 283 buffer = input_api.cStringIO.StringIO()
257 results = input_api.unittest.TextTestRunner(stream=buffer, verbosity=0).run( 284 results = input_api.unittest.TextTestRunner(stream=buffer, verbosity=0).run(
258 input_api.unittest.TestSuite(tests_suite)) 285 input_api.unittest.TestSuite(tests_suite))
259 if not results.wasSuccessful(): 286 if not results.wasSuccessful():
260 outputs.append(message_type("%d unit tests failed." % 287 outputs.append(message_type("%d unit tests failed." %
261 (len(results.failures) + len(results.errors)), 288 (len(results.failures) + len(results.errors)),
262 long_text=buffer.getvalue())) 289 long_text=buffer.getvalue()))
263 return outputs 290 return outputs
OLDNEW
« no previous file with comments | « no previous file | tests/presubmit_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698