Skip to content

Commit

Permalink
Merge coverage files at once
Browse files Browse the repository at this point in the history
Avoid writing intermediate files for every merge and parsing them back.
We can use one xml tree and merge all of them into it at once.

Signed-off-by: Michal Čihař <michal@cihar.com>
  • Loading branch information
nijel committed Aug 24, 2016
1 parent 3b1c479 commit cd55036
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions admin/merge-windows-coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
# https://github.com/x3mSpeedy/Flow123d-python-utils/blob/master/src/coverage/coverage_merge_module.py


import sys
import xml.etree.cElementTree as ET
import re
import glob

# constants
Expand All @@ -27,20 +25,18 @@ def __init__(self, filename, xmlfiles):
self.filtersuffix = ''

def execute_merge(self):
# merge all given files
totalfiles = len(self.xmlfiles)
# parse first one
basexml = ET.parse(self.xmlfiles[0])

self.merge_xml(self.xmlfiles[0], self.xmlfiles[1], self.finalxml)
# merge others
for i in range(len(self.xmlfiles) - 1):
addxml = ET.parse(self.xmlfiles[i + 1])
self.merge_xml(basexml, addxml)

for i in range(totalfiles - 2):
xmlfile = self.xmlfiles[i + 2]
self.merge_xml(self.finalxml, xmlfile, self.finalxml)

def merge_xml(self, xmlfile1, xmlfile2, outputfile):
# parse
xml1 = ET.parse(xmlfile1)
xml2 = ET.parse(xmlfile2)
# write result to output file
basexml.write(self.finalxml, encoding="UTF-8", xml_declaration=True)

def merge_xml(self, xml1, xml2):
# get packages
packages1 = self.filter_xml(xml1)
packages2 = self.filter_xml(xml2)
Expand All @@ -57,9 +53,6 @@ def merge_xml(self, xmlfile1, xmlfile2, outputfile):
self.merge_packages
)

# write result to output file
xml1.write(outputfile, encoding="UTF-8", xml_declaration=True)

def filter_xml(self, xmlfile):
xmlroot = xmlfile.getroot()
return xmlroot.findall(PACKAGES_LIST)
Expand Down

0 comments on commit cd55036

Please sign in to comment.