From 085bdfaee339d471fd8d49c0b349995d69bf3565 Mon Sep 17 00:00:00 2001 From: Richard Qin Date: Sat, 11 Apr 2026 02:57:24 +0800 Subject: feat: add license header automation script --- scripts/add_license.py | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 scripts/add_license.py (limited to 'scripts/add_license.py') diff --git a/scripts/add_license.py b/scripts/add_license.py new file mode 100644 index 0000000..d15c1fc --- /dev/null +++ b/scripts/add_license.py @@ -0,0 +1,57 @@ +import os +from pathlib import Path + +# File extensions to process +EXTENSIONS = {'.cpp', '.h', '.hpp', '.c', '.js', '.rs'} + +# License template +LICENSE_TEMPLATE = """/* + * Ricochet - A minimalist CLI web browser for fast, distraction-free navigation. + * Copyright (C) 2026 Richard Qin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +""" + +# Identifier to check if license already exists +IDENTIFIER = "Ricochet - A minimalist CLI web browser" + +def add_license_to_file(file_path): + try: + with open(file_path, 'r', encoding='utf-8') as f: + content = f.read() + + if IDENTIFIER in content[:500]: + print(f"[-] Skip: {file_path} (License already exists)") + return + with open(file_path, 'w', encoding='utf-8') as f: + f.write(LICENSE_TEMPLATE + "\n" + content) + print(f"[+] Updated: {file_path}") + + except Exception as e: + print(f"[!] Error: Failed to process {file_path} -> {e}") + +def main(target_dir): + path = Path(target_dir) + if not path.exists(): + print(f"Error: Path {target_dir} does not exist") + return + + for file in path.rglob('*'): + if file.suffix in EXTENSIONS: + add_license_to_file(file) + +if __name__ == "__main__": + project_root = input("Please enter the project root directory (press Enter to use the current directory): ").strip() or "." + main(project_root) \ No newline at end of file -- cgit v1.2.3