1010import re
1111import json
1212import logging
13- import zipfile
14- import shutil
1513# Parsing NOTICE
1614from bs4 import BeautifulSoup
1715import subprocess
7270platform_version = "" # Android Version. ex- 7.0.0.r1 -> 7.0
7371
7472# Define Const Variables
75-
73+ NOTICE_HTML_FILE_NAME = ""
7674ANDROID_LOG_FILE_NAME = "android.log"
7775num_cores = 1
7876now = ""
@@ -200,8 +198,7 @@ def set_env_variables_from_result_log():
200198 for line in android_log_lines :
201199 try :
202200 line = line .strip ()
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*' )
201+ pattern = re .compile (r'.*PLATFORM_VERSION\s*=\s*(\d+.?\d?)(.*\d*)\S*\s*' )
205202 matched = pattern .match (line )
206203 if matched is not None :
207204 platform_version = matched .group (1 )
@@ -338,8 +335,7 @@ def find_notice_value():
338335 str_notice_files = ""
339336
340337 try :
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 ))
338+ notice_file_list , notice_files = read_notice_file (os .path .abspath (build_out_notice_file_path ), NOTICE_HTML_FILE_NAME )
343339 if not notice_file_list :
344340 logger .info (f"Notice file is empty:{ notice_files } " )
345341 return
@@ -765,33 +761,16 @@ def find_meta_lic_files():
765761 if lic_list :
766762 lic = ',' .join (lic_list )
767763 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
789764
790765
791766def main ():
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
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
795774 analyze_source = False
796775 path_to_exclude = []
797776 RESULT_FILE_EXTENSION = ".xlsx"
@@ -805,18 +784,22 @@ def main():
805784 now = datetime .now ().strftime ('%y%m%d_%H%M' )
806785 log_txt_file = os .path .join (python_script_dir , f"fosslight_log_android_{ now } .txt" )
807786 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" )
809787 remove_list_file = ""
810788
811789 parser = argparse .ArgumentParser (description = 'FOSSLight Android' , prog = 'fosslight_android' , add_help = False )
812790 parser .add_argument ('-h' , '--help' , action = 'store_true' , required = False )
813791 parser .add_argument ('-v' , '--version' , action = 'store_true' , required = False )
814- parser .add_argument ('-s' , '--source' , type = str , 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 )
815796 parser .add_argument ('-m' , '--more' , action = 'store_true' , required = False )
797+ parser .add_argument ('-c' , '--check' , type = str , required = False )
816798 parser .add_argument ('-a' , '--android' , type = str , required = False )
817799 parser .add_argument ('-f' , '--find' , action = 'store_true' , required = False )
818800 parser .add_argument ('-i' , '--ignore' , action = 'store_true' , required = False )
819- parser .add_argument ('-p' , '--packaging' , type = str , required = False )
801+ parser .add_argument ('-p' , '--packaging' , type = str , required = False )
802+ parser .add_argument ('-d' , '--divide' , type = str , required = False )
820803 parser .add_argument ('-r' , '--remove' , type = str , required = False )
821804 parser .add_argument ('-e' , '--exclude' , nargs = "*" , required = False , default = [])
822805
@@ -827,9 +810,18 @@ def main():
827810 print_version (PKG_NAME )
828811 if args .source : # android source path
829812 os .chdir (args .source )
830- android_src_path = 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
831820 if args .more : # Analyze source mode.
832- analyze_source = True
821+ analyze_source = True
822+ if args .check :
823+ _NOTICE_CHECKLIST_TYPE = True
824+ notice_check_ok = (args .check == "ok" or args .check == "OK" )
833825 if args .android :
834826 ANDROID_LOG_FILE_NAME = args .android
835827 if args .find : # Execute "find" command when source path is not found.
@@ -843,9 +835,16 @@ def main():
843835
844836 if args .packaging :
845837 check_packaging_files (args .packaging )
846- return
838+ return
839+ if args .divide :
840+ divide_notice_files_by_binary (args .divide , python_script_dir , now )
841+ return
847842 if args .remove : # Remove the inputted list from the binary list.
848- remove_list_file = args .remove
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
849848
850849 read_success , android_log_lines = read_file (ANDROID_LOG_FILE_NAME )
851850 if not read_success :
@@ -868,27 +867,22 @@ def main():
868867 set_oss_name_by_repository ()
869868 if analyze_source :
870869 from ._src_analysis import find_item_to_analyze
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-
870+ final_bin_info = find_item_to_analyze (final_bin_info , python_script_dir , now , path_to_exclude )
871+
875872 scan_item = ScannerItem (PKG_NAME , now )
876873 scan_item .set_cover_pathinfo (android_src_path , "" )
877874
878875 scan_item .set_cover_comment (f"Total number of binaries: { len (final_bin_info )} " )
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-
876+ scan_item .set_cover_comment (f"\n Notice: { notice_files } " )
886877 scan_item .append_file_items (final_bin_info , PKG_NAME )
887878 success , msg , result_file = write_output_file (result_excel_file_name , RESULT_FILE_EXTENSION ,
888879 scan_item , HEADER , HIDDEN_HEADER )
889880 if not success :
890881 logger .warning (f"Failed to write result to excel:{ msg } " )
891- result_log ["Output FOSSLight Report" ] = f"{ result_file } "
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 )
892886
893887 # Print the result
894888 result_log ["Output Directory" ] = python_script_dir
0 commit comments