allowed BLOCK result for testkit-merger
[test/tools/testkit-lite.git] / testkit-merge
1 #!/usr/bin/python
2 #
3 # Copyright (C) 2014 Intel Corporation
4 #
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 #
19 # Authors: 
20 #           Nicolas Zingile <n.zingile@gmail.com>
21
22 import argparse
23 from testkitmerge.merger import *
24
25 def main():
26     argparser = argparse.ArgumentParser(description='Tool to merge testkit result xml files')
27     argparser.add_argument('-f', '--files', help='list of testkit xml result files', nargs='+')
28     argparser.add_argument('-o', '--outdir',  help='output directory of final result file', required=True)
29     argparser.add_argument('-n', '--name', help ='name of the final result file', default='result.xml')
30     args = argparser.parse_args()
31     print args
32
33     parser = etree.XMLParser(strip_cdata=False)
34     sourcexmltree = None
35     resultxmltree = None
36
37     for resultxml in args.files:
38         if not os.path.isfile(resultxml):
39             print "Error: the file '" + resultxml + "'doesn't exist !"
40             exit(1)
41         if not resultxml.endswith('.xml'):
42             print "Error: '" + resultxml + "' is not an xml file !"
43             exit(1)
44     for index in range(len(args.files)):
45         sourcexmltree =  etree.parse(args.files[index], parser)
46         resultxmltree = merge_testkitxml(sourcexmltree, resultxmltree)
47         
48     resultxmltree.write(os.path.join(args.outdir, args.name), pretty_print=True, encoding='utf8', method='xml', xml_declaration=True)
49
50 if __name__ == "__main__":
51     main()