-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppendATextInHeaders.py
More file actions
26 lines (23 loc) · 1.28 KB
/
Copy pathAppendATextInHeaders.py
File metadata and controls
26 lines (23 loc) · 1.28 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
#Prerequisite: Dump the list of headers that you want to modify in a text file
#Working directory for this script should be your source code's root directory
#I wanted to append Microsoft's banned.h in every header of our source code
#I had to append the #include at the end of the file and I wrote this script to save time.
#ToDo:Break the platform specific ifs into separate functions or find a way to reduce duplication!
import os
headerList = open("headersToModify.txt","w")
for root,dirs,files in os.walk("."):
for file in files:
if file.endswith(".h") or file.endswith(".hh") :
if os.name == "nt":
#headerList.write(os.path.join(root,file+"\n"))
headerList.write(root+"\\"+file+"\n")
os.chmod(root+"\\"+file, 511)
writefile = open(root+"\\"+file, "a")
writefile.write("\n#ifndef _INC_BANNED \n#include \"banned.h\"\n#endif\n")
writefile.close()
if os.name == "posix":
headerList.write(root+"/"+file+"\n")
os.chmod(root+"/"+file, 511)
writefile = open(root+"/"+file, "a")
writefile.write("\n#ifndef _INC_BANNED \n#include \"banned.h\"\n#endif\n")
writefile.close()