Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Apache license headers with SPDX ID #5808

Merged
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions scripts/update_license_headers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env python3
import re
import sys

def update_license_header(file_path):
with open(file_path, 'r') as file:
content = file.read()

apache_header_pattern = re.compile(
r'(/\*|#|//)\s*Licensed under the Apache License, Version 2\.0.*?'
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved
r'limitations under the License\.',
re.DOTALL
)
spdx_header = "// SPDX-License-Identifier: Apache-2.0\n"

if content.startswith(spdx_header):
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved
print(f"Skipping {file_path}: SPDX header already present")
return False

new_content, count = apache_header_pattern.subn(spdx_header, content, count=1)

if count > 0:
with open(file_path, 'w') as file:
file.write(new_content)
print(f"Updated {file_path}")
return True
else:
print(f"Skipping {file_path}: No Apache header found")
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved
return False

def main():
if len(sys.argv) < 2:
print("Usage: python update_license_headers.py <file> [<file> ...]")
sys.exit(1)

total_updated = sum(update_license_header(file) for file in sys.argv[1:])
print(f"Total files updated: {total_updated}")

if __name__ == "__main__":
main()
Loading