-
Notifications
You must be signed in to change notification settings - Fork 0
/
removeSkipXmls.py
36 lines (35 loc) · 1.21 KB
/
removeSkipXmls.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
from xml.dom import minidom
import sys,os
# Removes the skipped annotations in the given folder
def skipXmls(xmlfolder,outFile=None):
xmlFormat = ".xml"
count = 0
files=[]
if os.path.exists(outFile):
os.remove(outFile)
for xml in os.listdir(xmlfolder):
if xml.find(xmlFormat) == -1:
continue
doc = minidom.parse(xmlfolder+"/"+xml)
doSkip = False
objects = doc.getElementsByTagName("object")
fname = doc.getElementsByTagName("filename")[0]
for one_object in objects:
name = one_object.getElementsByTagName("name")[0]
if name.firstChild.data == "skipped":
doSkip = True
break
if doSkip == True:
count+=1
continue
if outFile!=None:
with open(outFile, 'a') as f3:
f3.write(os.path.splitext(fname.firstChild.data)[0] + os.linesep)
files.append(os.path.splitext(fname.firstChild.data)[0])
print('%d files are skipped'%count)
print('files are written at %s'%str(outFile))
return (files,count)
if __name__=='__main__':
xmlFolder = sys.argv[1]
outFile=sys.argv[2]
f,c=skipXmls(xmlFolder,outFile)