Skip to content

Commit

Permalink
Print the matched text for unknown spdx
Browse files Browse the repository at this point in the history
  • Loading branch information
soimkim authored Jun 25, 2021
2 parents 93dd796 + d2359d6 commit 9b21384
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 4 deletions.
7 changes: 7 additions & 0 deletions LICENSES/LicenseRef-MIT-like.txt
Original file line number Diff line number Diff line change
@@ -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.
12 changes: 12 additions & 0 deletions src/fosslight_source/_parsing_scancode_file_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import os
import logging
import re
import fosslight_util.constant as constant

logger = logging.getLogger(constant.LOGGER_NAME)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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, "")
Expand Down
2 changes: 1 addition & 1 deletion src/fosslight_source/run_scancode.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
6 changes: 3 additions & 3 deletions tests/cli_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
14 changes: 14 additions & 0 deletions tests/test_files/test_known_spdx.txt
Original file line number Diff line number Diff line change
@@ -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()
14 changes: 14 additions & 0 deletions tests/test_files/test_unknown_spdx.txt
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 9b21384

Please sign in to comment.