|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# Copyright 2026 Google LLC |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | + |
| 16 | +import os |
| 17 | +import re |
| 18 | +import sys |
| 19 | + |
| 20 | +def fix_copyright(path): |
| 21 | + if os.path.isfile(path): |
| 22 | + if path.endswith(".java"): |
| 23 | + _fix_file(path) |
| 24 | + elif os.path.isdir(path): |
| 25 | + for root, _, files in os.walk(path): |
| 26 | + for file in files: |
| 27 | + if file.endswith(".java"): |
| 28 | + _fix_file(os.path.join(root, file)) |
| 29 | + |
| 30 | +def _fix_file(file_path): |
| 31 | + with open(file_path, 'r') as f: |
| 32 | + content = f.read() |
| 33 | + |
| 34 | + # Replace "Copyright [Year] Google LLC" or "Copyright [Year] Google Inc." |
| 35 | + # with "Copyright 2026 Google LLC" |
| 36 | + new_content = re.sub( |
| 37 | + r'Copyright \d{4} Google (Inc\.|LLC)', |
| 38 | + 'Copyright 2026 Google LLC', |
| 39 | + content |
| 40 | + ) |
| 41 | + |
| 42 | + if new_content != content: |
| 43 | + with open(file_path, 'w') as f: |
| 44 | + f.write(new_content) |
| 45 | + print(f"Updated copyright in {file_path}") |
| 46 | + |
| 47 | +if __name__ == "__main__": |
| 48 | + if len(sys.argv) < 2: |
| 49 | + print("Usage: fix_copyright_headers.py <file_or_directory_path> ...") |
| 50 | + sys.exit(1) |
| 51 | + |
| 52 | + for arg in sys.argv[1:]: |
| 53 | + fix_copyright(arg) |
0 commit comments