OLD | NEW |
(Empty) | |
| 1 # Copyright (c) 2011 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 from __future__ import with_statement |
| 6 import datetime |
| 7 import os |
| 8 import re |
| 9 |
| 10 |
| 11 def process(checkout, patches): |
| 12 """Enforces current year in Chromium copyright. |
| 13 |
| 14 Makes lawyers happy! |
| 15 """ |
| 16 pattern = ( |
| 17 r'^(.*)Copyright \(c\) \d\d\d\d The Chromium Authors. ' |
| 18 r'All rights reserved.$') |
| 19 replacement = ( |
| 20 r'\1Copyright (c) %s The Chromium Authors. All rights reserved.' % |
| 21 datetime.date.today().year) |
| 22 |
| 23 for patch in patches.patches: |
| 24 if patch.is_delete or patch.is_binary: |
| 25 pass |
| 26 filepath = os.path.join(checkout.project_path, patch.filename) |
| 27 with open(filepath, 'rb') as f: |
| 28 lines = f.read().splitlines(True) |
| 29 if not lines: |
| 30 continue |
| 31 modified = False |
| 32 for i in xrange(min(5, len(lines))): |
| 33 old_line = lines[i] |
| 34 lines[i] = re.sub(pattern, replacement, lines[i]) |
| 35 if old_line != lines[i]: |
| 36 modified = True |
| 37 break |
| 38 if modified: |
| 39 with open(filepath, 'wb') as f: |
| 40 f.write(''.join(lines)) |
OLD | NEW |