Skip to content

Commit a81b042

Browse files
authored
Merge pull request #95 from SeongjunJo/exclude_path
Supports for excluding paths from analysis
2 parents 1692f3c + 85cebc4 commit a81b042

File tree

7 files changed

+42
-21
lines changed

7 files changed

+42
-21
lines changed

README.md

+12-2
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ Options:
8080
* Compare mode result file: supports excel, json, yaml, html
8181
-o <output> Output directory or file
8282
-c <number> Number of processes to analyze source
83+
-e <path> Path to exclude from analysis (ex, -e {dir} {file})
8384
-r Keep raw data
8485
-t Hide the progress bar
8586
-v Print FOSSLight Scanner version
@@ -96,12 +97,21 @@ Options:
9697
$ fosslight all -p /home/source_path -d "-a 'source /test/Projects/venv/bin/activate' -d 'deactivate'"
9798
```
9899

99-
### Ex 2. Download Link and analyze
100+
### Ex 2. Local Source Analysis with Path to Exclude
101+
```
102+
$ fosslight all -p /home/source_path -e temp_dir src/temp.py
103+
```
104+
105+
### Ex 3. Download Link and analyze
100106
```
101107
$ fosslight all -o test_result_wget -w "https://github.com/LGE-OSS/example.git"
102108
```
109+
If you want to analyze private repository, set your github token like below.
110+
```
111+
$ fosslight all -w "https://[email protected]/Foo/private_repo
112+
```
103113

104-
### Ex 3. Compare the BOM of two FOSSLight reports with yaml or excel format and check the oss status (change/add/delete)
114+
### Ex 4. Compare the BOM of two FOSSLight reports with yaml or excel format and check the oss status (change/add/delete)
105115
```
106116
$ fosslight compare -p FOSSLight_before_proj.yaml FOSSLight_after_proj.yaml -f excel
107117
```

requirements.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ openpyxl
44
progress
55
pyyaml
66
beautifulsoup4
7-
fosslight_util>=1.4.44
8-
fosslight_source>=1.7.7
9-
fosslight_dependency>=3.15.0
10-
fosslight_binary>=4.1.29
7+
fosslight_util>=1.4.45
8+
fosslight_source>=1.7.8
9+
fosslight_dependency>=3.15.1
10+
fosslight_binary>=4.1.30
1111
fosslight_prechecker>=3.0.27

src/fosslight_scanner/_help.py

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
-w <link>\t\t Link to be analyzed can be downloaded by wget or git clone
2828
-f <format>\t\t FOSSLight Report file format (excel, yaml)
2929
* Compare mode result file: supports excel, json, yaml, html
30+
-e <path>\t\t Path to exclude from analysis (ex, -e {dir} {file})
3031
-o <output>\t\t Output directory or file
3132
-c <number>\t\t Number of processes to analyze source
3233
-r\t\t\t Keep raw data

src/fosslight_scanner/cli.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def main():
2525
parser.add_argument('--timer', '-t', help='Hide the progress bar', action='store_true', dest='timer', default=False)
2626
parser.add_argument('--version', '-v', help='Print version', action='store_true', dest='version', default=False)
2727
parser.add_argument('--help', '-h', help='Print help message', action='store_true', dest='help')
28+
parser.add_argument('--exclude', '-e', help='Path to exclude from analysis', dest='exclude_path', nargs='*', default=[])
2829
parser.add_argument('--no_correction', help='No correction with sbom-info.yaml',
2930
action='store_true', required=False, default=False)
3031
parser.add_argument('--correct_fpath', help='Path to the sbom-info.yaml',
@@ -45,7 +46,7 @@ def main():
4546
args.mode = ['all']
4647
run_main(args.mode, args.path, args.dep_argument, args.output, args.format,
4748
args.link, args.db_url, args.timer, args.raw, args.core,
48-
not args.no_correction, args.correct_fpath, args.ui)
49+
not args.no_correction, args.correct_fpath, args.ui, args.exclude_path)
4950

5051

5152
if __name__ == "__main__":

src/fosslight_scanner/common.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,15 @@ def run_analysis(path_to_run, params, func, str_run_start, output, exe_path):
6262
return return_value
6363

6464

65-
def call_analysis_api(path_to_run, str_run_start, return_idx, func, *args):
65+
def call_analysis_api(path_to_run, str_run_start, return_idx, func, *args, **kwargs):
6666
# return_idx == -1 : Raw return value itself
6767
logger.info(f"## Start to run {str_run_start}")
6868
success = True
6969
result = []
7070
try:
7171
if path_to_run != "":
7272
logger.info(f"|--- Path to analyze : {path_to_run}")
73-
result = func(*args)
73+
result = func(*args, **kwargs)
7474
else:
7575
logger.info("Analyzing path is missing...")
7676
except SystemExit:

src/fosslight_scanner/fosslight_scanner.py

+18-12
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
SCANNER_MODE = ["all", "compare", "reuse", "prechecker", "binary", "bin", "src", "source", "dependency", "dep"]
4949

5050

51-
def run_dependency(path_to_analyze, output_file_with_path, params=""):
51+
def run_dependency(path_to_analyze, output_file_with_path, params="", path_to_exclude=[]):
5252
result_list = []
5353

5454
package_manager = ""
@@ -90,7 +90,7 @@ def run_dependency(path_to_analyze, output_file_with_path, params=""):
9090
output_file_with_path,
9191
pip_activate_cmd, pip_deactivate_cmd,
9292
output_custom_dir, app_name,
93-
github_token)
93+
github_token, path_to_exclude=path_to_exclude)
9494
if success:
9595
result_list = result.get('SRC_FL_Dependency')
9696
except Exception as ex:
@@ -106,7 +106,7 @@ def run_scanner(src_path, dep_arguments, output_path, keep_raw_data=False,
106106
remove_src_data=True, result_log={}, output_file="",
107107
output_extension="", num_cores=-1, db_url="",
108108
default_oss_name="", default_oss_version="", url="",
109-
correct_mode=True, correct_fpath="", ui_mode=False):
109+
correct_mode=True, correct_fpath="", ui_mode=False, path_to_exclude=[]):
110110
final_excel_dir = output_path
111111
success = True
112112
temp_output_fiiles = []
@@ -136,8 +136,8 @@ def run_scanner(src_path, dep_arguments, output_path, keep_raw_data=False,
136136
output_prechecker = os.path.join(_output_dir, output_files["PRECHECKER"])
137137
success, result = call_analysis_api(src_path, "Prechecker Lint",
138138
-1, prechecker_lint,
139-
abs_path, False,
140-
output_prechecker)
139+
abs_path, False, output_prechecker,
140+
exclude_path=path_to_exclude)
141141
success_file, copied_file = copy_file(output_prechecker, output_path)
142142
if success_file:
143143
temp_output_fiiles.append(copied_file)
@@ -150,12 +150,15 @@ def run_scanner(src_path, dep_arguments, output_path, keep_raw_data=False,
150150
-1, source_analysis,
151151
abs_path,
152152
src_output,
153-
False, num_cores, False)
153+
False, num_cores, False,
154+
path_to_exclude=path_to_exclude)
154155
else: # Run fosslight_source by using docker image
155156
src_output = os.path.join("output", output_files["SRC"])
156157
output_rel_path = os.path.relpath(abs_path, os.getcwd())
157158
command = shlex.quote(f"docker run -it -v {_output_dir}:/app/output "
158159
f"fosslight -p {output_rel_path} -o {src_output}")
160+
if path_to_exclude:
161+
command += f" -e {' '.join(path_to_exclude)}"
159162
command_result = subprocess.run(command, stdout=subprocess.PIPE, text=True)
160163
logger.info(f"Source Analysis Result:{command_result.stdout}")
161164

@@ -168,7 +171,8 @@ def run_scanner(src_path, dep_arguments, output_path, keep_raw_data=False,
168171
abs_path,
169172
os.path.join(_output_dir, output_files["BIN"]),
170173
"", db_url, False,
171-
correct_mode, correct_fpath)
174+
correct_mode, correct_fpath,
175+
path_to_exclude=path_to_exclude)
172176
if success:
173177
output_binary_txt_raw = f"{output_files['BIN'].split('.')[0]}.txt"
174178
success_file, copied_file = copy_file(os.path.join(_output_dir, output_binary_txt_raw),
@@ -177,7 +181,7 @@ def run_scanner(src_path, dep_arguments, output_path, keep_raw_data=False,
177181
temp_output_fiiles.append(copied_file)
178182

179183
if run_dep:
180-
run_dependency(src_path, os.path.join(_output_dir, output_files["DEP"]), dep_arguments)
184+
run_dependency(src_path, os.path.join(_output_dir, output_files["DEP"]), dep_arguments, path_to_exclude)
181185

182186
else:
183187
return
@@ -191,7 +195,8 @@ def run_scanner(src_path, dep_arguments, output_path, keep_raw_data=False,
191195
merge_files = [output_files["SRC"], output_files["BIN"], output_files["DEP"]]
192196
cover = CoverItem(tool_name=PKG_NAME,
193197
start_time=_start_time,
194-
input_path=abs_path)
198+
input_path=abs_path,
199+
exclude_path=path_to_exclude)
195200
cover.comment = merge_cover_comment(_output_dir, merge_files)
196201

197202
if output_extension == ".xlsx":
@@ -307,8 +312,9 @@ def init(output_path="", make_outdir=True):
307312
return os.path.isdir(_output_dir), output_root_dir, result_log
308313

309314

310-
def run_main(mode_list, path_arg, dep_arguments, output_file_or_dir, file_format, url_to_analyze, db_url,
311-
hide_progressbar=False, keep_raw_data=False, num_cores=-1, correct_mode=True, correct_fpath="", ui_mode=False):
315+
def run_main(mode_list, path_arg, dep_arguments, output_file_or_dir, file_format, url_to_analyze,
316+
db_url, hide_progressbar=False, keep_raw_data=False, num_cores=-1,
317+
correct_mode=True, correct_fpath="", ui_mode=False, path_to_exclude=[]):
312318
global _executed_path, _start_time
313319

314320
output_file = ""
@@ -417,7 +423,7 @@ def run_main(mode_list, path_arg, dep_arguments, output_file_or_dir, file_format
417423
remove_downloaded_source, {}, output_file,
418424
output_extension, num_cores, db_url,
419425
default_oss_name, default_oss_version, url_to_analyze,
420-
correct_mode, correct_fpath, ui_mode)
426+
correct_mode, correct_fpath, ui_mode, path_to_exclude)
421427
else:
422428
logger.error("No mode has been selected for analysis.")
423429
try:

tox.ini

+3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ norecursedirs = test_result_*
2525
[testenv:test_run]
2626
commands =
2727
rm -rf test_result_local_path
28+
rm -rf test_result_exclude_path
2829
rm -rf test_result_wget
2930
fosslight -o test_result_local_path/test.xlsx -p tests -r
3031
fosslight binary source -o test_result_multi_mode/test.xlsx -p tests -r
32+
fosslight -o test_result_exclude_path/test.xlsx -p tests -e test sample_license.txt
3133
fosslight dependency -o test_result_wget -w "https://github.com/LGE-OSS/example.git"
3234
ls test_result_wget
3335

@@ -39,5 +41,6 @@ commands =
3941
fosslight -h
4042
fosslight all -o test_result_local_path/test.xlsx -p tests -r
4143
fosslight binary dependency -o test_result_multi_mode/test.xlsx -p tests -r
44+
fosslight -o test_result_exclude_path/test.xlsx -p tests -e test sample_license.txt
4245
fosslight source -o test_result_wget -w "https://github.com/LGE-OSS/example.git"
4346
pytest -v --flake8

0 commit comments

Comments
 (0)