Skip to content

Commit 89c7d07

Browse files
authored
Merge pull request #92 from SeongjunJo/multi_mode
Supports for multiple modes
2 parents dfe56b9 + bd15f58 commit 89c7d07

File tree

5 files changed

+29
-24
lines changed

5 files changed

+29
-24
lines changed

requirements.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ progress
55
pyyaml
66
beautifulsoup4
77
fosslight_util>=1.4.44
8-
fosslight_source>=1.7.3
9-
fosslight_dependency>=3.7.4
8+
fosslight_source>=1.7.7
9+
fosslight_dependency>=3.15.0
1010
fosslight_binary>=4.1.29
11-
fosslight_prechecker>=3.0.1
11+
fosslight_prechecker>=3.0.27

src/fosslight_scanner/_get_input.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def ask_to_run(ask_msg):
2525
return return_value in return_true_item
2626

2727

28-
def get_input_mode(_executed_path, mode="all"):
28+
def get_input_mode(_executed_path, mode_list=["all"]):
2929
global _PYTHON_VERSION
3030
_PYTHON_VERSION = sys.version_info[0]
3131

@@ -40,7 +40,7 @@ def get_input_mode(_executed_path, mode="all"):
4040
else:
4141
src_path = get_input("Please enter the path to analyze:", _executed_path)
4242

43-
if mode == "all" or mode == "dependency" or mode == "dep":
43+
if "all" or "dependency" or "dep" in mode_list:
4444
dep_arguments = get_input(
4545
"Please enter arguments for dependency analysis:", "")
4646

src/fosslight_scanner/cli.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
def main():
1313
parser = ArgumentParser(description='FOSSLight Scanner', prog='fosslight_scanner', add_help=False)
14-
parser.add_argument('mode', nargs='?', help='source| dependency| binary| all| compare', default="all")
14+
parser.add_argument('mode', nargs='*', help='source| dependency| binary| all| compare', default="")
1515
parser.add_argument('--path', '-p', help='Path to analyze (In compare mode, two FOSSLight reports',
1616
dest='path', nargs='+', default="")
1717
parser.add_argument('--wget', '-w', help='Link to be analyzed', type=str, dest='link', default="")
@@ -41,6 +41,8 @@ def main():
4141
elif args.version:
4242
print_package_version(PKG_NAME, "FOSSLight Scanner Version:")
4343
else:
44+
if not args.mode:
45+
args.mode = ['all']
4446
run_main(args.mode, args.path, args.dep_argument, args.output, args.format,
4547
args.link, args.db_url, args.timer, args.raw, args.core,
4648
not args.no_correction, args.correct_fpath, args.ui)

src/fosslight_scanner/fosslight_scanner.py

+19-18
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
_start_time = ""
4646
_executed_path = ""
4747
SRC_DIR_FROM_LINK_PREFIX = "fosslight_src_dir_"
48-
SCANNER_MODE = ["compare", "reuse", "prechecker", "binary", "bin", "src", "source", "dependency", "dep"]
48+
SCANNER_MODE = ["all", "compare", "reuse", "prechecker", "binary", "bin", "src", "source", "dependency", "dep"]
4949

5050

5151
def run_dependency(path_to_analyze, output_file_with_path, params=""):
@@ -307,7 +307,7 @@ def init(output_path="", make_outdir=True):
307307
return os.path.isdir(_output_dir), output_root_dir, result_log
308308

309309

