diff options
| author | Richard Qin <richard.qin.x@gmail.com> | 2026-04-11 02:57:24 +0800 |
|---|---|---|
| committer | Richard Qin <richard.qin.x@gmail.com> | 2026-04-11 02:57:24 +0800 |
| commit | 085bdfaee339d471fd8d49c0b349995d69bf3565 (patch) | |
| tree | ad7fd4758849590e176de278e952147dea229e36 | |
| parent | 614dcb875411fcca63f9b8de50256c8b53889355 (diff) | |
| download | rwebbrowser-085bdfaee339d471fd8d49c0b349995d69bf3565.tar.gz rwebbrowser-085bdfaee339d471fd8d49c0b349995d69bf3565.tar.xz | |
feat: add license header automation script
| -rw-r--r-- | scripts/add_license.py | 57 |
1 files changed, 57 insertions, 0 deletions
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 <https://www.gnu.org/licenses/>. + */ +""" + +# 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 |
