-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathadd_header.py
43 lines (32 loc) · 1.19 KB
/
add_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
37
38
39
40
41
42
43
import os
import datetime
with open("header.text") as inf:
header = inf.read()
for directory in os.listdir():
if os.path.isdir(directory) and directory[0].isdigit():
for file in os.listdir(directory) :
#cpp
if file.endswith(".cpp") or file.endswith(".h"):
full_file = os.path.join(directory, file)
with open(full_file) as inf:
first_line = inf.readline()
if not first_line.startswith("//"):
with open(full_file) as inf:
text = inf.read()
year = datetime.datetime.now().year
text = header%(year, file) + "\n" + text
with open(full_file, 'w') as outf:
outf.write(text)
#python
if file.endswith(".py"):
header = header.replace("//", "#")
full_file = os.path.join(directory, file)
with open(full_file) as inf:
first_line = inf.readline()
if not first_line.startswith("#"):
with open(full_file) as inf:
text = inf.read()
year = datetime.datetime.now().year
text = header%(year, file) + "\n" + text
with open(full_file, 'w') as outf:
outf.write(text)