Skip to content

Commit 9eb6fa2

Browse files
authored
Merge pull request #11 from fosslight/exclude
Add paths to exclude from source analysis
2 parents 55c6e87 + dd4c418 commit 9eb6fa2

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

src/fosslight_android/_help.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
Optional
2020
-h\t\t\t\t Print help message
2121
-m\t\t\t\t Analyze the source code for the path where the license could not be found.
22+
-e <path1> <path2..>\t Path to exclude from source analysis.
2223
-p\t\t\t\t Check files that should not be included in the Packaging file.
2324
-f\t\t\t\t Print result of Find Command for binary that can not find Source Code Path.
2425
-t\t\t\t\t Collect NOTICE for binaries that are not added to NOTICE.html.

src/fosslight_android/_src_analysis.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
ANALYSIS_OUTPUT_DIR = "source_analyzed"
1414

1515

16-
def find_item_to_analyze(bin_info, output_path, start_time=""):
17-
logger.info("* START TO ANALYZE SOURCE")
16+
def find_item_to_analyze(bin_info, output_path, start_time="", path_to_exclude=[]):
1817
path_list_to_analyze = {}
1918
for item in bin_info:
2019
try:
@@ -25,15 +24,25 @@ def find_item_to_analyze(bin_info, output_path, start_time=""):
2524
except Exception as error:
2625
logger.debug(f"Find_item_to_analyze:{error}")
2726

28-
logger.info(f"|--Source analysis begins for {len(path_list_to_analyze)} paths.")
29-
idx = 0
27+
source_analysis_path = [path for path in path_list_to_analyze.keys() if path not in path_to_exclude]
28+
logger.info(f"|--Source analysis for {len(source_analysis_path)} paths.")
29+
for path in source_analysis_path:
30+
file_array = [len(files) for r, d, files in os.walk(path)]
31+
files = sum(file_array)
32+
logger.info(f"{path}, File Count:{files}")
33+
3034
output_dir = os.path.join(output_path, f"{ANALYSIS_OUTPUT_DIR}_{start_time}")
31-
for source_path in path_list_to_analyze.keys():
35+
36+
logger.info("------------------------------")
37+
logger.info("* START TO ANALYZE SOURCE *")
38+
idx = 0
39+
for source_path in source_analysis_path:
3240
try:
3341
idx += 1
34-
logger.info(f"|---{idx} {source_path}")
35-
license = run_src_analysis(source_path, start_time, output_dir)
36-
path_list_to_analyze[source_path] = license
42+
if os.path.isdir(source_path):
43+
logger.info(f"({idx}){source_path}")
44+
license = run_src_analysis(source_path, start_time, output_dir)
45+
path_list_to_analyze[source_path] = license
3746
except Exception as error:
3847
logger.debug(f"Failed to run src analysis:{error}")
3948

src/fosslight_android/android_binary_analysis.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,7 @@ def main():
761761
auto_fill_oss_name = True
762762
_NOTICE_CHECKLIST_TYPE = False
763763
analyze_source = False
764+
path_to_exclude = []
764765

765766
num_cores = multiprocessing.cpu_count() - 1
766767
if num_cores < 1:
@@ -788,6 +789,7 @@ def main():
788789
parser.add_argument('-p', '--packaging', type=str, required=False)
789790
parser.add_argument('-d', '--divide', type=str, required=False)
790791
parser.add_argument('-r', '--remove', type=str, required=False)
792+
parser.add_argument('-e', '--exclude', nargs="*", required=False, default=[])
791793

792794
args = parser.parse_args()
793795
if args.help:
@@ -813,6 +815,8 @@ def main():
813815
find_empty_path = True
814816
if args.ignore: # Disable the function to automatically convert OSS names based on AOSP.
815817
auto_fill_oss_name = False
818+
if args.exclude: # Path to exclude from source code analysis.
819+
path_to_exclude = args.exclude
816820

817821
logger, result_log = init_log(log_txt_file, True, logging.INFO, logging.DEBUG, PKG_NAME)
818822

@@ -850,7 +854,7 @@ def main():
850854
set_oss_name_by_repository()
851855
if analyze_source:
852856
from ._src_analysis import find_item_to_analyze
853-
final_bin_info = find_item_to_analyze(final_bin_info, python_script_dir, now)
857+
final_bin_info = find_item_to_analyze(final_bin_info, python_script_dir, now, path_to_exclude)
854858

855859
write_result_to_txt_and_excel(result_excel_file, final_bin_info, result_txt_file)
856860
result_log["Output FOSSLight Report"] = result_excel_file

0 commit comments

Comments
 (0)