Skip to content

Commit

Permalink
Merge pull request #4922 from NREL/labs_cli_remove_verbose
Browse files Browse the repository at this point in the history
Labs cli remove verbose in favor of `--loglevel `+ minor swig adjustments
  • Loading branch information
jmarrec authored Jul 4, 2023
2 parents 470e0ef + f1e0dec commit 79e9fe3
Show file tree
Hide file tree
Showing 30 changed files with 1,017 additions and 1,167 deletions.
79 changes: 38 additions & 41 deletions ci/colorize_cppcheck_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@

def colorize(lines):
def bold(s):
return '\x1b[1m{}\x1b[0m'.format(s)
return "\x1b[1m{}\x1b[0m".format(s)

def red(s):
return '\x1b[31m{}\x1b[0m'.format(s)
return "\x1b[31m{}\x1b[0m".format(s)

def green(s):
return '\x1b[32m{}\x1b[0m'.format(s)
return "\x1b[32m{}\x1b[0m".format(s)

def yellow(s):
return '\x1b[33m{}\x1b[0m'.format(s)
return "\x1b[33m{}\x1b[0m".format(s)

def blue(s):
return '\x1b[34m{}\x1b[0m'.format(s)
return "\x1b[34m{}\x1b[0m".format(s)

def magenta(s): # purple
return '\x1b[35m{}\x1b[0m'.format(s)
return "\x1b[35m{}\x1b[0m".format(s)

def cyan(s):
return '\x1b[36m{}\x1b[0m'.format(s)
return "\x1b[36m{}\x1b[0m".format(s)

def format_severity(txt, severity):
"""
Expand All @@ -37,7 +37,7 @@ def format_severity(txt, severity):
return red(txt)
if severity == "warning":
return yellow(txt)
if severity == 'style':
if severity == "style":
return blue(txt)
if severity == "performance":
return cyan(txt)
Expand All @@ -50,9 +50,9 @@ def format_severity(txt, severity):

return txt

re_message = re.compile(r'\[(?P<file>.*):(?P<line>.*?)\]:'
r'\((?P<severity>.*?)\),\[(?P<id>.*?)\],'
r'(?P<message>.*)')
re_message = re.compile(
r"\[(?P<file>.*):(?P<line>.*?)\]:" r"\((?P<severity>.*?)\),\[(?P<id>.*?)\]," r"(?P<message>.*)"
)

colored_lines = []
matched_messages = []
Expand All @@ -68,10 +68,9 @@ def format_severity(txt, severity):
else:
colored_lines.append(red(line))

severity_order = ['error', 'warning', 'performance', 'portability',
'style', 'information', 'debug', 'none']
severity_order = ["error", "warning", "performance", "portability", "style", "information", "debug", "none"]

counter = Counter(d['severity'] for d in matched_messages)
counter = Counter(d["severity"] for d in matched_messages)
summary_line = "\n\n==========================================\n"
summary_line += " {}:\n".format(bold(red("CPPCHECK Summary")))
summary_line += "------------------------------------------"
Expand All @@ -88,61 +87,59 @@ def format_severity(txt, severity):

summary_line += "\n==========================================\n\n"

n_errors = counter['error']
n_errors = counter["error"]
# if n_errors:
# summary_line += red("{} Errors".format(n_errors))
# else:
# summary_line = green("No Errors")

n_warnings = counter['warning']
n_warnings = counter["warning"]
# if n_warnings:
# summary_line += yellow("{} Warnings".format(n_warnings))
# else:
# summary_line = green("No Warnings")

n_styles = counter['style']
n_performances = counter['performance']
n_portabilities = counter['portability']
n_styles = counter["style"]
n_performances = counter["performance"]
n_portabilities = counter["portability"]
# n_informations = counter['information']

# n_debugs = counter['debug']

# Start by sorting by filename
matched_messages.sort(key=lambda d: d['file'])
matched_messages.sort(key=lambda d: severity_order.index(d['severity']))
matched_messages.sort(key=lambda d: d["file"])
matched_messages.sort(key=lambda d: severity_order.index(d["severity"]))

# Now sort by the severity we cared about
for d in matched_messages:

f = d['file']
line = d['line']
severity = d['severity']
iid = d['id']
message = d['message']
f = d["file"]
line = d["line"]
severity = d["severity"]
iid = d["id"]
message = d["message"]

colored_lines.append(
"[{f}:{line}]:({severity}),[{i}],{message}"
.format(f=magenta(f), # format_severity(f, severity),
line=green(line),
severity=format_severity(severity, severity),
i=bold(iid),
message=message))
"[{f}:{line}]:({severity}),[{i}],{message}".format(
f=magenta(f), # format_severity(f, severity),
line=green(line),
severity=format_severity(severity, severity),
i=bold(iid),
message=message,
)
)

return (colored_lines, summary_line, n_errors, n_warnings,
n_performances, n_portabilities, n_styles)
return (colored_lines, summary_line, n_errors, n_warnings, n_performances, n_portabilities, n_styles)


if __name__ == '__main__':
with open('cppcheck.txt', 'r') as f:
if __name__ == "__main__":
with open("cppcheck.txt", "r") as f:
content = f.read()

lines = content.splitlines()
(colored_lines, summary_line, n_errors, n_warnings,
n_performances, n_portabilities, n_styles) = colorize(lines)
(colored_lines, summary_line, n_errors, n_warnings, n_performances, n_portabilities, n_styles) = colorize(lines)
print(summary_line)
# sys.stdout.writelines(colored_lines)
print("\n".join(colored_lines))
n_tot = (n_errors + n_warnings + n_performances
+ n_portabilities + n_styles)
n_tot = n_errors + n_warnings + n_performances + n_portabilities + n_styles
if n_tot > 0:
exit(1)
Loading

0 comments on commit 79e9fe3

Please sign in to comment.