Skip to content
Closed
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
25 changes: 22 additions & 3 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 glob
from datetime import datetime
import fosslight_util.constant as constant
from fosslight_util.set_log import init_log
Expand Down Expand Up @@ -261,7 +262,7 @@ def create_report_file(
return scan_item


def merge_results(scancode_result: list = [], scanoss_result: list = [], spdx_downloads: dict = {}) -> list:
def merge_results(scancode_result: list = [], scanoss_result: list = [], spdx_downloads: dict = {}, path_to_exclude=[]) -> list:
"""
Merge scanner results and spdx parsing result.
:param scancode_result: list of scancode results in SourceItem.
Expand All @@ -285,6 +286,23 @@ def merge_results(scancode_result: list = [], scanoss_result: list = [], spdx_do
new_result_item.download_location = download_location
scancode_result.append(new_result_item)

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

# cnt = 0
if path_to_exclude:
for i in range(len(scancode_result) - 1, -1, -1): # Iterate from last to first
item_path = scancode_result[i].source_name_or_path # Assuming SourceItem has 'file_path' attribute
if any(
glob.fnmatch.fnmatch(item_path, f"{pattern}") or # file name
glob.fnmatch.fnmatch(item_path, f"*/{pattern}") or # file name in sub directory
glob.fnmatch.fnmatch(item_path, f"*{pattern}/*") # directory name
for pattern in normalized_patterns
):
# cnt += 1
# print(cnt, "EXCLUDED:", item_path)
del scancode_result[i] # Delete matching item

for item in scancode_result:
item.set_oss_item()

Expand Down Expand Up @@ -339,13 +357,14 @@ 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)
if selected_scanner in SCANNER_TYPE:
spdx_downloads = get_spdx_downloads(path_to_scan, path_to_exclude)
merged_result = merge_results(scancode_result, scanoss_result, spdx_downloads)
merged_result = merge_results(scancode_result, scanoss_result, spdx_downloads, path_to_exclude)
scan_item = create_report_file(start_time, merged_result, license_list, scanoss_result, selected_scanner,
print_matched_text, output_path, output_files, output_extensions, correct_mode,
correct_filepath, path_to_scan, path_to_exclude, formats)
Expand Down
3 changes: 3 additions & 0 deletions src/fosslight_source/run_scanoss.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ def run_scanoss_py(path_to_scan: str, output_file_name: str = "", format: list =

try:
if write_json_file:
destination_file = os.path.join(output_path, SCANOSS_RESULT_FILE)
if os.path.exists(destination_file):
os.remove(destination_file)
shutil.move(SCANOSS_RESULT_FILE, output_path)
else:
os.remove(output_json_file)
Expand Down
Loading