| 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))
|
|
|