Skip to content

Commit 6841eaa

Browse files
committed
Refactoring related to FOSSLight Util
1 parent fc6e620 commit 6841eaa

File tree

4 files changed

+30
-79
lines changed

4 files changed

+30
-79
lines changed

requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
fosslight_util~=1.4.40
2-
fosslight_source~=1.6.16
3-
fosslight_binary~=4.1.3
1+
fosslight_util~=2.0.0
2+
fosslight_source~=2.0.0
3+
fosslight_binary~=5.0.0
44
beautifulsoup4
55
lxml
66
numpy

src/fosslight_android/_common.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def set_oss_name(self, value):
9797
def set_oss_version(self, value):
9898
self.oss_version = value
9999

100-
def get_print_items(self):
100+
def get_print_array(self, return_excel=True):
101101
print_items_txt = []
102102
print_items_excel = []
103103
oss_name = self.oss_name
@@ -125,7 +125,10 @@ def get_print_items(self):
125125
excel_item.extend(item.split('\t'))
126126
excel_item.extend(['', '', '', '', '', comment, need_check, self.tlsh, self.checksum])
127127
print_items_excel.append(excel_item)
128-
return print_items_txt, print_items_excel
128+
if return_excel:
129+
return print_items_excel
130+
else:
131+
return print_items_txt
129132

130133

131134
def check_empty_column(license, oss_name, directory):

src/fosslight_android/_write_excel.py

Lines changed: 0 additions & 62 deletions
This file was deleted.

src/fosslight_android/android_binary_analysis.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import numpy as np
2424
from functools import partial
2525
from fosslight_util.set_log import init_log
26-
from ._write_excel import write_result
2726
from ._util import (
2827
read_file,
2928
write_txt_file,
@@ -54,7 +53,8 @@
5453
from fosslight_binary.binary_analysis import return_bin_only
5554
import argparse
5655
from 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

5959
EXCEPTIONAL_PATH = [r"(/)+gen/META/lic_intermediates/"]
6060
android_log_lines = []
@@ -74,6 +74,11 @@
7474
ANDROID_LOG_FILE_NAME = "android.log"
7575
num_cores = 1
7676
now = ""
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
7984
repositories = {}
@@ -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"\nNotice: {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"\nNotice: {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

Comments
 (0)