Skip to content

Commit 6f269b8

Browse files
authored
Merge pull request #85 from fosslight/multiple
Supports multiple input modes
2 parents 1120edd + 1e3f77c commit 6f269b8

File tree

2 files changed

+54
-37
lines changed

2 files changed

+54
-37
lines changed

src/fosslight_scanner/_help.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
Usage: fosslight [Mode] [option1] <arg1> [option2] <arg2>...
1313
1414
Parameters:
15-
Mode
15+
Mode: Multiple modes can be entered by separating them with , (ex. source,binary)
1616
all\t\t\t Run all scanners(Default)
1717
source\t\t Run FOSSLight Source Scanner
1818
dependency\t\t Run FOSSLight Dependency Scanner

src/fosslight_scanner/fosslight_scanner.py

Lines changed: 53 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
_start_time = ""
4545
_executed_path = ""
4646
SRC_DIR_FROM_LINK_PREFIX = "fosslight_src_dir_"
47+
SCANNER_MODE = ["compare", "reuse", "prechecker", "binary", "bin", "src", "source", "dependency", "dep"]
4748

4849

4950
def run_dependency(path_to_analyze, output_file_with_path, params=""):
@@ -352,48 +353,64 @@ def run_main(mode, path_arg, dep_arguments, output_file_or_dir, file_format, url
352353
run_dep = False
353354
run_prechecker = False
354355
remove_downloaded_source = False
356+
mode_list = []
355357

356-
if mode == "prechecker" or mode == "reuse":
357-
run_prechecker = True
358-
elif mode == "binary" or mode == "bin":
359-
run_bin = True
360-
elif mode == "source" or mode == "src":
361-
run_src = True
362-
elif mode == "dependency" or mode == "dep":
363-
run_dep = True
364-
else:
358+
if mode:
359+
mode_list = mode.split(',')
360+
mode_list = [item.strip() for item in mode_list]
361+
362+
if "compare" in mode_list:
363+
logger.error("Compare mode cannot be run together with other modes.")
364+
sys.exit(1)
365+
elif "all" in mode_list or (not mode):
365366
run_src = True
366367
run_bin = True
367368
run_dep = True
368369
run_prechecker = True
369-
370-
if src_path == "" and url_to_analyze == "":
371-
src_path, dep_arguments, url_to_analyze = get_input_mode(_executed_path, mode)
372-
373-
if not hide_progressbar:
374-
timer = TimerThread()
375-
timer.setDaemon(True)
376-
timer.start()
377-
378-
if url_to_analyze != "":
379-
remove_downloaded_source = True
380-
default_oss_name = extract_name_from_link(url_to_analyze)
381-
success, src_path = download_source(url_to_analyze, output_path)
382-
383-
if output_extension == ".yaml":
384-
correct_mode = False
385-
correct_fpath = ""
386370
else:
387-
if not correct_fpath:
388-
correct_fpath = src_path
389-
390-
if src_path != "":
391-
run_scanner(src_path, dep_arguments, output_path, keep_raw_data,
392-
run_src, run_bin, run_dep, run_prechecker,
393-
remove_downloaded_source, {}, output_file,
394-
output_extension, num_cores, db_url,
395-
default_oss_name, url_to_analyze,
396-
correct_mode, correct_fpath, ui_mode)
371+
if "prechecker" in mode_list or "reuse" in mode_list:
372+
run_prechecker = True
373+
if "binary" in mode_list or "bin" in mode_list:
374+
run_bin = True
375+
if "source" in mode_list or "src" in mode_list:
376+
run_src = True
377+
if "dependency" in mode_list or "dep" in mode_list:
378+
run_dep = True
379+
mode_not_supported = list(set(mode_list).difference(SCANNER_MODE))
380+
if len(mode_not_supported) > 0:
381+
logger.error(f"An unsupported mode was entered.:{mode_not_supported}")
382+
sys.exit(1)
383+
384+
if run_dep or run_src or run_bin or run_prechecker:
385+
if src_path == "" and url_to_analyze == "":
386+
src_path, dep_arguments, url_to_analyze = get_input_mode(_executed_path, mode)
387+
388+
if not hide_progressbar:
389+
timer = TimerThread()
390+
timer.setDaemon(True)
391+
timer.start()
392+
393+
if url_to_analyze != "":
394+
remove_downloaded_source = True
395+
default_oss_name = extract_name_from_link(url_to_analyze)
396+
success, src_path = download_source(url_to_analyze, output_path)
397+
398+
if output_extension == ".yaml":
399+
correct_mode = False
400+
correct_fpath = ""
401+
else:
402+
if not correct_fpath:
403+
correct_fpath = src_path
404+
405+
if src_path != "":
406+
run_scanner(src_path, dep_arguments, output_path, keep_raw_data,
407+
run_src, run_bin, run_dep, run_prechecker,
408+
remove_downloaded_source, {}, output_file,
409+
output_extension, num_cores, db_url,
410+
default_oss_name, url_to_analyze,
411+
correct_mode, correct_fpath, ui_mode)
412+
else:
413+
logger.error("No mode has been selected for analysis.")
397414
try:
398415
if not keep_raw_data:
399416
logger.debug(f"Remove temporary files: {_output_dir}")

0 commit comments

Comments
 (0)