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

Side by Side Diff: post_processors/chromium_copyright.py

Issue 6880115: Add post_processing code to update copyright year automatically. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/commit-queue
Patch Set: Significantly simplify code Created 9 years, 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « post_processors/__init__.py ('k') | projects.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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))
OLDNEW
« no previous file with comments | « post_processors/__init__.py ('k') | projects.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698