@@ -338,30 +338,34 @@ def get_result_of_notice_html(found_on_html, notice_file_found):
338338 return "nok"
339339
340340
341- def find_notice_value ():
341+ def find_notice_value (notice_zip_dest_file = "" ):
342342 global notice_file_list , final_bin_info
343- str_notice_files = ""
343+ notice_file_comment = "Notice file not found. "
344344
345345 try :
346346 notice_file_list , notice_files = read_notice_file (os .path .abspath (build_out_notice_file_path ), NOTICE_HTML_FILE_NAME )
347- if not notice_file_list :
348- logger .info (f"Notice file is empty:{ notice_files } " )
349- return
350- if notice_files :
351- for notice_file in notice_files :
352- if "NOTICE.txt" in notice_file :
353- logger .debug (f"NOTICE.txt: { notice_file } " )
354- notice_files .remove (notice_file )
355- str_notice_files = "," .join (notice_files )
356- logger .info (f"Notice files:{ str_notice_files } " )
357- else :
358- logger .debug ("Can't find a notice file" )
359- return_list = do_multi_process (find_notice_html , final_bin_info )
360- final_bin_info = return_list [:]
361-
362- except IOError as error : # 'CANNOT_FIND_NOTICE_HTML'
347+ if notice_file_list :
348+ if notice_files :
349+ for notice_file in notice_files :
350+ if "NOTICE.txt" in notice_file :
351+ logger .debug (f"NOTICE.txt: { notice_file } " )
352+ notice_files .remove (notice_file )
353+ str_notice_files = "," .join (notice_files )
354+ logger .debug (f"Notice files:{ str_notice_files } " )
355+ if notice_zip_dest_file :
356+ final_notice_zip = create_and_copy_notice_zip (notice_files , notice_zip_dest_file )
357+ if final_notice_zip :
358+ notice_file_comment = f"Notice file to upload FOSSLight Hub: { final_notice_zip } "
359+ else :
360+ notice_file_comment = "Failed to compress the Notice file."
361+ else :
362+ logger .debug ("Can't find a notice file to read." )
363+ return_list = do_multi_process (find_notice_html , final_bin_info )
364+ final_bin_info = return_list [:]
365+ except Exception as error :
363366 logger .debug (f"find_notice_value:{ error } " )
364- return str_notice_files
367+ logger .info (notice_file_comment )
368+ return notice_file_comment
365369
366370
367371def find_notice_html (bin_info , return_list ):
@@ -771,25 +775,22 @@ def find_meta_lic_files():
771775 meta_lic_files [key ] = lic
772776
773777
774- def create_and_move_notice_zip (notice_files , zip_file_path , destination_folder ):
775- notice_files_list = [file_path .strip () for file_path in notice_files .split ("," )]
776- num_of_notice_file = len (notice_files_list )
778+ def create_and_copy_notice_zip (notice_files_list , zip_file_path ):
777779 final_destination_file_name = ""
778- if len (notice_files_list ) == 0 :
779- print (f"There is no notice file at all." )
780- elif len (notice_files_list ) == 1 :
780+
781+ if len (notice_files_list ) == 1 :
781782 single_file_path = notice_files_list [0 ]
782- destination_path = os .path .join (destination_folder , os .path .basename (single_file_path ))
783+ destination_path = os .path .join (os . path . dirname ( zip_file_path ) , os .path .basename (single_file_path ))
783784 shutil .copy (single_file_path , destination_path )
784785 final_destination_file_name = destination_path
785- print (f"Notice file is copied to '{ destination_path } '." )
786+ logger . debug (f"Notice file is copied to '{ destination_path } '." )
786787 else :
787788 with zipfile .ZipFile (zip_file_path , 'w' ) as zipf :
788789 for single_file_path in notice_files_list :
789790 zipf .write (single_file_path , arcname = os .path .basename (single_file_path ))
790791 final_destination_file_name = zip_file_path
791792
792- return num_of_notice_file , final_destination_file_name
793+ return final_destination_file_name
793794
794795
795796def main ():
@@ -885,7 +886,7 @@ def main():
885886
886887 map_binary_module_name_and_path (find_binaries_from_out_dir ())
887888
888- notice_files = find_notice_value ()
889+ notice_result_comment = find_notice_value (result_notice_zip_file_name )
889890 find_bin_license_info ()
890891
891892 set_mk_file_path () # Mk file path and local path, location of NOTICE file, can be different
@@ -898,19 +899,12 @@ def main():
898899 if analyze_source :
899900 from ._src_analysis import find_item_to_analyze
900901 final_bin_info = find_item_to_analyze (final_bin_info , python_script_dir , now , path_to_exclude )
901-
902- num_of_notice_file , destination_file = create_and_move_notice_zip (notice_files , result_notice_zip_file_name , python_script_dir )
903-
902+
904903 scan_item = ScannerItem (PKG_NAME , now )
905904 scan_item .set_cover_pathinfo (android_src_path , "" )
906905
907906 scan_item .set_cover_comment (f"Total number of binaries: { len (final_bin_info )} " )
908- if num_of_notice_file == 0 :
909- logger .info (f"There is no notice file at all." )
910- scan_item .set_cover_comment (f"\n There is no notice file at all." )
911- else :
912- logger .info (f"Notice file to upload FOSSLight Hub: { destination_file } " )
913- scan_item .set_cover_comment (f"\n Notice file to upload FOSSLight Hub: { destination_file } " )
907+ scan_item .set_cover_comment (notice_result_comment )
914908
915909 scan_item .append_file_items (final_bin_info , PKG_NAME )
916910 success , msg , result_file = write_output_file (result_excel_file_name , RESULT_FILE_EXTENSION ,
0 commit comments