55import logging
66import os
77from fosslight_source .run_scancode import run_scan as source_analysis
8- from fosslight_source .cli import create_report_file
8+ from fosslight_source .cli import create_report_file , merge_results
99from ._common import CONST_NULL
1010from fosslight_util .constant import LOGGER_NAME
1111
@@ -25,36 +25,38 @@ def find_item_to_analyze(bin_info, output_path, start_time="", path_to_exclude=[
2525 logger .debug (f"Find_item_to_analyze:{ error } " )
2626
2727 source_analysis_path = [path for path in path_list_to_analyze .keys () if path not in path_to_exclude ]
28- logger .info (f"|--Source analysis for { len (source_analysis_path )} paths." )
29- for path in source_analysis_path :
30- file_array = [len (files ) for r , d , files in os .walk (path )]
31- files = sum (file_array )
32- logger .info (f"{ path } , File Count:{ files } " )
28+ if source_analysis_path :
29+ logger .info (f"|--Source analysis for { len (source_analysis_path )} paths." )
30+ for path in source_analysis_path :
31+ file_array = [len (files ) for r , d , files in os .walk (path )]
32+ files = sum (file_array )
33+ logger .debug (f"{ path } , File Count:{ files } " )
3334
34- output_dir = os .path .join (output_path , f"{ ANALYSIS_OUTPUT_DIR } _{ start_time } " )
35+ output_dir = os .path .join (output_path , f"{ ANALYSIS_OUTPUT_DIR } _{ start_time } " )
3536
36- logger .info ("------------------------------" )
37- logger .info ("* START TO ANALYZE SOURCE *" )
38- idx = 0
39- for source_path in source_analysis_path :
40- try :
41- idx += 1
42- if os .path .isdir (source_path ):
43- logger .info (f"({ idx } ){ source_path } " )
44- license = run_src_analysis (source_path , start_time , output_dir )
45- path_list_to_analyze [source_path ] = license
46- except Exception as error :
47- logger .debug (f"Failed to run src analysis:{ error } " )
37+ logger .info ("********* START TO ANALYZE SOURCE **********" )
38+ idx = 0
39+ for source_path in source_analysis_path :
40+ try :
41+ if idx > 1 : # TEST
42+ break
43+ idx += 1
44+ if os .path .isdir (source_path ):
45+ logger .info (f"({ idx } ){ source_path } " )
46+ license = run_src_analysis (source_path , start_time , output_dir )
47+ path_list_to_analyze [source_path ] = license
48+ except Exception as error :
49+ logger .debug (f"Failed to run src analysis:{ error } " )
4850
49- for analyzed_path , analyzed_license in path_list_to_analyze .items ():
50- try :
51- for item in bin_info :
52- source_path = item .source_code_path
53- item_license = item .license
54- if source_path == analyzed_path and item_license == CONST_NULL :
55- item .set_license (analyzed_license )
56- except Exception as error :
57- logger .debug (f"Failed to update license from src analysis:{ error } " )
51+ for analyzed_path , analyzed_license in path_list_to_analyze .items ():
52+ try :
53+ for item in bin_info :
54+ source_path = item .source_code_path
55+ item_license = item .license
56+ if source_path == analyzed_path and item_license == CONST_NULL :
57+ item .set_license (analyzed_license )
58+ except Exception as error :
59+ logger .debug (f"Failed to update license from src analysis:{ error } " )
5860
5961 return bin_info
6062
@@ -63,20 +65,22 @@ def run_src_analysis(scan_input_path, start_time="", output_dir=""):
6365 license = CONST_NULL
6466 if os .path .exists (scan_input_path ):
6567 try :
68+ output_file_name = scan_input_path .replace ("/" , "_" )
6669 success , result_log , result , matched_txt = source_analysis (os .path .abspath (scan_input_path ),
67- output_dir ,
70+ output_file_name ,
6871 False , - 1 , True , True , "" ,
6972 True )
73+ result = merge_results (result )
7074 if success :
71- output_file_name = scan_input_path .replace ("/" , "_" )
7275 license_list = []
7376 for scan_item in result :
7477 license_list .extend (scan_item .licenses )
7578 license_list = list (dict .fromkeys (license_list ))
7679 license = "," .join (license_list )
7780 if result :
78- create_report_file (start_time , result , matched_txt , "scancode" , True ,
79- output_dir , output_file_name , ".xlsx" )
81+ logger .debug (f"Create a report - source analysis :{ output_dir } /{ output_file_name } .xlsx" )
82+ create_report_file (start_time , result , matched_txt , [], 'scancode' ,
83+ True , output_dir , [output_file_name ], [".xlsx" ], False , "" , scan_input_path , "" , ["excel" ])
8084 else :
8185 logger .debug (f"Failed to analysis (scan) { scan_input_path } :{ result_log } " )
8286 except Exception as error :
0 commit comments