| OLD | NEW |
| (Empty) |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 import datetime | |
| 6 import os | |
| 7 import re | |
| 8 | |
| 9 import errors | |
| 10 | |
| 11 | |
| 12 def process(checkout, patch): | |
| 13 """Enforces current year in Chromium copyright.""" | |
| 14 pattern = ( | |
| 15 r'^(.*)Copyright (?:\(c\) )?\d{4}(|-\d{4}) The Chromium Authors. ' | |
| 16 r'All rights reserved.$') | |
| 17 replacement = ( | |
| 18 r'\1Copyright %s The Chromium Authors. All rights reserved.' % | |
| 19 datetime.date.today().year) | |
| 20 | |
| 21 if not patch.is_new or patch.is_binary: | |
| 22 return | |
| 23 filepath = os.path.join(checkout.project_path, patch.filename) | |
| 24 try: | |
| 25 with open(filepath, 'rb') as f: | |
| 26 lines = f.read().splitlines(True) | |
| 27 except IOError, e: | |
| 28 errors.send_stack(e) | |
| 29 lines = None | |
| 30 if not lines: | |
| 31 return | |
| 32 modified = False | |
| 33 for i in xrange(min(5, len(lines))): | |
| 34 old_line = lines[i] | |
| 35 lines[i] = re.sub(pattern, replacement, lines[i]) | |
| 36 if old_line != lines[i]: | |
| 37 modified = True | |
| 38 break | |
| 39 if modified: | |
| 40 with open(filepath, 'wb') as f: | |
| 41 f.write(''.join(lines)) | |
| OLD | NEW |