Chromium Code Reviews

Unified 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.
Jump to:
View side-by-side diff with in-line comments
« no previous file with comments | « post_processors/__init__.py ('k') | projects.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: post_processors/chromium_copyright.py
diff --git a/post_processors/chromium_copyright.py b/post_processors/chromium_copyright.py
new file mode 100644
index 0000000000000000000000000000000000000000..83de20f2024bba5e8163c3a4a7877b2195485186
--- /dev/null
+++ b/post_processors/chromium_copyright.py
@@ -0,0 +1,40 @@
+# Copyright (c) 2011 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+from __future__ import with_statement
+import datetime
+import os
+import re
+
+
+def process(checkout, patches):
+ """Enforces current year in Chromium copyright.
+
+ Makes lawyers happy!
+ """
+ pattern = (
+ r'^(.*)Copyright \(c\) \d\d\d\d The Chromium Authors. '
+ r'All rights reserved.$')
+ replacement = (
+ r'\1Copyright (c) %s The Chromium Authors. All rights reserved.' %
+ datetime.date.today().year)
+
+ for patch in patches.patches:
+ if patch.is_delete or patch.is_binary:
+ pass
+ filepath = os.path.join(checkout.project_path, patch.filename)
+ with open(filepath, 'rb') as f:
+ lines = f.read().splitlines(True)
+ if not lines:
+ continue
+ modified = False
+ for i in xrange(min(5, len(lines))):
+ old_line = lines[i]
+ lines[i] = re.sub(pattern, replacement, lines[i])
+ if old_line != lines[i]:
+ modified = True
+ break
+ if modified:
+ with open(filepath, 'wb') as f:
+ f.write(''.join(lines))
« no previous file with comments | « post_processors/__init__.py ('k') | projects.py » ('j') | no next file with comments »

Powered by Google App Engine