Merge pull request #330 from matthiaskrgr/htmlreport_2

Htmlreport: minor cleanup, write index of errors (with links) under "Defect list" in menu for each page
This commit is contained in:
Daniel Marjamäki 2014-06-01 14:01:23 +02:00
commit da73627059
1 changed files with 37 additions and 18 deletions

View File

@ -48,9 +48,9 @@ body {
-webkit-box-sizing: content-box; -webkit-box-sizing: content-box;
-moz-box-sizing: content-box; -moz-box-sizing: content-box;
box-sizing: content-box; box-sizing: content-box;
margin: 30px; margin: 10px;
overflow: auto; overflow: auto;
padding: 5px 20px; padding: 5px 10px;
width: auto; width: auto;
} }
@ -62,24 +62,38 @@ body {
float: left; float: left;
margin-top: 5px; margin-top: 5px;
text-align: left; text-align: left;
width: 100px; width: 150px;
height: auto; height: 75%;
position: fixed;
overflow: auto;
z-index: 1;
} }
#menu > a { #menu > a {
display: block; display: block;
margin-left: 10px; margin-left: 10px;
font: 12px;
z-index: 1;
}
.highlighttable {
background-color:white;
z-index: 10;
position: relative;
margin: -10 px;
} }
#content { #content {
background-color: white;
-webkit-box-sizing: content-box; -webkit-box-sizing: content-box;
-moz-box-sizing: content-box; -moz-box-sizing: content-box;
box-sizing: content-box; box-sizing: content-box;
border-left: thin solid #aaa;
float: left; float: left;
margin: 5px; margin: 5px;
margin-left: 10px;
padding: 0 10px 10px 10px; padding: 0 10px 10px 10px;
width: 80%; width: 80%;
padding-left: 150px;
} }
.linenos { .linenos {
@ -108,17 +122,18 @@ HTML_HEAD = """
<meta charset="utf-8"> <meta charset="utf-8">
<title>Cppcheck - HTML report - %s</title> <title>Cppcheck - HTML report - %s</title>
<link rel="stylesheet" href="style.css"> <link rel="stylesheet" href="style.css">
<style>
%s
</style>
</head> </head>
<body> <body>
<div id="page"> <div id="page">
<div id="header"> <div id="header">
<h1>Cppcheck report - %s</h1> <h1>Cppcheck report - %s</h1>
</div> </div>
<div id="menu"> <div id="menu" dir="rtl">
<a href="index.html">Defect list</a> <a href="index.html">Defect list</a>
<br>
"""
HTML_HEAD_END = """
</div> </div>
<div id="content"> <div id="content">
""" """
@ -303,9 +318,12 @@ if __name__ == '__main__':
'w') as output_file: 'w') as output_file:
output_file.write(HTML_HEAD % output_file.write(HTML_HEAD %
(options.title, (options.title,
htmlFormatter.get_style_defs('.highlight'), #htmlFormatter.get_style_defs('.highlight'),
options.title)) options.title))
for error in errors:
output_file.write("<a href='%s#line-%d'> %s %s</a>" % (data['htmlfile'], error['line'], error['id'], error['line']))
output_file.write(HTML_HEAD_END)
lexer = guess_lexer_for_filename(source_filename, '') lexer = guess_lexer_for_filename(source_filename, '')
if options.source_encoding: if options.source_encoding:
lexer.encoding = options.source_encoding lexer.encoding = options.source_encoding
@ -323,13 +341,14 @@ if __name__ == '__main__':
print('Creating index.html') print('Creating index.html')
with io.open(os.path.join(options.report_dir, 'index.html'), with io.open(os.path.join(options.report_dir, 'index.html'),
'w') as output_file: 'w') as output_file:
output_file.write(HTML_HEAD % (options.title, '', options.title)) output_file.write(HTML_HEAD % (options.title, options.title))
output_file.write('<table>') output_file.write(HTML_HEAD_END)
output_file.write(' <table>\n')
output_file.write( output_file.write(
' <tr><th>Line</th><th>Id</th><th>Severity</th><th>Message</th></tr>') ' <tr><th>Line</th><th>Id</th><th>Severity</th><th>Message</th></tr>')
for filename, data in sorted(files.items()): for filename, data in sorted(files.items()):
output_file.write( output_file.write(
"<tr><td colspan='4'><a href='%s'>%s</a></td></tr>" % "\n <tr><td colspan='4'><a href='%s'>%s</a></td></tr>" %
(data['htmlfile'], filename)) (data['htmlfile'], filename))
for error in data['errors']: for error in data['errors']:
if error['severity'] == 'error': if error['severity'] == 'error':
@ -339,15 +358,15 @@ if __name__ == '__main__':
if error['id'] == 'missingInclude': if error['id'] == 'missingInclude':
output_file.write( output_file.write(
'<tr><td></td><td>%s</td><td>%s</td><td>%s</td></tr>' % '\n <tr><td></td><td>%s</td><td>%s</td><td>%s</td></tr>' %
(error['id'], error['severity'], error['msg'])) (error['id'], error['severity'], error['msg']))
else: else:
output_file.write( output_file.write(
"<tr><td><a href='%s#line-%d'>%d</a></td><td>%s</td><td>%s</td><td %s>%s</td></tr>" % "\n <tr><td><a href='%s#line-%d'>%d</a></td><td>%s</td><td>%s</td><td %s>%s</td></tr>" %
(data['htmlfile'], error['line'], error['line'], (data['htmlfile'], error['line'], error['line'],
error['id'], error['severity'], error_class, error['id'], error['severity'], error_class,
error['msg'])) error['msg']))
output_file.write('</table>') output_file.write('\n </table>')
output_file.write(HTML_FOOTER % contentHandler.versionCppcheck) output_file.write(HTML_FOOTER % contentHandler.versionCppcheck)
print('Creating style.css file') print('Creating style.css file')