Skip to content

Commit

Permalink
Merge pull request #1328 from csordasmarton/cmd-sum-total
Browse files Browse the repository at this point in the history
Add total section for command line sum
  • Loading branch information
gyorb authored Jan 30, 2018
2 parents ddbd6a4 + da57f4d commit 5c36828
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
24 changes: 22 additions & 2 deletions libcodechecker/cmd/cmd_line_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,13 +637,16 @@ def checker_count(checker_dict, key):
report_filter.isUnique = True
sev_count = client.getSeverityCounts(run_ids, report_filter, None)
severities = []
severity_total = 0
for key, count in sorted(sev_count.items(),
reverse=True):
severities.append(dict(
severity=ttypes.Severity._VALUES_TO_NAMES[key],
reports=count))
severity_total += count

all_results = []
total = defaultdict(int)
for key, checker_data in sorted(all_checkers_dict.items(),
key=lambda x: x[1].severity,
reverse=True):
Expand All @@ -657,6 +660,12 @@ def checker_count(checker_dict, key):
intentional=checker_count(intentional_checkers, key),
resolved=checker_count(resolved_checkers, key),
))
total['total_reports'] += checker_data.count
total['total_resolved'] += checker_count(resolved_checkers, key)
total['total_unreviewed'] += checker_count(unrev_checkers, key)
total['total_confirmed'] += checker_count(confirmed_checkers, key)
total['total_false_positive'] += checker_count(false_checkers, key)
total['total_intentional'] += checker_count(intentional_checkers, key)

if args.output_format == 'json':
print(CmdLineOutputEncoder().encode(all_results))
Expand All @@ -676,7 +685,15 @@ def checker_count(checker_dict, key):
str(stat['false_positive']),
str(stat['intentional'])))

print(twodim_to_str(args.output_format, header, rows))
rows.append(('Total', '-', str(total['total_reports']),
str(total['total_resolved']),
str(total['total_unreviewed']),
str(total['total_confirmed']),
str(total['total_false_positive']),
str(total['total_intentional'])))

print(twodim_to_str(args.output_format, header, rows,
separate_footer=True))

# Print severity counts
header = ['Severity', 'All reports']
Expand All @@ -686,7 +703,10 @@ def checker_count(checker_dict, key):
rows.append((stat['severity'],
str(stat['reports'])))

print(twodim_to_str(args.output_format, header, rows))
rows.append(('Total', str(severity_total)))

print(twodim_to_str(args.output_format, header, rows,
separate_footer=True))


def handle_remove_run_results(args):
Expand Down
10 changes: 7 additions & 3 deletions libcodechecker/output_formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@


def twodim_to_str(format_name, keys, rows,
sort_by_column_number=None, rev=False):
sort_by_column_number=None, rev=False,
separate_footer=False):
"""
Converts the given two-dimensional array (with the specified keys)
to the given format.
Expand All @@ -32,7 +33,7 @@ def twodim_to_str(format_name, keys, rows,
return twodim_to_rows(rows)
elif format_name == 'table' or format_name == 'plaintext':
# TODO: 'plaintext' for now to support the 'CodeChecker cmd' interface.
return twodim_to_table(all_rows)
return twodim_to_table(all_rows, True, separate_footer)
elif format_name == 'csv':
return twodim_to_csv(all_rows)
elif format_name == 'dictlist':
Expand Down Expand Up @@ -81,7 +82,7 @@ def twodim_to_rows(lines):
return '\n'.join(str_parts)


def twodim_to_table(lines, separate_head=True):
def twodim_to_table(lines, separate_head=True, separate_footer=False):
"""
Pretty-prints the given two-dimensional array's lines.
"""
Expand Down Expand Up @@ -115,6 +116,9 @@ def twodim_to_table(lines, separate_head=True):
"columns than the others")
if i == 0 and separate_head:
str_parts.append("-" * (sum(widths) + 3 * (len(widths) - 1)))
if separate_footer and i == len(lines) - 2:
str_parts.append("-" * (sum(widths) + 3 * (len(widths) - 1)))

str_parts.append("-" * (sum(widths) + 3 * (len(widths) - 1)))

return '\n'.join(str_parts)
Expand Down

0 comments on commit 5c36828

Please sign in to comment.