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,9 @@ def main():
4748 print_matched_text = False
4849 format = ""
4950 selected_scanner = ""
51+ correct_mode = True
52+ correct_filepath = os .getcwd ()
53+
5054
5155 scanned_result = []
5256 license_list = []
@@ -64,6 +68,8 @@ def main():
6468 parser .add_argument ('-s' , '--scanner' , nargs = 1 , type = str , required = False , default = 'all' )
6569 parser .add_argument ('-t' , '--timeout' , type = int , required = False , default = 120 )
6670 parser .add_argument ('-c' , '--cores' , type = int , required = False , default = - 1 )
71+ parser .add_argument ('--no_correction' , action = 'store_true' , required = False )
72+ parser .add_argument ('--correct_fpath' , nargs = 1 , type = str , required = False )
6773
6874 args = parser .parse_args ()
6975
@@ -84,6 +90,10 @@ def main():
8490 format = '' .join (args .format )
8591 if args .scanner :
8692 selected_scanner = '' .join (args .scanner )
93+ if args .no_correction :
94+ correct_mode = False
95+ if args .correct_fpath :
96+ correct_filepath = '' .join (args .correct_fpath )
8797
8898 time_out = args .timeout
8999 core = args .cores
@@ -108,7 +118,8 @@ def main():
108118 success , _result_log ["Scan Result" ], scanned_result , license_list = run_scan (path_to_scan , output_file_name ,
109119 write_json_file , core , True ,
110120 print_matched_text , format , True ,
111- time_out )
121+ time_out , correct_mode ,
122+ correct_filepath )
112123 elif selected_scanner == 'scanoss' :
113124 scanned_result = run_scanoss_py (path_to_scan , output_file_name , format , True , write_json_file )
114125 elif selected_scanner == 'all' or selected_scanner == '' :
@@ -120,7 +131,7 @@ def main():
120131 print_help_msg_source_scanner ()
121132 sys .exit (1 )
122133 create_report_file (_start_time , scanned_result , license_list , selected_scanner , print_matched_text ,
123- output_path , output_file , output_extension )
134+ output_path , output_file , output_extension , correct_mode , correct_filepath )
124135 try :
125136 logger .info (yaml .safe_dump (_result_log , allow_unicode = True , sort_keys = True ))
126137 except Exception as ex :
@@ -131,7 +142,7 @@ def main():
131142
132143
133144def create_report_file (_start_time , scanned_result , license_list , selected_scanner , need_license = False ,
134- output_path = "" , output_file = "" , output_extension = "" ):
145+ output_path = "" , output_file = "" , output_extension = "" , correct_mode = True , correct_filepath = "" ):
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 , 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