From d2359d60ac34e02d31ca850fee6b0d6b9a4520db Mon Sep 17 00:00:00 2001 From: Soim Kim Date: Thu, 24 Jun 2021 16:15:40 +0900 Subject: [PATCH] Print the matched text for unknown spdx --- LICENSES/LicenseRef-MIT-like.txt | 7 +++++++ .../_parsing_scancode_file_item.py | 12 ++++++++++++ src/fosslight_source/run_scancode.py | 2 +- tests/cli_test.py | 6 +++--- tests/test_files/test_known_spdx.txt | 14 ++++++++++++++ tests/test_files/test_unknown_spdx.txt | 14 ++++++++++++++ 6 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 LICENSES/LicenseRef-MIT-like.txt create mode 100755 tests/test_files/test_known_spdx.txt create mode 100755 tests/test_files/test_unknown_spdx.txt diff --git a/LICENSES/LicenseRef-MIT-like.txt b/LICENSES/LicenseRef-MIT-like.txt new file mode 100644 index 0000000..34221dc --- /dev/null +++ b/LICENSES/LicenseRef-MIT-like.txt @@ -0,0 +1,7 @@ +# This License text is the License text for testing unknown-spdx. + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/src/fosslight_source/_parsing_scancode_file_item.py b/src/fosslight_source/_parsing_scancode_file_item.py index 3a63096..908ee07 100755 --- a/src/fosslight_source/_parsing_scancode_file_item.py +++ b/src/fosslight_source/_parsing_scancode_file_item.py @@ -5,6 +5,7 @@ import os import logging +import re import fosslight_util.constant as constant logger = logging.getLogger(constant.LOGGER_NAME) @@ -123,6 +124,7 @@ def parsing_file_item(scancode_file_list, has_error): prev_dir = "" prev_dir_value = False + regex = re.compile(r'licenseref-(\S)+') for file in scancode_file_list: try: @@ -182,6 +184,16 @@ def parsing_file_item(scancode_file_list, has_error): license_value = spdx.lower() if license_value != "": + if key == "unknown-spdx": + try: + if "matched_text" in lic_item: + matched_txt = lic_item["matched_text"].lower() + matched = regex.search(matched_txt) + if matched: + license_value = str(matched.group()) + except Exception: + pass + for word in _replace_word: if word in license_value: license_value = license_value.replace(word, "") diff --git a/src/fosslight_source/run_scancode.py b/src/fosslight_source/run_scancode.py index 81979ef..d85d304 100755 --- a/src/fosslight_source/run_scancode.py +++ b/src/fosslight_source/run_scancode.py @@ -97,7 +97,7 @@ def run_scan(path_to_scan, output_file_name="", copyright=True, return_results=True, processes=num_cores, output_json_pp=output_json_file, - only_findings=True) + only_findings=True, license_text=True) if not rc: msg = "Source code analysis failed." diff --git a/tests/cli_test.py b/tests/cli_test.py index d62d4b2..20618b3 100755 --- a/tests/cli_test.py +++ b/tests/cli_test.py @@ -27,13 +27,13 @@ def main(): ret = run_scan(path_to_find_bin, fosslight_report_name, True, -1, True) - logger.warn("[Scan] Result: %s" % (ret[0])) - logger.warn("[Scan] Result_msg: %s" % (ret[1])) + logger.warning("[Scan] Result: %s" % (ret[0])) + logger.warning("[Scan] Result_msg: %s" % (ret[1])) if len(ret) > 2: try: for scan_item in ret[2]: - logger.warn(scan_item.get_row_to_print()) + logger.warning(scan_item.get_row_to_print()) except Exception as ex: logger.error("Error:"+str(ex)) diff --git a/tests/test_files/test_known_spdx.txt b/tests/test_files/test_known_spdx.txt new file mode 100755 index 0000000..44651c6 --- /dev/null +++ b/tests/test_files/test_known_spdx.txt @@ -0,0 +1,14 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (c) 2020 LG Electronics Inc. +# SPDX-License-Identifier: Apache-2.0 + +import os + + +def main(): + print("Sample Python File") + + +if __name__ == '__main__': + main() diff --git a/tests/test_files/test_unknown_spdx.txt b/tests/test_files/test_unknown_spdx.txt new file mode 100755 index 0000000..1ea5b51 --- /dev/null +++ b/tests/test_files/test_unknown_spdx.txt @@ -0,0 +1,14 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (c) 2020 LG Electronics Inc. +# SPDX-License-Identifier: LicenseRef-MIT-like + +import os + + +def main(): + print("Sample Python File") + + +if __name__ == '__main__': + main()