1515from ._help import print_version , print_help_msg_source_scanner
1616from ._license_matched import get_license_list_to_print
1717from fosslight_util .output_format import check_output_format , write_output_file
18+ from fosslight_util .correct import correct_with_yaml
1819from .run_scancode import run_scan
1920from .run_scanoss import run_scanoss_py
2021from .run_scanoss import get_scanoss_extra_info
@@ -47,6 +48,8 @@ def main():
4748 print_matched_text = False
4849 format = ""
4950 selected_scanner = ""
51+ correct_mode = True
52+ correct_filepath = os .getcwd ()
5053
5154 scanned_result = []
5255 license_list = []
@@ -64,6 +67,8 @@ def main():
6467 parser .add_argument ('-s' , '--scanner' , nargs = 1 , type = str , required = False , default = 'all' )
6568 parser .add_argument ('-t' , '--timeout' , type = int , required = False , default = 120 )
6669 parser .add_argument ('-c' , '--cores' , type = int , required = False , default = - 1 )
70+ parser .add_argument ('--no_correction' , action = 'store_true' , required = False )
71+ parser .add_argument ('--correct_fpath' , nargs = 1 , type = str , required = False )
6772
6873 args = parser .parse_args ()
6974
@@ -84,6 +89,10 @@ def main():
8489 format = '' .join (args .format )
8590 if args .scanner :
8691 selected_scanner = '' .join (args .scanner )
92+ if args .no_correction :
93+ correct_mode = False
94+ if args .correct_fpath :
95+ correct_filepath = '' .join (args .correct_fpath )
8796
8897 time_out = args .timeout
8998 core = args .cores
@@ -108,7 +117,8 @@ def main():
108117 success , _result_log ["Scan Result" ], scanned_result , license_list = run_scan (path_to_scan , output_file_name ,
109118 write_json_file , core , True ,
110119 print_matched_text , format , True ,
111- time_out )
120+ time_out , correct_mode ,
121+ correct_filepath )
112122 elif selected_scanner == 'scanoss' :
113123 scanned_result = run_scanoss_py (path_to_scan , output_file_name , format , True , write_json_file )
114124 elif selected_scanner == 'all' or selected_scanner == '' :
@@ -120,7 +130,7 @@ def main():
120130 print_help_msg_source_scanner ()
121131 sys .exit (1 )
122132 create_report_file (_start_time , scanned_result , license_list , selected_scanner , print_matched_text ,
123- output_path , output_file , output_extension )
133+ output_path , output_file , output_extension , correct_mode , correct_filepath , path_to_scan )
124134 try :
125135 logger .info (yaml .safe_dump (_result_log , allow_unicode = True , sort_keys = True ))
126136 except Exception as ex :
@@ -131,7 +141,8 @@ def main():
131141
132142
133143def create_report_file (_start_time , scanned_result , license_list , selected_scanner , need_license = False ,
134- output_path = "" , output_file = "" , output_extension = "" ):
144+ output_path = "" , output_file = "" , output_extension = "" , correct_mode = True , correct_filepath = "" ,
145+ path_to_scan = "" ):
135146 """
136147 Create report files for given scanned result.
137148
@@ -178,6 +189,14 @@ def create_report_file(_start_time, scanned_result, license_list, selected_scann
178189 sheet_list ["scancode_reference" ] = get_license_list_to_print (license_list )
179190 sheet_list ["scanoss_reference" ] = get_scanoss_extra_info (scanned_result )
180191
192+ if correct_mode :
193+ success , msg_correct , correct_list = correct_with_yaml (correct_filepath , path_to_scan , sheet_list )
194+ if not success :
195+ logger .info (f"No correction with yaml: { msg_correct } " )
196+ else :
197+ sheet_list = correct_list
198+ logger .info ("Success to correct with yaml." )
199+
181200 output_file_without_ext = os .path .join (output_path , output_file )
182201 success_to_write , writing_msg , result_file = write_output_file (output_file_without_ext , output_extension ,
183202 sheet_list , extended_header )
@@ -216,7 +235,8 @@ def run_all_scanners(path_to_scan, output_file_name="", _write_json_file=False,
216235 success , _result_log ["Scan Result" ], scancode_result , license_list = run_scan (path_to_scan , output_file_name ,
217236 _write_json_file , num_cores ,
218237 True , need_license ,
219- format , called_by_cli , time_out )
238+ format , called_by_cli , time_out ,
239+ False , "" )
220240 scanoss_result = run_scanoss_py (path_to_scan , output_file_name , format , called_by_cli , _write_json_file )
221241
222242 for file_in_scancode_result in scancode_result :
0 commit comments