2323import numpy as np
2424from functools import partial
2525from fosslight_util .set_log import init_log
26- from ._write_excel import write_result
2726from ._util import (
2827 read_file ,
2928 write_txt_file ,
5453from fosslight_binary .binary_analysis import return_bin_only
5554import argparse
5655from pathlib import Path
57- from fosslight_util .cover import CoverItem
56+ from fosslight_util .oss_item import ScannerItem
57+ from fosslight_util .output_format import write_output_file
5858
5959EXCEPTIONAL_PATH = [r"(/)+gen/META/lic_intermediates/" ]
6060android_log_lines = []
7474ANDROID_LOG_FILE_NAME = "android.log"
7575num_cores = 1
7676now = ""
77+ HIDDEN_HEADER = {'TLSH' , "SHA1" }
78+ HEADER = {'BIN (Android)' : ['ID' , 'Binary Path' , 'Source Path' , 'Notice' , 'OSS Name' ,
79+ 'OSS Version' , 'License' , 'Download Location' , 'Homepage' ,
80+ 'Copyright Text' , 'License Text' , 'Exclude' , 'Comment' ,
81+ 'Need Check' , 'TLSH' , 'SHA1' ]}
7782
7883# For checking repository's name
7984repositories = {}
@@ -635,7 +640,7 @@ def remove_duplicated_binaries_by_checking_checksum(remove_list_file):
635640 continue
636641 if skip :
637642 cnt += 1
638- print_removed_str , print_removed_array = item .get_print_items ( )
643+ print_removed_str = item .get_print_array ( False )
639644 for row_removed in print_removed_str :
640645 str_bin_removed += f"{ row_removed } \n "
641646 continue
@@ -679,7 +684,7 @@ def remove_duplicated_binaries_by_checking_checksum(remove_list_file):
679684
680685 for bin_same_name in same_name_binaries :
681686 if bin_same_name .bin_name != final_added .bin_name :
682- print_removed_str , print_removed_array = bin_same_name .get_print_items ( )
687+ print_removed_str = bin_same_name .get_print_array ( False )
683688 for row_removed in print_removed_str :
684689 str_bin_removed += f"{ row_removed } \n "
685690 else : # Don't have any duplicated binaries
@@ -766,6 +771,7 @@ def main():
766771 _NOTICE_CHECKLIST_TYPE = False
767772 analyze_source = False
768773 path_to_exclude = []
774+ RESULT_FILE_EXTENSION = ".xlsx"
769775
770776 num_cores = multiprocessing .cpu_count () - 1
771777 if num_cores < 1 :
@@ -775,7 +781,7 @@ def main():
775781 android_src_path = python_script_dir
776782 now = datetime .now ().strftime ('%y%m%d_%H%M' )
777783 log_txt_file = os .path .join (python_script_dir , f"fosslight_log_android_{ now } .txt" )
778- result_excel_file = os .path .join (python_script_dir , f"fosslight_report_android_{ now } .xlsx " )
784+ result_excel_file_name = os .path .join (python_script_dir , f"fosslight_report_android_{ now } " )
779785 remove_list_file = ""
780786
781787 parser = argparse .ArgumentParser (description = 'FOSSLight Android' , prog = 'fosslight_android' , add_help = False )
@@ -861,13 +867,17 @@ def main():
861867 from ._src_analysis import find_item_to_analyze
862868 final_bin_info = find_item_to_analyze (final_bin_info , python_script_dir , now , path_to_exclude )
863869
864- cover = CoverItem (tool_name = PKG_NAME ,
865- start_time = now ,
866- input_path = android_src_path )
867- cover .comment = f"Total number of binaries: { len (final_bin_info )} "
868- cover .comment += f"\n Notice: { notice_files } "
869- write_result (result_excel_file , final_bin_info , cover )
870- result_log ["Output FOSSLight Report" ] = result_excel_file
870+ scan_item = ScannerItem (PKG_NAME , now )
871+ scan_item .set_cover_pathinfo (android_src_path , "" )
872+
873+ scan_item .set_cover_comment (f"Total number of binaries: { len (final_bin_info )} " )
874+ scan_item .set_cover_comment (f"\n Notice: { notice_files } " )
875+ scan_item .append_file_items (final_bin_info , PKG_NAME )
876+ success , msg , result_file = write_output_file (result_excel_file_name , RESULT_FILE_EXTENSION ,
877+ scan_item , HEADER , HIDDEN_HEADER )
878+ if not success :
879+ logger .warning (f"Failed to write result to excel:{ msg } " )
880+ result_log ["Output FOSSLight Report" ] = f"{ result_file } "
871881
872882 if _create_additial_notice :
873883 create_additional_notice (final_bin_info , python_script_dir )
0 commit comments