Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 19 additions & 46 deletions src/fosslight_android/android_binary_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
get_path_by_using_find
)
from .check_package_file import check_packaging_files
from .check_notice_file import (
run_notice_html_checklist,
from .check_notice_file import (
run_notice_html_checklist,
find_bin_in_notice,
read_notice_file,
create_additional_notice,
divide_notice_files_by_binary
divide_notice_files_by_binary
)
from ._binary_db_controller import get_oss_info_from_db
from ._common import (
Expand Down Expand Up @@ -72,7 +72,6 @@
platform_version = "" # Android Version. ex- 7.0.0.r1 -> 7.0

# Define Const Variables
NOTICE_HTML_FILE_NAME = ""
ANDROID_LOG_FILE_NAME = "android.log"
num_cores = 1
now = ""
Expand Down Expand Up @@ -343,7 +342,7 @@ def find_notice_value(notice_zip_dest_file=""):
notice_file_comment = "Notice file not found."

try:
notice_file_list, notice_files = read_notice_file(os.path.abspath(build_out_notice_file_path), NOTICE_HTML_FILE_NAME)
notice_file_list, notice_files = read_notice_file(os.path.abspath(build_out_notice_file_path))
if notice_file_list:
if notice_files:
for notice_file in notice_files:
Expand Down Expand Up @@ -793,14 +792,11 @@ def create_and_copy_notice_zip(notice_files_list, zip_file_path):
return final_destination_file_name


def main():
global android_log_lines, ANDROID_LOG_FILE_NAME, NOTICE_HTML_FILE_NAME, python_script_dir, num_cores, now, logger, final_bin_info
find_empty_path = False
_create_additial_notice = False
notice_check_ok = False
base_binary_txt = ""
auto_fill_oss_name = True
_NOTICE_CHECKLIST_TYPE = False
def main():
global android_log_lines, ANDROID_LOG_FILE_NAME, python_script_dir, num_cores, now, logger, final_bin_info
find_empty_path = False
notice_check_ok = False
auto_fill_oss_name = True
analyze_source = False
path_to_exclude = []
RESULT_FILE_EXTENSION = ".xlsx"
Expand All @@ -820,17 +816,12 @@ def main():
parser = argparse.ArgumentParser(description='FOSSLight Android', prog='fosslight_android', add_help=False)
parser.add_argument('-h', '--help', action='store_true', required=False)
parser.add_argument('-v', '--version', action='store_true', required=False)
parser.add_argument('-s', '--source', type=str, required=False)
parser.add_argument('-b', '--binary', type=str, required=False)
parser.add_argument('-n', '--notice', type=str, required=False)
parser.add_argument('-t', '--toadd', action='store_true', required=False)
parser.add_argument('-m', '--more', action='store_true', required=False)
parser.add_argument('-c', '--check', type=str, required=False)
parser.add_argument('-s', '--source', type=str, required=False)
parser.add_argument('-m', '--more', action='store_true', required=False)
parser.add_argument('-a', '--android', type=str, required=False)
parser.add_argument('-f', '--find', action='store_true', required=False)
parser.add_argument('-i', '--ignore', action='store_true', required=False)
parser.add_argument('-p', '--packaging', type=str, required=False)
parser.add_argument('-d', '--divide', type=str, required=False)
parser.add_argument('-p', '--packaging', type=str, required=False)
parser.add_argument('-r', '--remove', type=str, required=False)
parser.add_argument('-e', '--exclude', nargs="*", required=False, default=[])

Expand All @@ -841,18 +832,9 @@ def main():
print_version(PKG_NAME)
if args.source: # android source path
os.chdir(args.source)
android_src_path = args.source
if args.binary: # Base model's binary.txt to exclude
base_binary_txt = args.binary
if args.notice:
NOTICE_HTML_FILE_NAME = args.notice
if args.toadd: # Create needtoadd-notice.html file.
_create_additial_notice = True
android_src_path = args.source
if args.more: # Analyze source mode.
analyze_source = True
if args.check:
_NOTICE_CHECKLIST_TYPE = True
notice_check_ok = (args.check == "ok" or args.check == "OK")
analyze_source = True
if args.android:
ANDROID_LOG_FILE_NAME = args.android
if args.find: # Execute "find" command when source path is not found.
Expand All @@ -866,17 +848,10 @@ def main():

if args.packaging:
check_packaging_files(args.packaging)
return
if args.divide:
divide_notice_files_by_binary(args.divide, python_script_dir, now)
return
return

if args.remove: # Remove the inputted list from the binary list.
remove_list_file = args.remove

if _NOTICE_CHECKLIST_TYPE:
run_notice_html_checklist(base_binary_txt, notice_check_ok, NOTICE_HTML_FILE_NAME)
return

remove_list_file = args.remove
read_success, android_log_lines = read_file(ANDROID_LOG_FILE_NAME)
if not read_success:
logger.error("(-a option) Fail to read a file:" + ANDROID_LOG_FILE_NAME)
Expand Down Expand Up @@ -913,13 +888,11 @@ def main():
logger.warning(f"Failed to write result to excel:{msg}")
result_log["Output FOSSLight Report"] = f"{result_file}"

if _create_additial_notice:
create_additional_notice(final_bin_info, python_script_dir)

# Print the result
result_log["Output Directory"] = python_script_dir
try:
str_final_result_log = yaml.safe_dump(result_log, allow_unicode=True, sort_keys=True)
#str_final_result_log = yaml.safe_dump(result_log, allow_unicode=True, sort_keys=True)
str_final_result_log = yaml.safe_dump(result_log, allow_unicode=True)
logger.info(str_final_result_log)
except Exception as ex:
logger.warning(f"Failed to print result log. : {ex}")
Expand Down
23 changes: 19 additions & 4 deletions src/fosslight_android/check_notice_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,14 @@ def find_files_by_extension(path):
return files


def read_notice_file(notice_file_path, notice_html_file):
#def read_notice_file(notice_file_path, notice_html_file):
def read_notice_file(notice_file_path):
final_notice_file = {}
# NOTICE.html need to be skipped the errors related to decode
encodings = ["latin-1", "utf-8", "utf-16"]
notice_files = []


'''
if notice_html_file != "":
notice_files = notice_html_file.split(",")
else:
Expand All @@ -114,8 +116,21 @@ def read_notice_file(notice_file_path, notice_html_file):
additional_notice_files = find_files_by_extension(notice_file_path)
if len(additional_notice_files) > 0:
notice_files.extend(additional_notice_files)
notice_files = list(set(notice_files))

notice_files = list(set(notice_files))
'''

if os.path.isfile(notice_file_path):
notice_files.append(notice_file_path)
if notice_file_path.endswith(".html") or notice_file_path.endswith(".xml") or notice_file_path.endswith(".txt"):
notice_file_path = os.path.dirname(notice_file_path)

if os.path.isdir(notice_file_path):
additional_notice_files = find_files_by_extension(notice_file_path)
if len(additional_notice_files) > 0:
notice_files.extend(additional_notice_files)
notice_files = list(set(notice_files))


for file_name in notice_files:
file_list = {}
file_content = ""
Expand Down
Loading