Skip to content

Commit 15c6b17

Browse files
committed
Fix the correct mode bug for yaml format
Signed-off-by: Jiyeong Seok <[email protected]>
1 parent b2a40d2 commit 15c6b17

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

src/fosslight_scanner/common.py

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,15 @@ def merge_yamls(_output_dir, merge_yaml_files, final_report, remove_src_data=Fal
201201
return success, err_msg
202202

203203

204-
def correct_scanner_result(_output_dir, output_files, exist_src, exist_bin):
204+
def correct_scanner_result(_output_dir, output_files, output_extension, exist_src, exist_bin):
205205
src_oss_list = []
206206
bin_oss_list = []
207207
duplicates = False
208208

209209
if exist_src:
210-
src_oss_list = check_exclude_dir(get_osslist_with_xlsx(_output_dir, output_files['SRC'], SRC_SHEET))
210+
src_oss_list = check_exclude_dir(get_osslist(_output_dir, output_files['SRC'], output_extension, SRC_SHEET))
211211
if exist_bin:
212-
bin_oss_list = check_exclude_dir(get_osslist_with_xlsx(_output_dir, output_files['BIN'], BIN_SHEET))
212+
bin_oss_list = check_exclude_dir(get_osslist(_output_dir, output_files['BIN'], output_extension, BIN_SHEET))
213213

214214
if exist_src and exist_bin:
215215
try:
@@ -250,11 +250,13 @@ def correct_scanner_result(_output_dir, output_files, exist_src, exist_bin):
250250

251251
try:
252252
if exist_src:
253-
success, err_msg = write_xlsx_with_osslist(src_oss_list, _output_dir, output_files['SRC'], SRC_SHEET)
253+
success, err_msg = write_output_with_osslist(src_oss_list, _output_dir, output_files['SRC'],
254+
output_extension, SRC_SHEET)
254255
if not success:
255256
logger.warning(err_msg)
256257
if exist_bin:
257-
success, err_msg = write_xlsx_with_osslist(bin_oss_list, _output_dir, output_files['BIN'], BIN_SHEET)
258+
success, err_msg = write_output_with_osslist(bin_oss_list, _output_dir, output_files['BIN'],
259+
output_extension, BIN_SHEET)
258260
if not success:
259261
logger.warning(err_msg)
260262
if duplicates:
@@ -264,28 +266,35 @@ def correct_scanner_result(_output_dir, output_files, exist_src, exist_bin):
264266
return
265267

266268

267-
def write_xlsx_with_osslist(oss_list, output_dir, output_file, sheetname):
269+
def write_output_with_osslist(oss_list, output_dir, output_file, output_extension, sheetname):
270+
new_oss_list = []
268271
sheet_list = {}
269272
sheet_list[sheetname] = []
270-
new_oss_list = []
271273

272274
for src_item in oss_list:
273275
new_oss_list.append(src_item.get_print_array()[0])
274276
sheet_list[sheetname].extend(new_oss_list)
275277
if os.path.exists(os.path.join(output_dir, output_file)):
276278
os.remove(os.path.join(output_dir, output_file))
277-
success, err_msg, result_file = write_output_file(os.path.join(output_dir, output_file).rstrip('xlsx'), '.xlsx',
278-
sheet_list)
279+
success, err_msg, _ = write_output_file(os.path.join(output_dir, output_file).rstrip(output_extension),
280+
output_extension, sheet_list)
279281
return success, err_msg
280282

281283

282-
def get_osslist_with_xlsx(_output_dir, output_file, sheet_name):
284+
def get_osslist(_output_dir, output_file, output_extension, sheet_name=''):
285+
err_reason = ''
283286
oss_list = []
284-
oss_xlsx = os.path.join(_output_dir, output_file)
285-
286-
if os.path.exists(oss_xlsx):
287-
oss_list.extend(read_oss_report(oss_xlsx, sheet_name))
287+
oss_file_with_fullpath = os.path.join(_output_dir, output_file)
288288

289+
if os.path.exists(oss_file_with_fullpath):
290+
if output_extension == '.xlsx':
291+
oss_list = read_oss_report(oss_file_with_fullpath, sheet_name)
292+
elif output_extension == '.yaml':
293+
oss_list, _, err_reason = parsing_yml(oss_file_with_fullpath, _output_dir)
294+
else:
295+
err_reason = f'Not supported extension: {output_extension}'
296+
if err_reason:
297+
logger.info(f'get_osslist: {err_reason}')
289298
return oss_list
290299

291300

src/fosslight_scanner/fosslight_scanner.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,10 @@ def run_scanner(src_path, dep_arguments, output_path, keep_raw_data=False,
148148
-1, source_analysis,
149149
abs_path,
150150
src_output,
151-
False, num_cores, True)
151+
False, num_cores)
152152
if success:
153153
sheet_list["SRC_FL_Source"] = [scan_item.get_row_to_print() for scan_item in result[2]]
154-
need_license = True if output_extension == ".xlsx" else False
155-
create_report_file(0, result[2], result[3], 'all', need_license,
154+
create_report_file(0, result[2], result[3], 'all', False,
156155
_output_dir, output_files["SRC"].split('.')[0], output_extension,
157156
correct_mode, correct_fpath, abs_path)
158157
else: # Run fosslight_source by using docker image
@@ -204,7 +203,7 @@ def run_scanner(src_path, dep_arguments, output_path, keep_raw_data=False,
204203
exist_bin = True
205204
shutil.copy2(os.path.join(_output_dir, output_files['BIN']), os.path.join(_output_dir, tmp_dir))
206205
if exist_src or exist_bin:
207-
correct_scanner_result(_output_dir, output_files, exist_src, exist_bin)
206+
correct_scanner_result(_output_dir, output_files, output_extension, exist_src, exist_bin)
208207
if output_extension == ".xlsx":
209208
if remove_src_data:
210209
overwrite_excel(_output_dir, default_oss_name, "OSS Name")

0 commit comments

Comments
 (0)