Skip to content

Commit 0053ee0

Browse files
authored
Merge pull request #138 from fosslight/temp
Add yaml error reason to file name
2 parents 3697882 + b9f6962 commit 0053ee0

File tree

4 files changed

+43
-8
lines changed

4 files changed

+43
-8
lines changed

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ binaryornot
33
requests
44
reuse
55
PyYAML
6-
fosslight_util>=1.4.14
6+
fosslight_util>=1.4.16

src/fosslight_oss_pkg/_parsing_excel.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ def convert_yml_to_excel(oss_yaml_files, output_file, file_option_on, base_path)
4646

4747
if file_option_on:
4848
base_path = os.path.dirname(yaml_file)
49-
oss_items, _ = parsing_yml(yaml_file, base_path)
49+
oss_items, _, _ = parsing_yml(yaml_file, base_path)
50+
# if oss_items is abnormal(empty or invalid)
51+
if not oss_items:
52+
continue
53+
5054
for item in oss_items:
5155
items_to_print.extend(item.get_print_array())
5256
if not base_path.endswith(f"{os.sep}"):

src/fosslight_prechecker/_add.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ def download_oss_info_license(base_path, input_license=""):
323323
logger.info(f"\n # There is OSS Package Info file(s) : {oss_yaml_files}\n")
324324

325325
for oss_pkg_file in oss_yaml_files:
326-
_, license_list = parsing_yml(oss_pkg_file, base_path)
326+
_, license_list, _ = parsing_yml(oss_pkg_file, base_path)
327327

328328
for lic in license_list:
329329
converted_lic_list.append(check_input_license_format(lic))

src/fosslight_prechecker/_result.py

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,14 @@ def exclude_file_in_yaml(path_to_find, yaml_files, license_missing_files, copyri
239239
excluded_path = []
240240
lic_present_path = []
241241
cop_present_path = []
242+
abnormal_yaml_files = {}
243+
242244
for file in yaml_files:
243-
oss_items, _ = parsing_yml(file, path_to_find)
245+
oss_items, _, err_reason = parsing_yml(file, path_to_find, False)
246+
# if oss_items is abnormal(empty or invalid)
247+
if not oss_items:
248+
abnormal_yaml_files[file] = err_reason
249+
244250
for oss_item in oss_items:
245251
if oss_item.exclude:
246252
excluded_path.extend(get_path_in_yaml(oss_item))
@@ -255,7 +261,7 @@ def exclude_file_in_yaml(path_to_find, yaml_files, license_missing_files, copyri
255261
license_missing_files = extract_files_in_path(lic_present_path, list(license_missing_files - set(files_with_exclude_removed)))
256262
copyright_missing_files = extract_files_in_path(cop_present_path, list(copyright_missing_files - set(files_with_exclude_removed)))
257263

258-
return license_missing_files, copyright_missing_files
264+
return license_missing_files, copyright_missing_files, abnormal_yaml_files
259265

260266

261267
def get_total_file_list(path_to_find, prj_report, exclude_files):
@@ -266,12 +272,33 @@ def get_total_file_list(path_to_find, prj_report, exclude_files):
266272
return total_files_excluded
267273

268274

275+
def add_reason_to_file_name(oss_pkg_info_files, abnormal_yaml_files, path_to_find):
276+
if not path_to_find.endswith('/'):
277+
path_to_find += '/'
278+
279+
for key, val in abnormal_yaml_files.items():
280+
file_name = key.replace(path_to_find, '', 1)
281+
if file_name in oss_pkg_info_files:
282+
oss_pkg_info_files.remove(file_name)
283+
if val == "yaml_error":
284+
file_name += " (Yaml format error)"
285+
elif val == "not_supported":
286+
file_name += " (Not supported format)"
287+
elif val == "empty":
288+
file_name += " (Empty)"
289+
else:
290+
file_name += " (Unknown error)"
291+
oss_pkg_info_files.append(file_name)
292+
return oss_pkg_info_files
293+
294+
269295
def result_for_summary(path_to_find, oss_pkg_info_files, license_missing_files, copyright_missing_files,
270296
prj_report, _result_log, _check_only_file_mode, file_to_check_list, error_items, exclude_files):
271297
prechecker_compliant = False
272298
detected_lic = []
273299
missing_both_files = []
274300
file_total_num = ""
301+
abnormal_yaml_files = {}
275302

276303
if _check_only_file_mode:
277304
file_total_num = len(file_to_check_list)
@@ -286,12 +313,16 @@ def result_for_summary(path_to_find, oss_pkg_info_files, license_missing_files,
286313
if oss_pkg_info_files:
287314
oss_yaml_files = find_sbom_yaml_files(path_to_find)
288315
# Exclude files in yaml
289-
license_missing_files, copyright_missing_files = exclude_file_in_yaml(path_to_find, oss_yaml_files,
290-
set(license_missing_files) - set(oss_pkg_info_files),
291-
set(copyright_missing_files) - set(oss_pkg_info_files))
316+
license_missing_files, copyright_missing_files, abnormal_yaml_files \
317+
= exclude_file_in_yaml(path_to_find, oss_yaml_files,
318+
set(license_missing_files) - set(oss_pkg_info_files),
319+
set(copyright_missing_files) - set(oss_pkg_info_files))
292320
# Subtract excluded files(untracked or ignored file)
293321
oss_pkg_info_files = list(set(oss_pkg_info_files) - set(exclude_files))
294322

323+
# Add invalid format to file name
324+
oss_pkg_info_files = add_reason_to_file_name(oss_pkg_info_files, abnormal_yaml_files, path_to_find)
325+
295326
if len(license_missing_files) == 0 and len(copyright_missing_files) == 0:
296327
prechecker_compliant = True
297328

0 commit comments

Comments
 (0)