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

Unified Diff: presubmit_canned_checks.py

Issue 558007: Add presubmit_canned_checks.CheckLicense() (Closed)
Patch Set: Created 10 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/presubmit_unittest.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: presubmit_canned_checks.py
diff --git a/presubmit_canned_checks.py b/presubmit_canned_checks.py
index 3a57490078bc2a8fd0af1de414d32f231fa4d404..577dfc99526935b7f4b997cfa944647bd4523713 100755
--- a/presubmit_canned_checks.py
+++ b/presubmit_canned_checks.py
@@ -267,6 +267,25 @@ def CheckLongLines(input_api, output_api, maxlen=80, source_file_filter=None):
return []
+def CheckLicense(input_api, output_api, license, source_file_filter=None):
+ """Verifies the license header.
+ """
+ license_re = input_api.re.compile(license, input_api.re.MULTILINE)
+ bad_files = []
+ for f in input_api.AffectedSourceFiles(source_file_filter):
+ contents = input_api.ReadFile(f, 'rb')
+ if not license_re.search(contents):
+ bad_files.append(f.LocalPath())
+ if bad_files:
+ if input_api.is_committing:
+ res_type = output_api.PresubmitPromptWarning
+ else:
+ res_type = output_api.PresubmitNotifyResult
+ return [res_type(
+ "Found a bad license header in these files:", items=bad_files)]
+ return []
+
+
def CheckChangeSvnEolStyle(input_api, output_api, source_file_filter=None):
"""Checks that the source files have svn:eol-style=LF."""
return CheckSvnProperty(input_api, output_api,
« 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