From ab0ef80c14c4d15ff8458954577f9cd8032a2a9d Mon Sep 17 00:00:00 2001 From: Soim Kim Date: Fri, 25 Nov 2022 10:32:37 +0900 Subject: [PATCH] Add options when parsing yaml - Set list to null in case of error - Add an option to not log output --- src/fosslight_util/parsing_yaml.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/fosslight_util/parsing_yaml.py b/src/fosslight_util/parsing_yaml.py index 0e91941..7102ac3 100644 --- a/src/fosslight_util/parsing_yaml.py +++ b/src/fosslight_util/parsing_yaml.py @@ -16,7 +16,7 @@ EXAMPLE_OSS_PKG_INFO_LINK = "https://github.com/fosslight/fosslight_prechecker/blob/main/tests/convert/sbom-info.yaml" -def parsing_yml(yaml_file, base_path): +def parsing_yml(yaml_file, base_path, print_log=True): oss_list = [] license_list = [] idx = 1 @@ -51,9 +51,13 @@ def parsing_yml(yaml_file, base_path): license_list.extend(item.license) idx += 1 except AttributeError as ex: - _logger.error(f"Not supported yaml file format {ex}") + if print_log: + _logger.error(f"Not supported yaml file format {ex}") + oss_list = [] except yaml.YAMLError: - _logger.warning(f"Can't parse yaml - skip to parse yaml file: {yaml_file}") + if print_log: + _logger.warning(f"Can't parse yaml - skip to parse yaml file: {yaml_file}") + oss_list = [] return oss_list, set(license_list)