| Henrik Kjellander | b5ffc14 | 2016-12-15 09:48:52 +0100 | [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 |  | 
| Edward Lemur | 27b2c9a | 2018-02-01 15:23:33 +0100 | [diff] [blame] | 9 |  | 
| Henrik Kjellander | b5ffc14 | 2016-12-15 09:48:52 +0100 | [diff] [blame] | 10 | def _LicenseHeader(input_api): | 
 | 11 |   """Returns the license header regexp.""" | 
 | 12 |   # Accept any year number from 2003 to the current year | 
 | 13 |   current_year = int(input_api.time.strftime('%Y')) | 
 | 14 |   allowed_years = (str(s) for s in reversed(xrange(2003, current_year + 1))) | 
 | 15 |   years_re = '(' + '|'.join(allowed_years) + ')' | 
 | 16 |   license_header = ( | 
 | 17 |       r'.*? Copyright( \(c\))? %(year)s The WebRTC [Pp]roject [Aa]uthors\. ' | 
 | 18 |         r'All [Rr]ights [Rr]eserved\.\n' | 
 | 19 |       r'.*?\n' | 
 | 20 |       r'.*? Use of this source code is governed by a BSD-style license\n' | 
 | 21 |       r'.*? that can be found in the LICENSE file in the root of the source\n' | 
 | 22 |       r'.*? tree\. An additional intellectual property rights grant can be ' | 
 | 23 |         r'found\n' | 
 | 24 |       r'.*? in the file PATENTS\.  All contributing project authors may\n' | 
 | 25 |       r'.*? be found in the AUTHORS file in the root of the source tree\.\n' | 
 | 26 |   ) % { | 
 | 27 |       'year': years_re, | 
 | 28 |   } | 
 | 29 |   return license_header | 
 | 30 |  | 
 | 31 | def _CommonChecks(input_api, output_api): | 
 | 32 |   """Checks common to both upload and commit.""" | 
 | 33 |   results = [] | 
 | 34 |   results.extend(input_api.canned_checks.CheckLicense( | 
 | 35 |       input_api, output_api, _LicenseHeader(input_api))) | 
| Henrik Kjellander | b5ffc14 | 2016-12-15 09:48:52 +0100 | [diff] [blame] | 36 |   return results | 
 | 37 |  | 
 | 38 | def CheckChangeOnUpload(input_api, output_api): | 
 | 39 |   results = [] | 
 | 40 |   results.extend(_CommonChecks(input_api, output_api)) | 
 | 41 |   return results | 
 | 42 |  | 
 | 43 | def CheckChangeOnCommit(input_api, output_api): | 
 | 44 |   results = [] | 
 | 45 |   results.extend(_CommonChecks(input_api, output_api)) | 
 | 46 |   return results |