1+ def add_copyright ():
2+
3+ import os
4+ import sys
5+
6+ project = str (sys .argv [1 ])
7+ file_type = str (sys .argv [2 ])
8+ print (project )
9+ print (file_type )
10+
11+ # Create an array of paths mirroring structure of current directory
12+ # while ignoring this script and problematic file types
13+ paths = []
14+ for (root , dirs , files ) in os .walk ('.' , topdown = True ):
15+ for f in files :
16+ if f == 'add-copyright.py' :
17+ continue
18+ elif '.data' in f :
19+ continue
20+ elif '.png' in f :
21+ continue
22+ elif '.jar' in f :
23+ continue
24+ elif '.' not in f :
25+ continue
26+ elif '.pack' in f :
27+ continue
28+ elif '.idx' in f :
29+ continue
30+ else :
31+ path = os .path .join (root , f )
32+ paths .append (path )
33+ # print(paths)
34+
35+ # Iterate through file paths, adding a copyright line to each file
36+ for p in paths :
37+ if '.circleci' in p :
38+ continue
39+ elif '.github' in p :
40+ continue
41+ elif '.gitignore' in p :
42+ continue
43+ else :
44+ if file_type == 'java' :
45+ if p [- 4 :] == 'java' :
46+ with open (p , 'r' ) as t :
47+ contents = t .readlines ()
48+ line = f'/* Copyright 2018-2022 contributors to the { project } project */\n \n '
49+ contents .insert (0 , line )
50+ with open (p , 'w' ) as t :
51+ contents = '' .join (contents )
52+ t .write (contents )
53+ elif file_type == 'py' :
54+ if p [- 2 :] == 'py' :
55+ with open (p , 'r' ) as t :
56+ contents = t .readlines ()
57+ line = f'# Copyright 2018-2022 contributors to the { project } project\n \n '
58+ contents .insert (0 , line )
59+ with open (p , 'w' ) as t :
60+ contents = '' .join (contents )
61+ t .write (contents )
62+ elif file_type == 'md' :
63+ if p [- 2 :] == 'md' :
64+ with open (p , 'r' ) as t :
65+ contents = t .readlines ()
66+ line = f'<!-- Copyright 2018-2022 contributors to the { project } project -->\n \n '
67+ contents .insert (0 , line )
68+ with open (p , 'w' ) as t :
69+ contents = '' .join (contents )
70+ t .write (contents )
71+ elif file_type == 'html' :
72+ if p [- 2 :] == 'html' :
73+ with open (p , 'r' ) as t :
74+ contents = t .readlines ()
75+ line = f'<!-- Copyright 2018-2022 contributors to the { project } project -->\n \n '
76+ contents .insert (0 , line )
77+ with open (p , 'w' ) as t :
78+ contents = '' .join (contents )
79+ t .write (contents )
80+ elif file_type == 'txt' :
81+ if p [- 3 :] == 'txt' :
82+ with open (p , 'r' ) as t :
83+ contents = t .readlines ()
84+ line = f'Copyright 2018-2022 contributors to the { project } project\n \n '
85+ contents .insert (0 , line )
86+ with open (p , 'w' ) as t :
87+ contents = '' .join (contents )
88+ t .write (contents )
89+ elif file_type == 'rs' :
90+ if p [- 2 :] == 'rs' :
91+ with open (p , 'r' ) as t :
92+ contents = t .readlines ()
93+ line = f'// Copyright 2018-2022 contributors to the { project } project\n \n '
94+ contents .insert (0 , line )
95+ with open (p , 'w' ) as t :
96+ contents = '' .join (contents )
97+ t .write (contents )
98+ elif file_type == 'sh' :
99+ if p [- 2 :] == 'sh' :
100+ with open (p , 'a' ) as t :
101+ line = f'\n # Copyright 2018-2022 contributors to the { project } project'
102+ t .write (line )
103+ elif file_type == 'ts' :
104+ if p [- 2 :] == 'ts' :
105+ with open (p , 'r' ) as t :
106+ contents = t .readlines ()
107+ line = f'// Copyright 2018-2022 contributors to the { project } project\n \n '
108+ contents .insert (0 , line )
109+ with open (p , 'w' ) as t :
110+ contents = '' .join (contents )
111+ t .write (contents )
112+
113+ add_copyright ()
0 commit comments