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

Side by Side Diff: presubmit_canned_checks.py

Issue 558007: Add presubmit_canned_checks.CheckLicense() (Closed)
Patch Set: Created 10 years, 10 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 ### Description checks 8 ### Description checks
9 9
10 def CheckChangeHasTestField(input_api, output_api): 10 def CheckChangeHasTestField(input_api, output_api):
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 if len(bad) == 5: # Just show the first 5 errors. 260 if len(bad) == 5: # Just show the first 5 errors.
261 break 261 break
262 262
263 if bad: 263 if bad:
264 msg = "Found lines longer than %s characters (first 5 shown)." % maxlen 264 msg = "Found lines longer than %s characters (first 5 shown)." % maxlen
265 return [output_api.PresubmitPromptWarning(msg, items=bad)] 265 return [output_api.PresubmitPromptWarning(msg, items=bad)]
266 else: 266 else:
267 return [] 267 return []
268 268
269 269
270 def CheckLicense(input_api, output_api, license, source_file_filter=None):
271 """Verifies the license header.
272 """
273 license_re = input_api.re.compile(license, input_api.re.MULTILINE)
274 bad_files = []
275 for f in input_api.AffectedSourceFiles(source_file_filter):
276 contents = input_api.ReadFile(f, 'rb')
277 if not license_re.search(contents):
278 bad_files.append(f.LocalPath())
279 if bad_files:
280 if input_api.is_committing:
281 res_type = output_api.PresubmitPromptWarning
282 else:
283 res_type = output_api.PresubmitNotifyResult
284 return [res_type(
285 "Found a bad license header in these files:", items=bad_files)]
286 return []
287
288
270 def CheckChangeSvnEolStyle(input_api, output_api, source_file_filter=None): 289 def CheckChangeSvnEolStyle(input_api, output_api, source_file_filter=None):
271 """Checks that the source files have svn:eol-style=LF.""" 290 """Checks that the source files have svn:eol-style=LF."""
272 return CheckSvnProperty(input_api, output_api, 291 return CheckSvnProperty(input_api, output_api,
273 'svn:eol-style', 'LF', 292 'svn:eol-style', 'LF',
274 input_api.AffectedSourceFiles(source_file_filter)) 293 input_api.AffectedSourceFiles(source_file_filter))
275 294
276 295
277 def CheckSvnForCommonMimeTypes(input_api, output_api): 296 def CheckSvnForCommonMimeTypes(input_api, output_api):
278 """Checks that common binary file types have the correct svn:mime-type.""" 297 """Checks that common binary file types have the correct svn:mime-type."""
279 output = [] 298 output = []
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 stderr=input_api.subprocess.PIPE) 405 stderr=input_api.subprocess.PIPE)
387 stdoutdata, stderrdata = subproc.communicate() 406 stdoutdata, stderrdata = subproc.communicate()
388 # Discard the output if returncode == 0 407 # Discard the output if returncode == 0
389 if subproc.returncode: 408 if subproc.returncode:
390 outputs.append("Test '%s' failed with code %d\n%s\n%s\n" % ( 409 outputs.append("Test '%s' failed with code %d\n%s\n%s\n" % (
391 unit_test_name, subproc.returncode, stdoutdata, stderrdata)) 410 unit_test_name, subproc.returncode, stdoutdata, stderrdata))
392 if outputs: 411 if outputs:
393 return [message_type("%d unit tests failed." % len(outputs), 412 return [message_type("%d unit tests failed." % len(outputs),
394 long_text='\n'.join(outputs))] 413 long_text='\n'.join(outputs))]
395 return [] 414 return []
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