1010import re
1111import json
1212import logging
13+ import zipfile
14+ import shutil
1315# Parsing NOTICE
1416from bs4 import BeautifulSoup
1517import subprocess
7072platform_version = "" # Android Version. ex- 7.0.0.r1 -> 7.0
7173
7274# Define Const Variables
73- NOTICE_HTML_FILE_NAME = ""
75+
7476ANDROID_LOG_FILE_NAME = "android.log"
7577num_cores = 1
7678now = ""
@@ -198,7 +200,8 @@ def set_env_variables_from_result_log():
198200 for line in android_log_lines :
199201 try :
200202 line = line .strip ()
201- pattern = re .compile (r'.*PLATFORM_VERSION\s*=\s*(\d+.?\d?)(.*\d*)\S*\s*' )
203+ #pattern = re.compile(r'.*PLATFORM_VERSION\s*=\s*(\d+.?\d?)(.*\d*)\S*\s*')
204+ pattern = re .compile (r'.*PLATFORM_VERSION\s*=\s*(\d+)\.?\d*\S*\s*' )
202205 matched = pattern .match (line )
203206 if matched is not None :
204207 platform_version = matched .group (1 )
@@ -335,7 +338,8 @@ def find_notice_value():
335338 str_notice_files = ""
336339
337340 try :
338- notice_file_list , notice_files = read_notice_file (os .path .abspath (build_out_notice_file_path ), NOTICE_HTML_FILE_NAME )
341+ #notice_file_list, notice_files = read_notice_file(os.path.abspath(build_out_notice_file_path), NOTICE_HTML_FILE_NAME)
342+ notice_file_list , notice_files = read_notice_file (os .path .abspath (build_out_notice_file_path ))
339343 if not notice_file_list :
340344 logger .info (f"Notice file is empty:{ notice_files } " )
341345 return
@@ -761,16 +765,33 @@ def find_meta_lic_files():
761765 if lic_list :
762766 lic = ',' .join (lic_list )
763767 meta_lic_files [key ] = lic
768+
769+
770+ def create_and_move_notice_zip (notice_files , zip_file_path , destination_folder ):
771+ notice_files_list = [file_path .strip () for file_path in notice_files .split ("," )]
772+ num_of_notice_file = len (notice_files_list )
773+ final_destination_file_name = ""
774+ if len (notice_files_list ) == 0 :
775+ print (f"There is no notice file at all." )
776+ elif len (notice_files_list ) == 1 :
777+ single_file_path = notice_files_list [0 ]
778+ destination_path = os .path .join (destination_folder , os .path .basename (single_file_path ))
779+ shutil .copy (single_file_path , destination_path )
780+ final_destination_file_name = destination_path
781+ print (f"Notice file is copied to '{ destination_path } '." )
782+ else :
783+ with zipfile .ZipFile (zip_file_path , 'w' ) as zipf :
784+ for single_file_path in notice_files_list :
785+ zipf .write (single_file_path , arcname = os .path .basename (single_file_path ))
786+ final_destination_file_name = zip_file_path
787+
788+ return num_of_notice_file , final_destination_file_name
764789
765790
766791def main ():
767- global android_log_lines , ANDROID_LOG_FILE_NAME , NOTICE_HTML_FILE_NAME , python_script_dir , num_cores , now , logger , final_bin_info
768- find_empty_path = False
769- _create_additial_notice = False
770- notice_check_ok = False
771- base_binary_txt = ""
772- auto_fill_oss_name = True
773- _NOTICE_CHECKLIST_TYPE = False
792+ global android_log_lines , ANDROID_LOG_FILE_NAME , python_script_dir , num_cores , now , logger , final_bin_info
793+ find_empty_path = False
794+ auto_fill_oss_name = True
774795 analyze_source = False
775796 path_to_exclude = []
776797 RESULT_FILE_EXTENSION = ".xlsx"
@@ -784,22 +805,18 @@ def main():
784805 now = datetime .now ().strftime ('%y%m%d_%H%M' )
785806 log_txt_file = os .path .join (python_script_dir , f"fosslight_log_android_{ now } .txt" )
786807 result_excel_file_name = os .path .join (python_script_dir , f"fosslight_report_android_{ now } " )
808+ result_notice_zip_file_name = os .path .join (python_script_dir , f"notice_to_fosslight-hub_{ now } .zip" )
787809 remove_list_file = ""
788810
789811 parser = argparse .ArgumentParser (description = 'FOSSLight Android' , prog = 'fosslight_android' , add_help = False )
790812 parser .add_argument ('-h' , '--help' , action = 'store_true' , required = False )
791813 parser .add_argument ('-v' , '--version' , action = 'store_true' , required = False )
792- parser .add_argument ('-s' , '--source' , type = str , required = False )
793- parser .add_argument ('-b' , '--binary' , type = str , required = False )
794- parser .add_argument ('-n' , '--notice' , type = str , required = False )
795- parser .add_argument ('-t' , '--toadd' , action = 'store_true' , required = False )
814+ parser .add_argument ('-s' , '--source' , type = str , required = False )
796815 parser .add_argument ('-m' , '--more' , action = 'store_true' , required = False )
797- parser .add_argument ('-c' , '--check' , type = str , required = False )
798816 parser .add_argument ('-a' , '--android' , type = str , required = False )
799817 parser .add_argument ('-f' , '--find' , action = 'store_true' , required = False )
800818 parser .add_argument ('-i' , '--ignore' , action = 'store_true' , required = False )
801- parser .add_argument ('-p' , '--packaging' , type = str , required = False )
802- parser .add_argument ('-d' , '--divide' , type = str , required = False )
819+ parser .add_argument ('-p' , '--packaging' , type = str , required = False )
803820 parser .add_argument ('-r' , '--remove' , type = str , required = False )
804821 parser .add_argument ('-e' , '--exclude' , nargs = "*" , required = False , default = [])
805822
@@ -810,18 +827,9 @@ def main():
810827 print_version (PKG_NAME )
811828 if args .source : # android source path
812829 os .chdir (args .source )
813- android_src_path = args .source
814- if args .binary : # Base model's binary.txt to exclude
815- base_binary_txt = args .binary
816- if args .notice :
817- NOTICE_HTML_FILE_NAME = args .notice
818- if args .toadd : # Create needtoadd-notice.html file.
819- _create_additial_notice = True
830+ android_src_path = args .source
820831 if args .more : # Analyze source mode.
821- analyze_source = True
822- if args .check :
823- _NOTICE_CHECKLIST_TYPE = True
824- notice_check_ok = (args .check == "ok" or args .check == "OK" )
832+ analyze_source = True
825833 if args .android :
826834 ANDROID_LOG_FILE_NAME = args .android
827835 if args .find : # Execute "find" command when source path is not found.
@@ -835,16 +843,9 @@ def main():
835843
836844 if args .packaging :
837845 check_packaging_files (args .packaging )
838- return
839- if args .divide :
840- divide_notice_files_by_binary (args .divide , python_script_dir , now )
841- return
846+ return
842847 if args .remove : # Remove the inputted list from the binary list.
843- remove_list_file = args .remove
844-
845- if _NOTICE_CHECKLIST_TYPE :
846- run_notice_html_checklist (base_binary_txt , notice_check_ok , NOTICE_HTML_FILE_NAME )
847- return
848+ remove_list_file = args .remove
848849
849850 read_success , android_log_lines = read_file (ANDROID_LOG_FILE_NAME )
850851 if not read_success :
@@ -867,22 +868,27 @@ def main():
867868 set_oss_name_by_repository ()
868869 if analyze_source :
869870 from ._src_analysis import find_item_to_analyze
870- final_bin_info = find_item_to_analyze (final_bin_info , python_script_dir , now , path_to_exclude )
871-
871+ final_bin_info = find_item_to_analyze (final_bin_info , python_script_dir , now , path_to_exclude )
872+
873+ num_of_notice_file , destination_file = create_and_move_notice_zip (notice_files , result_notice_zip_file_name , python_script_dir )
874+
872875 scan_item = ScannerItem (PKG_NAME , now )
873876 scan_item .set_cover_pathinfo (android_src_path , "" )
874877
875878 scan_item .set_cover_comment (f"Total number of binaries: { len (final_bin_info )} " )
876- scan_item .set_cover_comment (f"\n Notice: { notice_files } " )
879+ if num_of_notice_file == 0 :
880+ logger .info (f"There is no notice file at all." )
881+ scan_item .set_cover_comment (f"\n There is no notice file at all." )
882+ else :
883+ logger .info (f"Notice file to upload FOSSLight Hub: { destination_file } " )
884+ scan_item .set_cover_comment (f"\n Notice file to upload FOSSLight Hub: { destination_file } " )
885+
877886 scan_item .append_file_items (final_bin_info , PKG_NAME )
878887 success , msg , result_file = write_output_file (result_excel_file_name , RESULT_FILE_EXTENSION ,
879888 scan_item , HEADER , HIDDEN_HEADER )
880889 if not success :
881890 logger .warning (f"Failed to write result to excel:{ msg } " )
882- result_log ["Output FOSSLight Report" ] = f"{ result_file } "
883-
884- if _create_additial_notice :
885- create_additional_notice (final_bin_info , python_script_dir )
891+ result_log ["Output FOSSLight Report" ] = f"{ result_file } "
886892
887893 # Print the result
888894 result_log ["Output Directory" ] = python_script_dir
0 commit comments