From 465b6101837079880da3cba880bb291be12a1a68 Mon Sep 17 00:00:00 2001 From: Chih-Hung Hsieh Date: Wed, 22 Jun 2016 19:15:12 -0700 Subject: [PATCH] Add +/- buttons to expand/collapse warning categories. * Add expand/collapse-all buttons to expand/collapse all warnings. * Use HTML styles to reduce output file size. Change-Id: Ica188cc4f123ce0ab8547f88315325c3e0560a39 Test: Checked output html file with Chrome browser. --- tools/warn.py | 172 ++++++++++++++++++++++++++++---------------------- 1 file changed, 96 insertions(+), 76 deletions(-) diff --git a/tools/warn.py b/tools/warn.py index a4a9e16bb..b61505b6b 100755 --- a/tools/warn.py +++ b/tools/warn.py @@ -1683,8 +1683,41 @@ warnpatterns = [ ] anchor = 0 -cur_row_color = 0 -row_colors = [ 'e0e0e0', 'd0d0d0' ] +cur_row_class = 0 + +html_script_style = """\ + + \n""" + def output(text): print text, @@ -1693,39 +1726,23 @@ def htmlbig(param): return '' + param + '' def dumphtmlprologue(title): - output('\n\n' + title + '\n\n') + output('\n\n') + output('' + title + '\n') + output(html_script_style) + output('\n\n') output('') output(htmlbig(title)) output('

\n') +def dumphtmlepilogue(): + output('\n\n\n') + def tablerow(text): - global cur_row_color - output('',) - cur_row_color = 1 - cur_row_color - output(text,) - output('\n') - -def begintable(text, backgroundcolor, extraanchor): - global anchor - output('') - if extraanchor: - output('') - output('') - output('') - anchor += 1 - -def endtable(): - output('
') - output(htmlbig(text[0]) + '
') - for i in text[1:]: - output(i + '
') - output('
' + - 'top
' + - 'previous
' + - 'next') - output('

') - + global cur_row_class + output('') + cur_row_class = 1 - cur_row_class + output(text) + output('') # dump some stats about total number of warnings and such def dumpstats(): @@ -1743,38 +1760,33 @@ def dumpstats(): output('\nTotal number of warnings: ' + str(total) + '') if total < 1000: output('(low count may indicate incremental build)') - output('\n

\n') + output('

\n') + output(' ' + + '') + output('
\n') -# dump count of warnings of a given severity in TOC -def dumpcount(sev): - first = True - for i in warnpatterns: - if i['severity'] == sev and len(i['members']) > 0: - if first: - output(headerforseverity(sev) + ':\n

' + - '') - output('' + - '\n') - first = False - if not first: - output('
' + descriptionfor(i) + - ' (' + str(len(i['members'])) + ')
\n') - -# dump table of content, list of all warning patterns -def dumptoc(): - n = 1 +# dump everything for a given severity +def dumpseverity(sev): + global anchor + output('\n
' + + headerforseverity(sev) + ':\n') output('
\n') for i in warnpatterns: - i['anchor'] = 'Warning' + str(n) - n += 1 - dumpcount(severity.FIXMENOW) - dumpcount(severity.HIGH) - dumpcount(severity.MEDIUM) - dumpcount(severity.LOW) - dumpcount(severity.TIDY) - dumpcount(severity.HARMLESS) - dumpcount(severity.UNKNOWN) - output('
\n

\n') + if i['severity'] == sev and len(i['members']) > 0: + output('\n\n') + anchor += 1 + i['anchor'] = str(anchor) + mark = str(anchor) + '_mark' + output('' + + '\n') + output('
' + descriptionfor(i) + + ' (' + str(len(i['members'])) + ')
\n') + dumpcategory(i) + output('\n') def allpatterns(cat): pats = '' @@ -1791,15 +1803,28 @@ def descriptionfor(cat): # show which warnings no longer occur def dumpfixed(): - tablestarted = False + global anchor + anchor += 1 + mark = str(anchor) + '_mark' + output('\n

' + + ' Fixed warnings. ' + + 'No more occurences. Please consider turning these into ' + + 'errors if possible, before they are reintroduced in to the build' + + ':

\n') + output('
\n') + fixed_patterns = [] for i in warnpatterns: if len(i['members']) == 0 and i['severity'] != severity.SKIP: - if tablestarted == False: - tablestarted = True - begintable(['Fixed warnings', 'No more occurences. Please consider turning these in to errors if possible, before they are reintroduced in to the build'], 'blue', '') - tablerow(i['description'] + ' (' + allpatterns(i) + ') ' + i['option']) - if tablestarted: - endtable() + fixed_patterns.append(i['description'] + ' (' + + allpatterns(i) + ') ' + i['option']) + fixed_patterns.sort() + output('\n') + output('
\n') def warningwithurl(line): if not args.url: @@ -1821,17 +1846,12 @@ def dumpcategory(cat): header = [descriptionfor(cat),str(len(cat['members'])) + ' occurences:'] if cat['option'] != '': header[1:1] = [' (related option: ' + cat['option'] +')'] - begintable(header, colorforseverity(cat['severity']), cat['anchor']) + + output('\n') def classifywarning(line): @@ -1895,7 +1915,6 @@ dumpstats() # sort table based on number of members once dumpstats has deduplicated the # members. warnpatterns.sort(reverse=True, key=lambda i: len(i['members'])) -dumptoc() dumpseverity(severity.FIXMENOW) dumpseverity(severity.HIGH) dumpseverity(severity.MEDIUM) @@ -1904,3 +1923,4 @@ dumpseverity(severity.TIDY) dumpseverity(severity.HARMLESS) dumpseverity(severity.UNKNOWN) dumpfixed() +dumphtmlepilogue()