Skip to content

Commit 8424c1c

Browse files
committed
Add dependency recursive mode
Signed-off-by: 석지영/책임연구원/SW공학(연)Open Source TP <[email protected]>
1 parent ea7fed7 commit 8424c1c

File tree

6 files changed

+31
-20
lines changed

6 files changed

+31
-20
lines changed

src/fosslight_scanner/_help.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,14 @@
4040
--no_correction\t Enter if you don't want to correct OSS information with sbom-info.yaml
4141
* Correction mode only supported xlsx format.
4242
--correct_fpath <path> Path to the sbom-info.yaml file
43-
--ui\t\t\t Generate UI mode result file
43+
--ui\t\t Generate UI mode result file
44+
--recursive_dep\t Recursively analyze dependencies
4445
4546
Options for only 'all' or 'bin' mode
4647
-u <db_url>\t\t DB Connection(format :'postgresql://username:password@host:port/database_name')
4748
4849
Options for only 'all' or 'dependency' mode
49-
-d <dependency_argument>\t Additional arguments for running dependency analysis"""
50+
-d <dependency_arg>\t Additional arguments for running dependency analysis"""
5051

5152

5253
def print_help_msg():

src/fosslight_scanner/_parse_setting.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ def parse_setting_json(data):
2525
source_print_matched_text = data.get('source_print_matched_text', False)
2626
source_time_out = data.get('source_time_out', 120)
2727
binary_simple = data.get('binary_simple', False)
28+
recursive_dep = data.get('recursive_dep', False)
2829
str_lists = [mode, path, exclude_path]
2930
strings = [
3031
dep_argument, output, format, db_url,
3132
correct_fpath, link, selected_source_scanner
3233
]
33-
booleans = [timer, raw, no_correction, ui, source_write_json_file, source_print_matched_text, binary_simple]
34+
booleans = [timer, raw, no_correction, ui, source_write_json_file, source_print_matched_text, binary_simple, recursive_dep]
3435

3536
is_incorrect = False
3637

@@ -65,4 +66,4 @@ def parse_setting_json(data):
6566
return mode, path, dep_argument, output, format, link, db_url, timer, \
6667
raw, core, no_correction, correct_fpath, ui, exclude_path, \
6768
selected_source_scanner, source_write_json_file, source_print_matched_text, source_time_out, \
68-
binary_simple
69+
binary_simple, recursive_dep

src/fosslight_scanner/cli.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515

1616

1717
def set_args(mode, path, dep_argument, output, format, link, db_url, timer,
18-
raw, core, no_correction, correct_fpath, ui, setting, exclude_path):
18+
raw, core, no_correction, correct_fpath, ui, setting, exclude_path,
19+
recursive_dep):
1920

2021
selected_source_scanner = "all"
2122
source_write_json_file = False
@@ -30,7 +31,7 @@ def set_args(mode, path, dep_argument, output, format, link, db_url, timer,
3031
s_mode, s_path, s_dep_argument, s_output, s_format, s_link, s_db_url, s_timer, s_raw, s_core, \
3132
s_no_correction, s_correct_fpath, s_ui, s_exclude_path, \
3233
s_selected_source_scanner, s_source_write_json_file, s_source_print_matched_text, \
33-
s_source_time_out, s_binary_simple = parse_setting_json(data)
34+
s_source_time_out, s_binary_simple, s_recursive_dep = parse_setting_json(data)
3435

3536
# direct cli arguments have higher priority than setting file
3637
mode = mode or s_mode
@@ -47,6 +48,7 @@ def set_args(mode, path, dep_argument, output, format, link, db_url, timer,
4748
correct_fpath = correct_fpath or s_correct_fpath
4849
ui = ui or s_ui
4950
exclude_path = exclude_path or s_exclude_path
51+
recursive_dep = recursive_dep or s_recursive_dep
5052

5153
# These options are only set from the setting file, not from CLI arguments
5254
selected_source_scanner = s_selected_source_scanner or selected_source_scanner
@@ -60,7 +62,7 @@ def set_args(mode, path, dep_argument, output, format, link, db_url, timer,
6062
return mode, path, dep_argument, output, format, link, db_url, timer, \
6163
raw, core, no_correction, correct_fpath, ui, exclude_path, \
6264
selected_source_scanner, source_write_json_file, source_print_matched_text, source_time_out, \
63-
binary_simple
65+
binary_simple, recursive_dep
6466

6567

6668
def main():
@@ -79,7 +81,7 @@ def main():
7981
type=str, dest='format',nargs='*', default=[])
8082
parser.add_argument('--output', '-o', help='Output directory or file',
8183
type=str, dest='output', default="")
82-
parser.add_argument('--dependency', '-d', help='Dependency arguments',
84+
parser.add_argument('--dependency', '-d', help='Dependency arguments (e.g. -d "-m pip" )',
8385
type=str, dest='dep_argument', default="")
8486
parser.add_argument('--url', '-u', help="DB Url",
8587
type=str, dest='db_url', default="")
@@ -105,6 +107,8 @@ def main():
105107
type=str, required=False, default='')
106108
parser.add_argument('--ui', help='Generate UI mode result file',
107109
action='store_true', required=False, default=False)
110+
parser.add_argument('--recursive_dep', '-rd', help='Recursively analyze dependencies',
111+
action='store_true', dest='recursive_dep', default=False)
108112

109113
try:
110114
args = parser.parse_args()
@@ -118,16 +122,16 @@ def main():
118122
else:
119123
mode, path, dep_argument, output, format, link, db_url, timer, raw, core, no_correction, correct_fpath, \
120124
ui, exclude_path, selected_source_scanner, source_write_json_file, source_print_matched_text, \
121-
source_time_out, binary_simple, = set_args(
125+
source_time_out, binary_simple, recursive_dep = set_args(
122126
args.mode, args.path, args.dep_argument, args.output,
123127
args.format, args.link, args.db_url, args.timer, args.raw,
124128
args.core, args.no_correction, args.correct_fpath, args.ui,
125-
args.setting, args.exclude_path)
129+
args.setting, args.exclude_path, args.recursive_dep)
126130

127131
run_main(mode, path, dep_argument, output, format, link, db_url, timer,
128132
raw, core, not no_correction, correct_fpath, ui, exclude_path,
129133
selected_source_scanner, source_write_json_file, source_print_matched_text,
130-
source_time_out, binary_simple)
134+
source_time_out, binary_simple, recursive_dep)
131135

132136

133137
if __name__ == "__main__":

src/fosslight_scanner/fosslight_scanner.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@
5757
]
5858

