Skip to content

Commit

Permalink
Use glob pattern matching for exclusion
Browse files Browse the repository at this point in the history
Signed-off-by: Wonjae Park <[email protected]>

Signed-off-by: Wonjae Park <[email protected]>
  • Loading branch information
JustinWonjaePark committed Nov 27, 2024
1 parent f52aa50 commit 5abce8c
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/fosslight_source/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import platform
import warnings
import logging
import fnmatch
from datetime import datetime
import fosslight_util.constant as constant
from fosslight_util.set_log import init_log
Expand Down Expand Up @@ -285,14 +286,15 @@ def merge_results(scancode_result: list = [], scanoss_result: list = [], spdx_do
for i in range(len(scancode_result) - 1, -1, -1):
item = scancode_result[i]
item_path = item.source_name_or_path

# normalize for windows
normalized_patterns = [os.path.normpath(pattern).replace("\\", "/") for pattern in path_to_exclude]

if not any(
item_path == excluded or item_path.startswith(f"{excluded}{os.sep}")
for excluded in path_to_exclude
):
item.set_oss_item()
else:
# remove from the scanned list if path is matched with exclude patterns
if any(fnmatch.fnmatch(item_path.replace("\\", "/"), pattern) for pattern in normalized_patterns):
del scancode_result[i]
else:
item.set_oss_item()

return scancode_result

Expand Down Expand Up @@ -345,7 +347,7 @@ def run_scanners(
success, result_log[RESULT_KEY], scancode_result, license_list = run_scan(path_to_scan, output_file_name,
write_json_file, num_cores, True,
print_matched_text, formats, called_by_cli,
time_out, correct_mode, correct_filepath)
time_out, correct_mode, correct_filepath, path_to_exclude)
if selected_scanner == 'scanoss' or selected_scanner == 'all' or selected_scanner == '':
scanoss_result = run_scanoss_py(path_to_scan, output_file_name, formats, True, write_json_file, num_cores,
path_to_exclude)
Expand Down

0 comments on commit 5abce8c

Please sign in to comment.