Skip to content

Commit 8145345

Browse files
testing fl util dev_exclude_error2
Signed-off-by: Wonjae Park <[email protected]>
1 parent 482d39c commit 8145345

File tree

1 file changed

+31
-34
lines changed

1 file changed

+31
-34
lines changed

src/fosslight_source/cli.py

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from ._scan_item import SourceItem
2727
from fosslight_util.oss_item import ScannerItem
2828
from typing import Tuple
29+
import time
2930

3031
SRC_SHEET_NAME = 'SRC_FL_Source'
3132
SCANOSS_HEADER = {SRC_SHEET_NAME: ['ID', 'Source Path', 'OSS Name',
@@ -85,7 +86,6 @@ def main() -> None:
8586
path_to_scan = ''.join(args.path)
8687
if args.exclude:
8788
path_to_exclude = args.exclude
88-
print("path_to_exclude in main : ", path_to_exclude)
8989
if args.json:
9090
write_json_file = True
9191
output_file_name = ''.join(args.output)
@@ -110,9 +110,26 @@ def main() -> None:
110110

111111
if os.path.isdir(path_to_scan):
112112
result = []
113-
result = run_scanners(path_to_scan, output_file_name, write_json_file, core, True,
114-
print_matched_text, formats, time_out, correct_mode, correct_filepath,
115-
selected_scanner, path_to_exclude)
113+
114+
test_cases = [
115+
(["file1.js", "file2.py"], "./exclude_test"),
116+
(["sample/*"], "./exclude_test"),
117+
(["sample/subfolder/*"], "./exclude_test"),
118+
(["*.py"], "./exclude_test"),
119+
(["subfolder"], "./exclude_test"),
120+
]
121+
# no = 0
122+
# for i, (patterns, path_to_scan) in enumerate(test_cases, 1):
123+
124+
for i, (path_to_exclude, path_to_scan) in enumerate(test_cases, 1):
125+
print(f"\n=== 케이스 {i} ===", path_to_exclude)
126+
result = run_scanners(path_to_scan, output_file_name, write_json_file, core, True,
127+
print_matched_text, formats, time_out, correct_mode, correct_filepath,
128+
selected_scanner, path_to_exclude)
129+
time.sleep(40)
130+
# result = run_scanners(path_to_scan, output_file_name, write_json_file, core, True,
131+
# print_matched_text, formats, time_out, correct_mode, correct_filepath,
132+
# selected_scanner, path_to_exclude)
116133
sys.exit(0)
117134

118135
_result_log["Scan Result"] = result[1]
@@ -264,7 +281,8 @@ def create_report_file(
264281
return scan_item
265282

266283

267-
def merge_results(scancode_result: list = [], scanoss_result: list = [], spdx_downloads: dict = {}) -> list:
284+
def merge_results(scancode_result: list = [], scanoss_result: list = [], spdx_downloads: dict = {}, excluded_file_list=[]) -> list:
285+
268286
"""
269287
Merge scanner results and spdx parsing result.
270288
:param scancode_result: list of scancode results in SourceItem.
@@ -288,6 +306,12 @@ def merge_results(scancode_result: list = [], scanoss_result: list = [], spdx_do
288306
new_result_item.download_location = download_location
289307
scancode_result.append(new_result_item)
290308

309+
for i in range(len(scancode_result) - 1, -1, -1): # Iterate from last to first
310+
item_path = scancode_result[i].source_name_or_path # Assuming SourceItem has 'file_path' attribute
311+
if item_path in excluded_file_list:
312+
print("EXCLUDING : ", item_path)
313+
del scancode_result[i] # Delete matching item
314+
291315
for item in scancode_result:
292316
item.set_oss_item()
293317

@@ -332,34 +356,7 @@ def run_scanners(
332356

333357
logger, result_log = init_log(os.path.join(output_path, f"fosslight_log_src_{start_time}.txt"),
334358
True, logging.INFO, logging.DEBUG, PKG_NAME, path_to_scan, path_to_exclude)
335-
# print("path_to_exclude : ", type(path_to_exclude), "||", path_to_exclude)
336-
# print("path_to_scan : ", type(path_to_scan), " || ", path_to_scan)
337-
338-
# excluded_file_list = excluding_files(path_to_exclude, path_to_scan)
339-
# no = 0
340-
# print("excluding_file_list : ", type(excluded_file_list))
341-
# print(excluded_file_list)
342-
# for excluded_file in excluded_file_list:
343-
# no = no + 1
344-
# print(no, ". ", excluded_file)
345-
346-
# if __name__ == "__main__":
347-
test_cases = [
348-
(["file1.js", "file2.py"], "./exclude_test"),
349-
(["sample/*"], "./exclude_test"),
350-
(["sample/subfolder/*"], "./exclude_test"),
351-
(["*.py"], "./exclude_test"),
352-
(["subfolder"], "./exclude_test"),
353-
]
354-
355-
for i, (patterns, path_to_scan) in enumerate(test_cases, 1):
356-
print(f"\n=== 케이스 {i} ===", patterns)
357-
excluding = excluding_files(patterns, path_to_scan)
358-
for r, re in enumerate(excluding, 1):
359-
print(f"{r}. {re}")
360-
# print("\n".join(result))
361-
362-
return 0
359+
excluded_file_list = excluding_files(path_to_exclude, path_to_scan)
363360

364361
if '.xlsx' not in output_extensions and print_matched_text:
365362
logger.warning("-m option is only available for excel.")
@@ -376,7 +373,7 @@ def run_scanners(
376373
path_to_exclude)
377374
if selected_scanner in SCANNER_TYPE:
378375
spdx_downloads = get_spdx_downloads(path_to_scan, path_to_exclude)
379-
merged_result = merge_results(scancode_result, scanoss_result, spdx_downloads)
376+
merged_result = merge_results(scancode_result, scanoss_result, spdx_downloads, excluded_file_list)
380377
scan_item = create_report_file(start_time, merged_result, license_list, scanoss_result, selected_scanner,
381378
print_matched_text, output_path, output_files, output_extensions, correct_mode,
382379
correct_filepath, path_to_scan, path_to_exclude, formats)

0 commit comments

Comments
 (0)