-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathguize.py
124 lines (90 loc) · 2.83 KB
/
guize.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/python
#check the xml syntax
import re
import sys
import os
fdout = open("results.txt","w")
def findfieldCount(line):
fieldCount = re.match(r"""<entry key=.*fieldCount">(\d*)</entry>""", line)
return fieldCount
def checkfield(count,line):
rematch = r"""<entry key=.*field\[%s\]">.*</entry>""" % count
original = re.match(rematch, line)
return original
def checkfieldvalue(count,line):
rematch = r"""<entry key=.*field\[%s\]\..+">.*</entry>""" % count
original = re.match(rematch, line)
return original
def check(linenum, xmllist):
count = 0
while True:
if len(xmllist[linenum]) <= 2:
return count
break
if checkfield(count,xmllist[linenum]) == None:
print linenum ,'line has a wrong field number'
fdout.write(str(linenum)+'line has a wrong field number'+"\n")
return count
break
else:
linenum = linenum + 1
while True:
if checkfieldvalue(count,xmllist[linenum]) == None:
count = count + 1
break
else:
linenum = linenum + 1
continue
# filename = sys.argv[1]
# xml = open(filename)
# xmllist = list(xml)
# print xmllist[20]
# print len(xmllist[2])
# print xmllist[2]
# print len(xmllist)
def final_check(filename):
# if filename.endswith('xml'):
xml = open(filename)
xmllist = list(xml)
# i = 0
# else
i = 0
fdout.write(filename+"\n")
print filename
while True:
if i == len(xmllist):
# print xmllist
print "check complete"
break
line = xmllist[i]
if findfieldCount(line) == None:
i = i + 1
continue
else:
count = findfieldCount(line).group(1)
i = i + 1
if int(check(i, xmllist)) != int(count):
print i,"line has a wrong field count"
fdout.write(str(i)+"line has a wrong field count"+"\n")
# print count,check(i,xmllist)
def main():
pre_pwd = os.getcwd()
file_list = os.listdir(pre_pwd)
# print file_list
for file_each in file_list:
if file_each.endswith('xml'):
final_check(file_each)
# else:
# pass
if __name__ == '__main__':
main()
# while true:
# # test = open('test.xml')
# # line = test.readline()
# # findfieldCount(line)
# # findfieldCount("""<entry key="mapper[2].fieldCount">17</entry>""")
# xml = open('map.xml')
# xmllist = list(xml)
# for line in xmllist:
# print line
# xml.close()