-
Notifications
You must be signed in to change notification settings - Fork 0
/
Test.py
46 lines (35 loc) · 1.52 KB
/
Test.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
44
45
46
#!/usr/bin/env python3
from shutil import copyfile, move
import os
import glob
def main():
BasePath = './'
Files = glob.glob(BasePath + '*.html')
CopyFileName = 'CopyFrom.html' # 'CopyFromFooter.html' 'CopyFrom.html'
Keyword = 'EDIT ME' # 'EDIT FOOT' 'EDIT ME'
for FileName in Files:
print(FileName)
if('Edit' in FileName or FileName == CopyFileName):
continue
else:
# FileName = 'indexTest.html'
if(not (os.path.isdir(BasePath +'Bak/'))):
os.makedirs(BasePath + 'Bak/')
copyfile(BasePath + FileName, BasePath + 'Bak/'+FileName+'.bak')
with open(BasePath + FileName, 'r') as f1, open(BasePath +'Edit'+FileName.split(BasePath)[-1], 'w') as f2:
WriteFlag = True
for Line in f1.readlines():
if(Keyword in Line):
f2.write(Line)
Tabs = Line.split('<!-- ' + Keyword + ' -->')[0]
if(WriteFlag):
with open(BasePath + CopyFileName, 'r') as f3:
for CopyLine in f3.readlines():
f2.write(Tabs + '\t' + CopyLine)
WriteFlag = not WriteFlag
if(WriteFlag and not (Keyword in Line)):
f2.write(Line)
# Replace original file
move(BasePath +'Edit'+FileName.split(BasePath)[-1], BasePath + FileName)
if __name__=='__main__':
main()