310-
def run_main(mode, path_arg, dep_arguments, output_file_or_dir, file_format, url_to_analyze, db_url,
310+
def run_main(mode_list, path_arg, dep_arguments, output_file_or_dir, file_format, url_to_analyze, db_url,
311311
hide_progressbar=False, keep_raw_data=False, num_cores=-1, correct_mode=True, correct_fpath="", ui_mode=False):
312312
global _executed_path, _start_time
313313

@@ -317,7 +317,18 @@ def run_main(mode, path_arg, dep_arguments, output_file_or_dir, file_format, url
317317
src_path = ""
318318
_executed_path = os.getcwd()
319319

320-
if mode == "compare":
320+
mode_not_supported = list(set(mode_list).difference(SCANNER_MODE))
321+
if mode_not_supported:
322+
logger.error(f"[Error]: An unsupported mode was entered.:{mode_not_supported}")
323+
sys.exit(1)
324+
if len(mode_list) > 2:
325+
logger.error("[Error]: Enter no more than two modes.")
326+
sys.exit(1)
327+
if ("compare" in mode_list) and (len(mode_list) > 1) and (mode_list != ["compare", "compare"]):
328+
logger.error("[Error]: Compare mode cannot be run together with other modes.")
329+
sys.exit(1)
330+
331+
if "compare" in mode_list:
321332
CUSTOMIZED_FORMAT = {'excel': '.xlsx', 'html': '.html', 'json': '.json', 'yaml': '.yaml'}
322333
if isinstance(path_arg, list) and len(path_arg) == 2:
323334
before_comp_f = path_arg[0]
@@ -342,7 +353,7 @@ def run_main(mode, path_arg, dep_arguments, output_file_or_dir, file_format, url
342353
logger.error(msg)
343354
sys.exit(1)
344355
try:
345-
if mode == "compare":
356+
if "compare" in mode_list:
346357
if before_comp_f == '' or after_comp_f == '':
347358
logger.error("before and after files are necessary.")
348359
return False
@@ -362,20 +373,14 @@ def run_main(mode, path_arg, dep_arguments, output_file_or_dir, file_format, url
362373
run_dep = False
363374
run_prechecker = False
364375
remove_downloaded_source = False
365-
mode_list = []
366376

367-
if mode:
368-
mode_list = mode.split(',')
369-
mode_list = [item.strip() for item in mode_list]
370-
371-
if "compare" in mode_list:
372-
logger.error("Compare mode cannot be run together with other modes.")
373-
sys.exit(1)
374-
elif "all" in mode_list or (not mode):
377+
if "all" in mode_list or (not mode_list):
375378
run_src = True
376379
run_bin = True
377380
run_dep = True
378381
run_prechecker = False
382+
if "prechecker" in mode_list or "reuse" in mode_list:
383+
run_prechecker = True
379384
else:
380385
if "prechecker" in mode_list or "reuse" in mode_list:
381386
run_prechecker = True
@@ -385,14 +390,10 @@ def run_main(mode, path_arg, dep_arguments, output_file_or_dir, file_format, url
385390
run_src = True
386391
if "dependency" in mode_list or "dep" in mode_list:
387392
run_dep = True
388-
mode_not_supported = list(set(mode_list).difference(SCANNER_MODE))
389-
if len(mode_not_supported) > 0:
390-
logger.error(f"An unsupported mode was entered.:{mode_not_supported}")
391-
sys.exit(1)
392393

393394
if run_dep or run_src or run_bin or run_prechecker:
394395
if src_path == "" and url_to_analyze == "":
395-
src_path, dep_arguments, url_to_analyze = get_input_mode(_executed_path, mode)
396+
src_path, dep_arguments, url_to_analyze = get_input_mode(_executed_path, mode_list)
396397

397398
if not hide_progressbar:
398399
timer = TimerThread()

tox.ini

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ commands =
2727
rm -rf test_result_local_path
2828
rm -rf test_result_wget
2929
fosslight -o test_result_local_path/test.xlsx -p tests -r
30+
fosslight binary source -o test_result_multi_mode/test.xlsx -p tests -r
3031
fosslight dependency -o test_result_wget -w "https://github.com/LGE-OSS/example.git"
3132
ls test_result_wget
3233

@@ -37,5 +38,6 @@ deps =
3738
commands =
3839
fosslight -h
3940
fosslight all -o test_result_local_path/test.xlsx -p tests -r
41+
fosslight binary dependency -o test_result_multi_mode/test.xlsx -p tests -r
4042
fosslight source -o test_result_wget -w "https://github.com/LGE-OSS/example.git"
4143
pytest -v --flake8

0 commit comments

Comments
 (0)