5959

60-
def run_dependency(path_to_analyze, output_file_with_path, params="", path_to_exclude=[], formats=[]):
60+
def run_dependency(path_to_analyze, output_file_with_path, params="", path_to_exclude=[], formats=[],
61+
recursive_dep=False):
6162
result = []
6263

6364
package_manager = ""
@@ -100,7 +101,9 @@ def run_dependency(path_to_analyze, output_file_with_path, params="", path_to_ex
100101
output_file_with_path,
101102
pip_activate_cmd, pip_deactivate_cmd,
102103
output_custom_dir, app_name,
103-
github_token, formats, True, path_to_exclude=path_to_exclude
104+
github_token, formats, True, path_to_exclude=path_to_exclude,
105+
graph_path="", graph_size=(600,600),
106+
recursive=recursive_dep
104107
)
105108
if success:
106109
result = scan_item
@@ -131,7 +134,7 @@ def run_scanner(src_path, dep_arguments, output_path, keep_raw_data=False,
131134
default_oss_name="", default_oss_version="", url="",
132135
correct_mode=True, correct_fpath="", ui_mode=False, path_to_exclude=[],
133136
selected_source_scanner="all", source_write_json_file=False, source_print_matched_text=False,
134-
source_time_out=120, binary_simple=False, formats=[]):
137+
source_time_out=120, binary_simple=False, formats=[], recursive_dep=False):
135138
final_excel_dir = output_path
136139
success = True
137140
all_cover_items = []
@@ -232,7 +235,8 @@ def run_scanner(src_path, dep_arguments, output_path, keep_raw_data=False,
232235

233236
if run_dep:
234237
dep_scanitem = run_dependency(src_path, _output_dir,
235-
dep_arguments, path_to_exclude, formats)
238+
dep_arguments, path_to_exclude, formats,
239+
recursive_dep)
236240
all_scan_item.file_items.update(dep_scanitem.file_items)
237241
all_cover_items.append(dep_scanitem.cover)
238242
else:
@@ -359,7 +363,7 @@ def run_main(mode_list, path_arg, dep_arguments, output_file_or_dir, file_format
359363
db_url, hide_progressbar=False, keep_raw_data=False, num_cores=-1,
360364
correct_mode=True, correct_fpath="", ui_mode=False, path_to_exclude=[],
361365
selected_source_scanner="all", source_write_json_file=False, source_print_matched_text=False,
362-
source_time_out=120, binary_simple=False):
366+
source_time_out=120, binary_simple=False, recursive_dep=False):
363367
global _executed_path, _start_time
364368

365369
output_files = []
@@ -470,7 +474,7 @@ def run_main(mode_list, path_arg, dep_arguments, output_file_or_dir, file_format
470474
default_oss_name, default_oss_version, url_to_analyze,
471475
correct_mode, correct_fpath, ui_mode, path_to_exclude,
472476
selected_source_scanner, source_write_json_file, source_print_matched_text, source_time_out,
473-
binary_simple, formats)
477+
binary_simple, formats, recursive_dep)
474478

475479
if extract_folder:
476480
shutil.rmtree(extract_folder)

tests/test__parse_setting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ def test_parse_setting_json_valid_data():
3131
result = parse_setting_json(data)
3232
assert result == (
3333
['test'], ['/some/path'], 'arg', 'output', 'json', 'http://example.com', 'sqlite:///:memory:', True,
34-
True, 4, True, '/correct/path', True, ['/exclude/path'], 'scanner', True, True, 60, True
34+
True, 4, True, '/correct/path', True, ['/exclude/path'], 'scanner', True, True, 60, True, False
3535
)

tests/test_cli.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,14 @@ def mock_open(*args, **kwargs):
4545
# Call the function with some arguments
4646
result = set_args(
4747
mode=None, path=None, dep_argument=None, output=None, format=None, link=None, db_url=None, timer=None,
48-
raw=None, core=-1, no_correction=None, correct_fpath=None, ui=None, setting="dummy_path", exclude_path=None
48+
raw=None, core=-1, no_correction=None, correct_fpath=None, ui=None, setting="dummy_path", exclude_path=None,
49+
recursive_dep=False
4950
)
5051

5152
# Expected result
5253
expected = (
5354
["test_mode"], ["test_path"], "test_dep_argument", "test_output", ["test_format"], "test_link", "test_db_url", True,
54-
True, 4, True, "test_correct_fpath", True, ["test_exclude_path"], "test_scanner", True, True, 100, True
55+
True, 4, True, "test_correct_fpath", True, ["test_exclude_path"], "test_scanner", True, True, 100, True, False
5556
)
5657

5758
assert result == expected

0 commit comments

Comments
 (0)