-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_copyright.py
More file actions
80 lines (62 loc) · 2.59 KB
/
add_copyright.py
File metadata and controls
80 lines (62 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env python3
"""
Copyright Header Tool for Astro-AI Platform
Adds copyright notices to all Python files in the project.
"""
import os
import glob
from pathlib import Path
COPYRIGHT_HEADER = '''"""
Astro-AI: Galaxy Evolution Analysis Platform
Copyright (c) 2025 Redwan Rahman and CAM-SUST
All rights reserved. Licensed under the Astro-AI Proprietary License.
See LICENSE file for full terms and conditions.
Contact: redwanrahman2002@outlook.com
"""
'''
def add_copyright_header(file_path):
"""Add copyright header to a Python file if not already present."""
try:
with open(file_path, 'r', encoding='utf-8') as f:
content = f.read()
# Skip if copyright already exists
if 'Copyright (c) 2025 Redwan Rahman and CAM-SUST' in content:
print(f"Copyright already exists in {file_path}")
return
# Skip if file starts with shebang
if content.startswith('#!'):
lines = content.split('\n')
# Find the first non-shebang, non-comment line
insert_pos = 0
for i, line in enumerate(lines):
if not line.startswith('#') and line.strip():
insert_pos = i
break
# Insert copyright after shebang and initial comments
lines.insert(insert_pos, COPYRIGHT_HEADER.rstrip())
new_content = '\n'.join(lines)
else:
# Add copyright at the beginning
new_content = COPYRIGHT_HEADER + content
# Write the updated content
with open(file_path, 'w', encoding='utf-8') as f:
f.write(new_content)
print(f"Added copyright header to {file_path}")
except Exception as e:
print(f"Error processing {file_path}: {e}")
def main():
"""Add copyright headers to all Python files in the project."""
project_root = Path(__file__).parent
python_files = glob.glob(str(project_root / "**/*.py"), recursive=True)
# Skip this script itself and __pycache__ files
python_files = [f for f in python_files if
not f.endswith('add_copyright.py') and
'__pycache__' not in f]
print(f"Found {len(python_files)} Python files to process...")
for file_path in python_files:
add_copyright_header(file_path)
print("\nCopyright header addition complete!")
print("\nIMPORTANT: Review all files before committing to ensure")
print("copyright headers are properly placed and don't break functionality.")
if __name__ == "__main__":
main()