Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend command line filters #1312

Merged
merged 1 commit into from
Jan 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions docs/user_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -1255,14 +1255,18 @@ positional arguments:

optional arguments:
-h, --help show this help message and exit
-s, --suppressed Show only suppressed results instead of only
unsuppressed ones. (default: False)
-s, --suppressed DEPRECATED. Use the '--filter' option to get false
positive (suppressed) results. Show only suppressed
results instead of only unsuppressed ones.
--filter FILTER Filter results. The filter string has the following
format:
[<SEVERITIES>]:[<CHECKER_NAMES>]:[<FILE_PATHS>] where
severites, checker_names, file_paths should be a comma
[<SEVERITIES>]:[<CHECKER_NAMES>]:[<FILE_PATHS>]:
[<DETECTION_STATUSES>]:[<REVIEW_STATUSES>] where
severites, checker_names, file_paths,
detection_statuses and review_statuses should be a comma
separated list, e.g.:
"high,medium:unix,core:*.cpp,*.h" (default: ::)
"high,medium:unix,core:*.cpp,*.h:new,unresolved:
false_positive,intentional" (default: ::)
~~~~~~~~~~~~~~~~~~~~~

### <a name="cmd-diff"></a> Show differences between two runs (`diff`)
Expand Down
40 changes: 24 additions & 16 deletions libcodechecker/cmd/cmd_line_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,14 @@ def add_filter_conditions(report_filter, filter_str):
the checker id doesn't have to be complete (e.g. unix).
"""

if filter_str.count(':') != 2:
LOG.error("Filter string has to contain two colons (e.g. "
"\"high,medium:unix,core:*.cpp\").")
if filter_str.count(':') != 4:
LOG.error("Filter string has to contain four colons (e.g. "
"\"high,medium:unix,core:*.cpp:new,unresolved:"
"false_positive,intentional\").")
sys.exit(1)

severities, checkers, paths = map(lambda x: x.strip(),
filter_str.split(':'))
severities, checkers, paths, dt_statuses, rw_statuses = \
map(lambda x: x.strip(), filter_str.split(':'))

if severities:
report_filter.severity = map(
Expand All @@ -99,6 +100,16 @@ def add_filter_conditions(report_filter, filter_str):
report_filter.filepath = map(lambda x: '*' + x + '*',
paths.split(','))

if dt_statuses:
report_filter.detectionStatus = map(
lambda x: ttypes.DetectionStatus._NAMES_TO_VALUES[x.upper()],
dt_statuses.split(','))

if rw_statuses:
report_filter.reviewStatus = map(
lambda x: ttypes.ReviewStatus._NAMES_TO_VALUES[x.upper()],
rw_statuses.split(','))

# ---------------------------------------------------------------------------
# Argument handlers for the 'CodeChecker cmd' subcommands.
# ---------------------------------------------------------------------------
Expand Down Expand Up @@ -154,24 +165,21 @@ def handle_list_results(args):
if args.output_format == 'json':
print(CmdLineOutputEncoder().encode(all_results))
else:

if args.suppressed:
header = ['File', 'Checker', 'Severity', 'Msg', 'Suppress comment']
else:
header = ['File', 'Checker', 'Severity', 'Msg']
header = ['File', 'Checker', 'Severity', 'Msg', 'Review status',
'Detection status']

rows = []
for res in all_results:
bug_line = res.line
checked_file = res.checkedFile + ' @ ' + str(bug_line)
sev = ttypes.Severity._VALUES_TO_NAMES[res.severity]
rw_status = \
ttypes.ReviewStatus._VALUES_TO_NAMES[res.reviewData.status]
dt_status = \
ttypes.DetectionStatus._VALUES_TO_NAMES[res.detectionStatus]

if args.suppressed:
rows.append((checked_file, res.checkerId, sev,
res.checkerMsg, res.suppressComment))
else:
rows.append(
(checked_file, res.checkerId, sev, res.checkerMsg))
rows.append((checked_file, res.checkerId, sev,
res.checkerMsg, rw_status, dt_status))

print(twodim_to_str(args.output_format, header, rows))

Expand Down
18 changes: 11 additions & 7 deletions libcodechecker/libhandlers/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,23 +132,27 @@ def __add_filtering_arguments(parser):
Add some common filtering arguments to the given parser.
"""

# TODO: '-s' does not mean suppressed anymore in any other command.
parser.add_argument('-s', '--suppressed',
dest="suppressed",
action='store_true',
help="Show only suppressed results instead of only "
"unsuppressed ones.")
help="DEPRECATED. Use the '--filter' option to get "
"false positive (suppressed) results. Show only "
"suppressed results instead of only unsuppressed "
"ones.")

parser.add_argument('--filter',
type=str,
dest='filter',
default="::",
default="::::",
help="Filter results. The filter string has the "
"following format: "
"[<SEVERITIES>]:[<CHECKER_NAMES>]:[<FILE_PATHS>] "
"[<SEVERITIES>]:[<CHECKER_NAMES>]:[<FILE_PATHS>]:"
"[<DETECTION_STATUSES>]:[<REVIEW_STATUSES>]"
"where severites, checker_names, "
"file_paths should be a comma separated list, "
"e.g.: \"high,medium:unix,core:*.cpp,*.h\"")
"file_paths, detection_statuses, review_statuses "
"should be a comma separated list, e.g.:"
"\"high,medium:unix,core:*.cpp,*.h:"
"new,unresolved:false_positive,intentional\"")


def __register_results(parser):
Expand Down