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

Side by Side Diff: presubmit_canned_checks.py

Issue 4360002: Largely reduce the number of pylint warnings and fix one typo. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: address comments Created 10 years, 1 month 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 | « git_cl_hooks.py ('k') | presubmit_support.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 # Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Generic presubmit checks that can be reused by other presubmit checks.""" 5 """Generic presubmit checks that can be reused by other presubmit checks."""
6 6
7 ### Description checks 7 ### Description checks
8 8
9 def CheckChangeHasTestField(input_api, output_api): 9 def CheckChangeHasTestField(input_api, output_api):
10 """Requires that the changelist have a TEST= field.""" 10 """Requires that the changelist have a TEST= field."""
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 if len(bad) == 5: # Just show the first 5 errors. 268 if len(bad) == 5: # Just show the first 5 errors.
269 break 269 break
270 270
271 if bad: 271 if bad:
272 msg = 'Found lines longer than %s characters (first 5 shown).' % maxlen 272 msg = 'Found lines longer than %s characters (first 5 shown).' % maxlen
273 return [output_api.PresubmitPromptWarning(msg, items=bad)] 273 return [output_api.PresubmitPromptWarning(msg, items=bad)]
274 else: 274 else:
275 return [] 275 return []
276 276
277 277
278 def CheckLicense(input_api, output_api, license, source_file_filter=None, 278 def CheckLicense(input_api, output_api, license_re, source_file_filter=None,
279 accept_empty_files=True): 279 accept_empty_files=True):
280 """Verifies the license header. 280 """Verifies the license header.
281 """ 281 """
282 license_re = input_api.re.compile(license, input_api.re.MULTILINE) 282 license_re = input_api.re.compile(license_re, input_api.re.MULTILINE)
283 bad_files = [] 283 bad_files = []
284 for f in input_api.AffectedSourceFiles(source_file_filter): 284 for f in input_api.AffectedSourceFiles(source_file_filter):
285 contents = input_api.ReadFile(f, 'rb') 285 contents = input_api.ReadFile(f, 'rb')
286 if accept_empty_files and not contents: 286 if accept_empty_files and not contents:
287 continue 287 continue
288 if not license_re.search(contents): 288 if not license_re.search(contents):
289 bad_files.append(f.LocalPath()) 289 bad_files.append(f.LocalPath())
290 if bad_files: 290 if bad_files:
291 if input_api.is_committing: 291 if input_api.is_committing:
292 res_type = output_api.PresubmitPromptWarning 292 res_type = output_api.PresubmitPromptWarning
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 return [] 476 return []
477 # Reformat as an dict of platform: [status, url] 477 # Reformat as an dict of platform: [status, url]
478 values = dict([[v[0], [v[1], v[2]]] for v in values if len(v) == 3]) 478 values = dict([[v[0], [v[1], v[2]]] for v in values if len(v) == 3])
479 if not values: 479 if not values:
480 # It returned useless data. 480 # It returned useless data.
481 return [output_api.PresubmitNotifyResult('Failed to parse try job results')] 481 return [output_api.PresubmitNotifyResult('Failed to parse try job results')]
482 482
483 for platform in platforms: 483 for platform in platforms:
484 values.setdefault(platform, ['not started', '']) 484 values.setdefault(platform, ['not started', ''])
485 message = None 485 message = None
486 non_success = [k.upper() for k,v in values.iteritems() if v[0] != 'success'] 486 non_success = [k.upper() for k, v in values.iteritems() if v[0] != 'success']
487 if 'failure' in [v[0] for v in values.itervalues()]: 487 if 'failure' in [v[0] for v in values.itervalues()]:
488 message = 'Try job failures on %s!\n' % ', '.join(non_success) 488 message = 'Try job failures on %s!\n' % ', '.join(non_success)
489 elif non_success: 489 elif non_success:
490 message = ('Unfinished (or not even started) try jobs on ' 490 message = ('Unfinished (or not even started) try jobs on '
491 '%s.\n') % ', '.join(non_success) 491 '%s.\n') % ', '.join(non_success)
492 if message: 492 if message:
493 message += ( 493 message += (
494 'Is try server wrong or broken? Please notify %s. ' 494 'Is try server wrong or broken? Please notify %s. '
495 'Thanks.\n' % owner) 495 'Thanks.\n' % owner)
496 return [output_api.PresubmitPromptWarning(message=message)] 496 return [output_api.PresubmitPromptWarning(message=message)]
(...skipping 27 matching lines...) Expand all
524 pending_builds_len = len(builder.get('pending_builds', [])) 524 pending_builds_len = len(builder.get('pending_builds', []))
525 if pending_builds_len > max_pendings: 525 if pending_builds_len > max_pendings:
526 out.append('%s has %d build(s) pending' % 526 out.append('%s has %d build(s) pending' %
527 (builder_name, pending_builds_len)) 527 (builder_name, pending_builds_len))
528 if out: 528 if out:
529 return [output_api.PresubmitPromptWarning( 529 return [output_api.PresubmitPromptWarning(
530 'Build(s) pending. It is suggested to wait that no more than %d ' 530 'Build(s) pending. It is suggested to wait that no more than %d '
531 'builds are pending.' % max_pendings, 531 'builds are pending.' % max_pendings,
532 long_text='\n'.join(out))] 532 long_text='\n'.join(out))]
533 return [] 533 return []
OLDNEW
« no previous file with comments | « git_cl_hooks.py ('k') | presubmit_support.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698