1010import platform
1111import getopt
1212import logging
13+ import yaml
1314from scancode import cli
1415from datetime import datetime
1516import fosslight_util .constant as constant
1617from fosslight_util .set_log import init_log
18+ from fosslight_util .set_log import init_log_item
19+ from fosslight_util .timer_thread import TimerThread
1720from ._write_oss_report_src import write_result_to_csv , write_result_to_excel
1821from ._parsing_scancode_file_item import parsing_file_item
19- from fosslight_util .timer_thread import TimerThread
2022
2123logger = logging .getLogger (constant .LOGGER_NAME )
2224warnings .filterwarnings ("ignore" , category = FutureWarning )
23-
25+ _PKG_NAME = "fosslight_source"
26+ _ERROR_PREFIX = "* Error : "
2427
2528def print_help_msg ():
2629 print ("* Required : -p path_to_scan" )
@@ -52,7 +55,7 @@ def main():
5255 timer = TimerThread ()
5356 timer .setDaemon (True )
5457 timer .start ()
55- success , msg = run_scan (_path_to_scan , _output_file , _write_json_file , - 1 )
58+ success , result_log = run_scan (_path_to_scan , _output_file , _write_json_file , - 1 )
5659
5760
5861def run_scan (path_to_scan , output_file_name = "" ,
@@ -61,6 +64,8 @@ def run_scan(path_to_scan, output_file_name="",
6164
6265 success = True
6366 msg = ""
67+ _str_final_result_log = ""
68+ _result_log = {}
6469
6570 _windows = platform .system () == "Windows"
6671 start_time = datetime .now ().strftime ('%Y-%m-%d_%H-%M-%S' )
@@ -77,6 +82,7 @@ def run_scan(path_to_scan, output_file_name="",
7782 output_dir = os .path .dirname (os .path .abspath (output_file_name ))
7883
7984 logger = init_log (os .path .join (output_dir , "fosslight_src_log_" + start_time + ".txt" ))
85+ _result_log = init_log_item (_PKG_NAME , path_to_scan )
8086
8187 if path_to_scan == "" :
8288 if _windows :
@@ -102,29 +108,38 @@ def run_scan(path_to_scan, output_file_name="",
102108 if rc :
103109 for key , value in results .items ():
104110 if key == "files" :
105- rc , result_list = parsing_file_item (value )
111+ rc , result_list , parsing_msg = parsing_file_item (value )
112+ _result_log ["Parsing Log" ] = parsing_msg
106113 if rc :
107114 if len (result_list ) > 0 :
108115 sheet_list ["SRC" ] = result_list
109116 write_result_to_excel (
110117 output_file + ".xlsx" , sheet_list )
118+ _result_log ["OSS Report" ] = output_file
111119 else :
112120 msg = "* There is no item" \
113121 " to print in OSS-Report."
114122 if not _windows :
115123 write_result_to_csv (output_csv_file + ".csv" , sheet_list )
116124 else :
117- msg = "* Source code analysis failed."
125+ msg = _ERROR_PREFIX + " Source code analysis failed."
118126 success = False
119127 except Exception as ex :
120128 success = False
121- msg = '* Error :' + str (ex )
129+ msg = _ERROR_PREFIX + str (ex )
122130 else :
123131 success = False
124- msg = "* Check the path to scan. :" + path_to_scan
132+ msg = _ERROR_PREFIX + " Check the path to scan. :" + path_to_scan
125133
126- logger .warn ("* Scan Result:" + str (success )+ "\n " + msg )
127- return success , msg
134+ scan_result_msg = str (success )+ " " + msg
135+ _result_log ["Scan Result" ] = scan_result_msg .strip ()
136+ _result_log ["Output Directory" ] = output_dir
137+ try :
138+ _str_final_result_log = yaml .safe_dump (_result_log , allow_unicode = True , sort_keys = True )
139+ logger .warn ("\n " + _str_final_result_log )
140+ except Exception as ex :
141+ logger .warn (_ERROR_PREFIX + "Failed to print result log. " + str (ex ))
142+ return success , _str_final_result_log
128143
129144
130145if __name__ == '__main__' :
0 commit comments