2121import yaml
2222import argparse
2323from .run_spdx_extractor import get_spdx_downloads
24- from ._scan_item import ScanItem
25- from fosslight_util .cover import CoverItem
24+ from ._scan_item import SourceItem
25+ from fosslight_util .oss_item import ScannerItem
2626
2727SRC_SHEET_NAME = 'SRC_FL_Source'
2828SCANOSS_HEADER = {SRC_SHEET_NAME : ['ID' , 'Source Path' , 'OSS Name' ,
3535
3636logger = logging .getLogger (constant .LOGGER_NAME )
3737warnings .filterwarnings ("ignore" , category = FutureWarning )
38- _PKG_NAME = "fosslight_source"
38+ PKG_NAME = "fosslight_source"
3939RESULT_KEY = "Scan Result"
4040
4141
@@ -75,7 +75,7 @@ def main():
7575 if args .help :
7676 print_help_msg_source_scanner ()
7777 if args .version :
78- print_version (_PKG_NAME )
78+ print_version (PKG_NAME )
7979 if not args .path :
8080 path_to_scan = os .getcwd ()
8181 else :
@@ -171,24 +171,21 @@ def create_report_file(_start_time, merged_result, license_list, scanoss_result,
171171
172172 if not correct_filepath :
173173 correct_filepath = path_to_scan
174- cover = CoverItem (tool_name = _PKG_NAME ,
175- start_time = _start_time ,
176- input_path = path_to_scan ,
177- exclude_path = path_to_exclude )
174+
175+ scan_item = ScannerItem (PKG_NAME , _start_time )
176+ scan_item .set_cover_pathinfo (path_to_scan , path_to_exclude )
178177 files_count , removed_files_count = count_files (path_to_scan , path_to_exclude )
179- cover . comment = f"Total number of files / removed files: { files_count } / { removed_files_count } "
178+ scan_item . set_cover_comment ( f"Total number of files / removed files: { files_count } / { removed_files_count } " )
180179
181- if len ( merged_result ) == 0 :
180+ if not merged_result :
182181 if files_count < 1 :
183- cover . comment += "(No file detected.)"
182+ scan_item . set_cover_comment ( "(No file detected.)" )
184183 else :
185- cover . comment += "(No OSS detected.)"
184+ scan_item . set_cover_comment ( "(No OSS detected.)" )
186185
187- sheet_list [SRC_SHEET_NAME ] = []
188186 if merged_result :
189- for scan_item in merged_result :
190- for row in scan_item .get_row_to_print ():
191- sheet_list [SRC_SHEET_NAME ].append (row )
187+ sheet_list = {}
188+ scan_item .append_file_items (merged_result , PKG_NAME )
192189
193190 if selected_scanner == 'scanoss' :
194191 extended_header = SCANOSS_HEADER
@@ -203,37 +200,40 @@ def create_report_file(_start_time, merged_result, license_list, scanoss_result,
203200 else :
204201 sheet_list ["scancode_reference" ] = get_license_list_to_print (license_list )
205202 sheet_list ["scanoss_reference" ] = get_scanoss_extra_info (scanoss_result )
203+ if sheet_list :
204+ scan_item .external_sheets = sheet_list
206205
207206 if correct_mode :
208- success , msg_correct , correct_list = correct_with_yaml (correct_filepath , path_to_scan , sheet_list )
207+ success , msg_correct , correct_item = correct_with_yaml (correct_filepath , path_to_scan , scan_item )
209208 if not success :
210209 logger .info (f"No correction with yaml: { msg_correct } " )
211210 else :
212- sheet_list = correct_list
211+ scan_item = correct_item
213212 logger .info ("Success to correct with yaml." )
214213
215214 combined_paths_and_files = [os .path .join (output_path , file ) for file in output_files ]
216215 results = []
217216 for combined_path_and_file , output_extension in zip (combined_paths_and_files , output_extensions ):
218- if need_license and output_extension == _json_ext and "scanoss_reference" in sheet_list :
219- del sheet_list ["scanoss_reference" ]
220- results .append (write_output_file (combined_path_and_file , output_extension , sheet_list , extended_header , "" , cover ))
217+ # if need_license and output_extension == _json_ext and "scanoss_reference" in sheet_list:
218+ # del sheet_list["scanoss_reference"]
219+ results .append (write_output_file (combined_path_and_file , output_extension , scan_item , extended_header , "" ))
221220 for success , msg , result_file in results :
222221 if success :
223222 logger .info (f"Output file: { result_file } " )
224- if cover :
225- logger .info (f' { cover . comment } ' )
223+ for row in scan_item . get_cover_comment () :
224+ logger .info (row )
226225 else :
227226 logger .error (f"Fail to generate result file { result_file } . msg:({ msg } )" )
227+ return scan_item
228228
229229
230230def merge_results (scancode_result = [], scanoss_result = [], spdx_downloads = {}):
231231 """
232232 Merge scanner results and spdx parsing result.
233- :param scancode_result: list of scancode results in ScanItem .
234- :param scanoss_result: list of scanoss results in ScanItem .
233+ :param scancode_result: list of scancode results in SourceItem .
234+ :param scanoss_result: list of scanoss results in SourceItem .
235235 :param spdx_downloads: dictionary of spdx parsed results.
236- :return merged_result: list of merged result in ScanItem .
236+ :return merged_result: list of merged result in SourceItem .
237237 """
238238
239239 # If anything that is found at SCANOSS only exist, add it to result.
@@ -247,9 +247,13 @@ def merge_results(scancode_result=[], scanoss_result=[], spdx_downloads={}):
247247 merged_result_item = scancode_result [scancode_result .index (file_name )]
248248 merged_result_item .download_location = download_location
249249 else :
250- new_result_item = ScanItem (file_name )
250+ new_result_item = SourceItem (file_name )
251251 new_result_item .download_location = download_location
252252 scancode_result .append (new_result_item )
253+
254+ for item in scancode_result :
255+ item .set_oss_item ()
256+
253257 return scancode_result
254258
255259
@@ -284,7 +288,7 @@ def run_scanners(path_to_scan, output_file_name="", write_json_file=False, num_c
284288 success , msg , output_path , output_files , output_extensions = check_output_formats (output_file_name , formats )
285289
286290 logger , result_log = init_log (os .path .join (output_path , f"fosslight_log_src_{ start_time } .txt" ),
287- True , logging .INFO , logging .DEBUG , _PKG_NAME , path_to_scan , path_to_exclude )
291+ True , logging .INFO , logging .DEBUG , PKG_NAME , path_to_scan , path_to_exclude )
288292
289293 if '.xlsx' not in output_extensions and print_matched_text :
290294 logger .warning ("-m option is only available for excel." )
@@ -302,17 +306,17 @@ def run_scanners(path_to_scan, output_file_name="", write_json_file=False, num_c
302306 if selected_scanner in SCANNER_TYPE :
303307 spdx_downloads = get_spdx_downloads (path_to_scan , path_to_exclude )
304308 merged_result = merge_results (scancode_result , scanoss_result , spdx_downloads )
305- create_report_file (start_time , merged_result , license_list , scanoss_result , selected_scanner ,
306- print_matched_text , output_path , output_files , output_extensions , correct_mode ,
307- correct_filepath , path_to_scan , path_to_exclude )
309+ scan_item = create_report_file (start_time , merged_result , license_list , scanoss_result , selected_scanner ,
310+ print_matched_text , output_path , output_files , output_extensions , correct_mode ,
311+ correct_filepath , path_to_scan , path_to_exclude )
308312 else :
309313 print_help_msg_source_scanner ()
310314 result_log [RESULT_KEY ] = "Unsupported scanner"
311315 success = False
312316 else :
313317 result_log [RESULT_KEY ] = f"Format error. { msg } "
314318 success = False
315- return success , result_log .get (RESULT_KEY , "" ), merged_result , license_list , scanoss_result
319+ return success , result_log .get (RESULT_KEY , "" ), scan_item , license_list , scanoss_result
316320
317321
318322if __name__ == '__main__' :
0 commit comments