Skip to content

Commit e7b293b

Browse files
committed
Fix to add default name and url for yaml
and add compared result summary log Signed-off-by: Jiyeong Seok <[email protected]>
1 parent c85b553 commit e7b293b

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

src/fosslight_scanner/_run_compare.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
ADD = "add"
2020
DELETE = "delete"
2121
CHANGE = "change"
22+
COMP_STATUS = [ADD, DELETE, CHANGE]
2223

2324

2425
def write_result_json_yaml(output_file, compared_result, file_ext):
@@ -93,10 +94,9 @@ def write_result_html(output_file, compared_result, before_yaml, after_yaml):
9394

9495
table_html = f.find("table", {"id": "comp_result"})
9596

96-
status = [ADD, DELETE, CHANGE]
9797
row = 2
9898
MIN_ROW_NUM = 100
99-
for st in status:
99+
for st in COMP_STATUS:
100100
for oi in compared_result[st]:
101101
compared_row = parse_result_for_table(oi, st)
102102
tr = f.new_tag('tr')
@@ -155,8 +155,7 @@ def write_result_xlsx(output_file, compared_result):
155155
worksheet.write_row(0, 0, HEADER, bold)
156156

157157
row = 1
158-
status = [ADD, DELETE, CHANGE]
159-
for st in status:
158+
for st in COMP_STATUS:
160159
for oi in compared_result[st]:
161160
compared_row = parse_result_for_table(oi, st)
162161
worksheet.write_row(row, 0, compared_row)
@@ -215,6 +214,16 @@ def get_comparison_result_filename(output_path, output_file, output_extension, _
215214
return result_file
216215

217216

217+
def count_compared_result(compared_result):
218+
comp_len = [len(compared_result[st]) for st in COMP_STATUS]
219+
if sum(comp_len) == 0:
220+
count_str = "all oss lists are the same."
221+
else:
222+
count_str = f"total {sum(comp_len)} oss updated ("
223+
count_str += ', '.join([f"{COMP_STATUS[x]}: {comp_len[x]}" for x in range(0, 3)]) + ")"
224+
logger.info(f"Comparison result: {count_str}")
225+
226+
218227
def run_compare(before_yaml, after_yaml, output_path, output_file, file_ext, _start_time):
219228
ret = False
220229
logger.info("Start compare mode")
@@ -224,6 +233,7 @@ def run_compare(before_yaml, after_yaml, output_path, output_file, file_ext, _st
224233
result_file = get_comparison_result_filename(output_path, output_file, file_ext, _start_time)
225234
compared_result = compare_yaml(before_yaml, after_yaml)
226235
if compared_result != '':
236+
count_compared_result(compared_result)
227237
ret, result_file = write_compared_result(result_file, compared_result, file_ext, before_yaml, after_yaml)
228238
if ret:
229239
logger.info(f"Success to write compared result: {result_file}")

src/fosslight_scanner/common.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def overwrite_excel(excel_file_path, oss_name, column_name='OSS Name'):
159159
logger.debug(f"overwrite_excel:{ex}")
160160

161161

162-
def merge_yamls(_output_dir, merge_yaml_files, final_report):
162+
def merge_yamls(_output_dir, merge_yaml_files, final_report, remove_src_data=False, default_oss_name='', url=''):
163163
success = True
164164
err_msg = ''
165165

@@ -169,11 +169,21 @@ def merge_yamls(_output_dir, merge_yaml_files, final_report):
169169
for mf in merge_yaml_files:
170170
if os.path.exists(os.path.join(_output_dir, mf)):
171171
oss_list, license_list = parsing_yml(os.path.join(_output_dir, mf), _output_dir)
172+
173+
if remove_src_data:
174+
existed_yaml = {}
175+
for oi in oss_list:
176+
oi.name = default_oss_name if oi.name == '-' else oi.name
177+
oi.download_location = url if oi.download_location == '' else oi.download_location
178+
create_yaml_with_ossitem(oi, existed_yaml)
179+
with open(os.path.join(_output_dir, mf), 'w') as f:
180+
yaml.dump(existed_yaml, f, default_flow_style=False, sort_keys=False)
181+
172182
oss_total_list.extend(oss_list)
173183

174184
if oss_total_list != []:
175-
for oi in oss_total_list:
176-
create_yaml_with_ossitem(oi, yaml_dict)
185+
for oti in oss_total_list:
186+
create_yaml_with_ossitem(oti, yaml_dict)
177187
with open(os.path.join(_output_dir, final_report), 'w') as f:
178188
yaml.dump(yaml_dict, f, default_flow_style=False, sort_keys=False)
179189
else:

src/fosslight_scanner/fosslight_scanner.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ def run_scanner(src_path, dep_arguments, output_path, keep_raw_data=False,
130130
"BIN": f"FL_Binary{output_extension}",
131131
"BIN_TXT": "FL_Binary.txt",
132132
"DEP": f"FL_Dependency{output_extension}",
133-
134133
"PRECHECKER": "FL_Prechecker.yaml"}
135134
if run_prechecker:
136135
output_prechecker = os.path.join(_output_dir, output_files["PRECHECKER"])
@@ -197,7 +196,8 @@ def run_scanner(src_path, dep_arguments, output_path, keep_raw_data=False,
197196
success, err_msg = merge_excels(_output_dir, final_report)
198197
elif output_extension == ".yaml":
199198
merge_yaml_files = [output_files["SRC"], output_files["BIN"], output_files["DEP"]]
200-
success, err_msg = merge_yamls(_output_dir, merge_yaml_files, final_report)
199+
success, err_msg = merge_yamls(_output_dir, merge_yaml_files, final_report,
200+
remove_src_data, default_oss_name, url)
201201

202202
if success:
203203
result_log["Output File"] = final_report

0 commit comments

Comments
 (0)