-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_copyright_headers.py
More file actions
74 lines (63 loc) · 2.31 KB
/
Copy pathcheck_copyright_headers.py
File metadata and controls
74 lines (63 loc) · 2.31 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
#!/usr/bin/env python3
import os
import re
from pathlib import Path
def check_copyright_headers():
"""Check for missing copyright headers in C# files"""
root_dir = Path('.')
# Pattern to match University of Dundee copyright header
dundee_pattern = r'// Copyright \(c\) The University of Dundee \d{4}(-\d{4})?'
# Files to ignore
ignore_patterns = [
'.Designer.cs',
'Program.cs',
'Settings.Designer.cs',
'Class1.cs',
'Images.Designer.cs',
'ToolTips.Designer.cs',
'Resources.Designer.cs',
'ProjectInstaller.cs',
'ProjectInstaller.Designer.cs',
'TableView.cs',
'TreeView.cs'
]
issues = []
for cs_file in root_dir.rglob('*.cs'):
# Skip ignored files
if any(pattern in cs_file.name for pattern in ignore_patterns):
continue
# Skip git and build directories
if '.git' in str(cs_file) or 'obj' in str(cs_file) or 'bin' in str(cs_file):
continue
# Skip if it's auto-generated
try:
with open(cs_file, 'r', encoding='utf-8') as f:
first_line = f.readline().strip()
if first_line == '// <autogenerated />':
continue
except:
continue
# Check if file has proper copyright header
try:
with open(cs_file, 'r', encoding='utf-8') as f:
content = f.read(500) # Read first 500 characters
if not re.search(dundee_pattern, content):
issues.append(f"Missing/correct copyright header: {cs_file}")
# Check what copyright it does have
if 'Copyright' in content:
lines = content.split('\n')[:10]
for line in lines:
if 'Copyright' in line:
issues.append(f" Has: {line.strip()}")
break
except Exception as e:
issues.append(f"Could not read {cs_file}: {e}")
return issues
if __name__ == '__main__':
issues = check_copyright_headers()
if issues:
print(f"Found {len(issues)} copyright issues:")
for issue in issues:
print(issue)
else:
print("No copyright header issues found")