#!/usr/bin/env python3 # Copyright (C) 2024 Riften Labs AS, # 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 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" ] # Multiple possible copyright lines to allow both 2024 and 2025 copyright_lines = [ "Copyright (C) 2024 Riften Labs AS", "Copyright (C) 2025 Riften Labs AS" ] OUR_PATH = os.path.dirname(os.path.realpath(__file__)) def check_file_for_lines(file_path, lines, copyright_lines): """Check if the file contains all the specified lines and at least one 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 at least one copyright line is present copyright_present = any(line in content for line in copyright_lines) 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_lines): 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'])