kjellander@webrtc.org | de2a76f | 2012-03-27 15:57:30 +0000 | [diff] [blame] | 1 | # Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 2 | # |
| 3 | # Use of this source code is governed by a BSD-style license |
| 4 | # that can be found in the LICENSE file in the root of the source |
| 5 | # tree. An additional intellectual property rights grant can be found |
| 6 | # in the file PATENTS. All contributing project authors may |
| 7 | # be found in the AUTHORS file in the root of the source tree. |
| 8 | |
| 9 | def _LicenseHeader(input_api): |
| 10 | """Returns the license header regexp.""" |
Henrik Kjellander | 57e5fd2 | 2015-05-25 12:55:39 +0200 | [diff] [blame] | 11 | # Accept any year number from 2003 to the current year |
kjellander@webrtc.org | 6307dbf | 2012-08-31 07:07:11 +0000 | [diff] [blame] | 12 | current_year = int(input_api.time.strftime('%Y')) |
Henrik Kjellander | 57e5fd2 | 2015-05-25 12:55:39 +0200 | [diff] [blame] | 13 | allowed_years = (str(s) for s in reversed(xrange(2003, current_year + 1))) |
kjellander@webrtc.org | 6307dbf | 2012-08-31 07:07:11 +0000 | [diff] [blame] | 14 | years_re = '(' + '|'.join(allowed_years) + ')' |
kjellander@webrtc.org | de2a76f | 2012-03-27 15:57:30 +0000 | [diff] [blame] | 15 | license_header = ( |
Henrik Kjellander | 57e5fd2 | 2015-05-25 12:55:39 +0200 | [diff] [blame] | 16 | r'.*? Copyright( \(c\))? %(year)s The WebRTC [Pp]roject [Aa]uthors\. ' |
| 17 | r'All [Rr]ights [Rr]eserved\.\n' |
kjellander@webrtc.org | de2a76f | 2012-03-27 15:57:30 +0000 | [diff] [blame] | 18 | r'.*?\n' |
| 19 | r'.*? Use of this source code is governed by a BSD-style license\n' |
| 20 | r'.*? that can be found in the LICENSE file in the root of the source\n' |
| 21 | r'.*? tree\. An additional intellectual property rights grant can be ' |
| 22 | r'found\n' |
| 23 | r'.*? in the file PATENTS\. All contributing project authors may\n' |
| 24 | r'.*? be found in the AUTHORS file in the root of the source tree\.\n' |
| 25 | ) % { |
kjellander@webrtc.org | 6307dbf | 2012-08-31 07:07:11 +0000 | [diff] [blame] | 26 | 'year': years_re, |
kjellander@webrtc.org | de2a76f | 2012-03-27 15:57:30 +0000 | [diff] [blame] | 27 | } |
| 28 | return license_header |
| 29 | |
| 30 | def _CommonChecks(input_api, output_api): |
| 31 | """Checks common to both upload and commit.""" |
| 32 | results = [] |
kjellander@webrtc.org | de2a76f | 2012-03-27 15:57:30 +0000 | [diff] [blame] | 33 | results.extend(input_api.canned_checks.CheckLicense( |
| 34 | input_api, output_api, _LicenseHeader(input_api))) |
| 35 | return results |
| 36 | |
| 37 | def CheckChangeOnUpload(input_api, output_api): |
| 38 | results = [] |
| 39 | results.extend(_CommonChecks(input_api, output_api)) |
| 40 | return results |
| 41 | |
| 42 | def CheckChangeOnCommit(input_api, output_api): |
| 43 | results = [] |
| 44 | results.extend(_CommonChecks(input_api, output_api)) |
kjellander@webrtc.org | de2a76f | 2012-03-27 15:57:30 +0000 | [diff] [blame] | 45 | return results |