-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_page_footer.py
74 lines (54 loc) · 1.95 KB
/
update_page_footer.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import os
import utils
import codecs
def update_file_footer(file_path):
code, file_content = utils.read_file_content(file_path)
if not code:
return False, "Read file error, " + str(file_content)
if file_content[0:3] == codecs.BOM_UTF8:
file_content = file_content[3:]
if file_content[0:3] == b'\xc3\xaf\xc2\xbb\xc2\xbf'.decode():
file_content = file_content[3:]
while file_content.startswith("\n"):
file_content = file_content[1:]
if file_content.startswith("<html"):
error = False
if file_content.find("<body") != -1:
if file_content.find("</body>") == -1:
error = True
elif file_content.find("<BODY") != -1:
error = True
else:
error = True
if error:
print(file_path)
print(file_content[0:10].encode())
else:
print(file_path)
print(file_content[0:10].encode())
return False, "Found error"
return True, True
def update_all_footer():
count = 0
for root, _, f_names in os.walk("."):
for file in f_names:
if "root" == "./.git":
continue
full_path = os.path.join(root, file)
base_name = file
if not base_name.endswith(".html"):
continue
code, result = update_file_footer(full_path)
if not code:
print("update_file_footer error, %s - %s" % (full_path, str(result)))
return False, False
count += 1
# if count >= 2:
# return True, False
return True, True
def start():
update_all_footer()
return True, True
if __name__ == "__main__":
code, result = start()
print(code, result)