-
Notifications
You must be signed in to change notification settings - Fork 58
/
add_license_header.py
36 lines (30 loc) · 1.1 KB
/
add_license_header.py
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
# Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#
# Licensed under the NVIDIA Source Code License [see LICENSE for details].
"""
Adds license header to new files that don't have the license header.
"""
import os
LICENSE_TEXT = """# Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#
# Licensed under the NVIDIA Source Code License [see LICENSE for details].
"""
def check_license_exists(filename):
with open(filename, 'r') as f:
lines_to_check = LICENSE_TEXT.strip().split('\n')
for line in lines_to_check:
file_line = f.readline().strip()
if file_line != line:
return False
return True
def add_license_header(filename):
if not check_license_exists(filename):
with open(filename, 'r+') as f:
content = f.read()
f.seek(0, 0)
f.write(LICENSE_TEXT + '\n' + content)
if __name__ == "__main__":
for root, dirs, files in os.walk('.'):
for file in files:
if file.endswith('.py'):
add_license_header(os.path.join(root, file))