You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
proxysql/scripts/lint/normalize-cppcheck.py

27 lines
651 B

#!/usr/bin/env python3
import sys
import re
import os
"""
Normalize cppcheck stderr output. Produce lines like:
<file>:<line>: <id> - <message>
"""
path = sys.argv[1] if len(sys.argv) > 1 else None
data = ''
if path and os.path.exists(path):
data = open(path).read()
else:
data = sys.stdin.read()
lines = []
for raw in data.splitlines():
# cppcheck prints: [path:line]: (id) message
m = re.match(r"\[(?P<file>[^:]+):(?P<line>\d+)\] (?P<id>[^:]+): (?P<msg>.*)", raw)
if m:
lines.append(f"{m.group('file')}:{m.group('line')}: {m.group('id').strip()} - {m.group('msg').strip()}")
for l in sorted(set(lines)):
print(l)