1717from fosslight_util .set_log import init_log
1818from fosslight_util .set_log import init_log_item
1919from fosslight_util .timer_thread import TimerThread
20- from ._write_oss_report_src import write_result_to_csv , write_result_to_excel
2120from ._parsing_scancode_file_item import parsing_file_item
21+ from fosslight_util .write_excel import write_excel_and_csv
2222
2323logger = logging .getLogger (constant .LOGGER_NAME )
2424warnings .filterwarnings ("ignore" , category = FutureWarning )
2525_PKG_NAME = "fosslight_source"
2626_ERROR_PREFIX = "* Error : "
2727
28+
2829def print_help_msg ():
2930 print ("* Required : -p path_to_scan" )
3031 print ("* Optional : -j " )
@@ -72,12 +73,10 @@ def run_scan(path_to_scan, output_file_name="",
7273
7374 if output_file_name == "" :
7475 output_file = "OSS-Report_" + start_time
75- output_csv_file = "result_" + start_time
7676 output_json_file = "scancode_" + start_time
7777 output_dir = os .getcwd ()
7878 else :
7979 output_file = output_file_name
80- output_csv_file = output_file_name
8180 output_json_file = output_file_name
8281 output_dir = os .path .dirname (os .path .abspath (output_file_name ))
8382
@@ -92,7 +91,6 @@ def run_scan(path_to_scan, output_file_name="",
9291
9392 num_cores = multiprocessing .cpu_count () - 1 if num_cores < 0 else num_cores
9493
95- sheet_list = {}
9694 if os .path .isdir (path_to_scan ):
9795 try :
9896 output_json_file = output_json_file + ".json" if _write_json_file \
@@ -104,32 +102,28 @@ def run_scan(path_to_scan, output_file_name="",
104102 processes = num_cores ,
105103 output_json_pp = output_json_file ,
106104 only_findings = True )
107-
108- if rc :
105+ if not rc :
106+ msg += _ERROR_PREFIX + "Source code analysis failed.\n "
107+ success = False
108+ if results :
109+ sheet_list = {}
109110 for key , value in results .items ():
110111 if key == "files" :
111112 rc , result_list , parsing_msg = parsing_file_item (value )
112113 _result_log ["Parsing Log" ] = parsing_msg
113114 if rc :
114- if len (result_list ) > 0 :
115- sheet_list ["SRC" ] = result_list
116- write_result_to_excel (
117- output_file + ".xlsx" , sheet_list )
118- _result_log ["OSS Report" ] = output_file
119- else :
120- msg = "* There is no item" \
121- " to print in OSS-Report."
122- if not _windows :
123- write_result_to_csv (output_csv_file + ".csv" , sheet_list )
124- else :
125- msg = _ERROR_PREFIX + "Source code analysis failed."
126- success = False
115+ sheet_list ["SRC" ] = [scan_item .get_row_to_print () for scan_item in result_list ]
116+ success_to_write , writing_msg = write_excel_and_csv (
117+ output_file , sheet_list )
118+ logger .warn ("* Writing excel :" + str (success_to_write )+ " " + writing_msg )
119+ if success_to_write :
120+ _result_log ["OSS Report" ] = output_file + ".xlsx"
127121 except Exception as ex :
128122 success = False
129- msg = _ERROR_PREFIX + str (ex )
123+ msg = _ERROR_PREFIX + str (ex )+ " \n "
130124 else :
131125 success = False
132- msg = _ERROR_PREFIX + "Check the path to scan. :" + path_to_scan
126+ msg = _ERROR_PREFIX + "Check the path to scan. :" + path_to_scan + " \n "
133127
134128 scan_result_msg = str (success )+ " " + msg
135129 _result_log ["Scan Result" ] = scan_result_msg .strip ()
0 commit comments