Created
February 22, 2018 10:23
-
-
Save rpuntaie/caa77f718c6e5109cdd584029f0db43f to your computer and use it in GitHub Desktop.
python function to convert the xml file generated by CppCheck into a text table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def cppcheck2tbl(filename): | |
""" | |
Takes the xml file generated by CppCheck | |
and converts it to a text table. | |
""" | |
import xml.etree.ElementTree as ET | |
import csv | |
import html | |
tree = ET.parse(filename) | |
root = tree.getroot() | |
def errors(root): | |
for err in root.findall('errors/error'): | |
loc = err.find('location') | |
yield [html.unescape(err.attrib[x]) for x in 'id severity msg'.split()]+[loc.attrib['file'],loc.attrib['line']] | |
tbl = '\n'.join(['\t\t'.join(x) for x in errors(root)]) | |
del tree | |
return tbl |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment