riftenlabs-indexer/linters/copyright_check.py
Dagur Valberg Johannsson d85bc2c9db
Update copyright headers
2026-01-21 12:37:13 +01:00

52 lines
2.1 KiB
Python
Executable file

#!/usr/bin/env python3
# Copyright (C) 2024-2026 Whiterun LLC,
# This software is licensed under the GNU Affero General Public License (AGPL), version 3.0 or later.,
# A copy of the license can be found in the LICENSE file or at https://www.gnu.org/licenses/agpl-3.0.html
import os
import re
import sys
required_lines = [
"This software is licensed under the GNU Affero General Public License (AGPL), version 3.0 or later.",
"A copy of the license can be found in the LICENSE file or at https://www.gnu.org/licenses/agpl-3.0.html"
]
# Regex pattern to match copyright lines with Whiterun LLC
# Matches: "Copyright (C) 2026 Whiterun LLC" or "Copyright (C) 2024-2026 Whiterun LLC"
copyright_pattern = re.compile(r"Copyright \(C\) (\d{4}-)?\d{4} Whiterun LLC")
OUR_PATH = os.path.dirname(os.path.realpath(__file__))
def check_file_for_lines(file_path, lines, copyright_pattern):
"""Check if the file contains all the specified lines and a valid copyright line."""
with open(file_path, 'r', encoding='utf-8') as file:
content = file.read()
# Check if all required lines are present
required_present = all(line in content for line in lines)
# Check if copyright pattern matches
copyright_present = bool(copyright_pattern.search(content))
return required_present and copyright_present
def check_files(directories):
"""Traverse the src directory and check each .rs file."""
missing = 0
for directory in directories:
for root, dirs, files in os.walk(os.path.join(OUR_PATH, "..", directory)):
for file in files:
if file.endswith('.rs') or file.endswith('.py'):
file_path = os.path.join(root, file)
if not check_file_for_lines(file_path, required_lines, copyright_pattern):
print(f"{file_path}: Missing")
missing += 1
if missing:
print(f"{missing} file(s) are missing copyright headers")
sys.exit(1)
else:
print(f"OK")
sys.exit(0)
check_files(['src', 'contrib', 'linters'])