Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 24 additions & 28 deletions src/fosslight_source/_parsing_scancode_file_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,59 +44,58 @@ def parsing_file_item(scancode_file_list, has_error, need_matched_license=False)
rc = True
scancode_file_item = []
license_list = {} # Key :[license]+[matched_text], value: MatchedLicense()
msg = ""
msg = []

prev_dir = ""
prev_dir_value = False
regex = re.compile(r'licenseref-(\S)+')
regex = re.compile(r'licenseref-(\S+)', re.IGNORECASE)

if scancode_file_list:
for file in scancode_file_list:
try:
is_binary = False
is_dir = False
file_path = file["path"]

if "is_binary" in file:
is_binary = file["is_binary"]
file_path = file.get("path", "")
if not file_path:
continue
is_binary = file.get("is_binary", False)
if "type" in file:
is_dir = file["type"] == "directory"
if is_dir:
prev_dir_value = is_exclude_dir(file_path)
prev_dir = file_path

if not is_binary and not is_dir:
licenses = file["licenses"]
copyright_list = file["copyrights"]
licenses = file.get("licenses", [])
copyright_list = file.get("copyrights", [])

result_item = ScanItem(file_path)

if has_error and "scan_errors" in file:
error_msg = file["scan_errors"]
error_msg = file.get("scan_errors", [])
if len(error_msg) > 0:
logger.debug(f"Test_msg {file_path}:{error_msg}")
result_item.comment = ",".join(error_msg)
scancode_file_item.append(result_item)
continue

copyright_value_list = [x["value"] for x in copyright_list]
copyright_value_list = []
for x in copyright_list:
copyright_value_list.append(x.get("value", ""))
result_item.copyright = copyright_value_list

# Set the license value
license_detected = []
if licenses is None or licenses == "":
continue

license_expression_list = file["license_expressions"]
license_expression_list = file.get("license_expressions", {})
if len(license_expression_list) > 0:
license_expression_list = [
x.lower() for x in license_expression_list
if x is not None]

for lic_item in licenses:
license_value = ""
key = lic_item["key"]
spdx = lic_item["spdx_license_key"]
key = lic_item.get("key", "")
spdx = lic_item.get("spdx_license_key", "")
# logger.debug("LICENSE_KEY:"+str(key)+",SPDX:"+str(spdx))

if key is not None and key != "":
Expand All @@ -111,11 +110,10 @@ def parsing_file_item(scancode_file_list, has_error, need_matched_license=False)
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())
matched_txt = lic_item.get("matched_text", "")
matched = regex.search(matched_txt)
if matched:
license_value = str(matched.group())
except Exception:
pass

Expand All @@ -136,9 +134,8 @@ def parsing_file_item(scancode_file_list, has_error, need_matched_license=False)
lic_info = MatchedLicense(license_value, lic_category, lic_matched_text, file_path)
license_list[lic_matched_key] = lic_info

matched_rule = lic_item["matched_rule"]
if matched_rule["is_license_text"]:
result_item.is_license_text = True
matched_rule = lic_item.get("matched_rule", {})
result_item.is_license_text = matched_rule.get("is_license_text", False)

if len(license_detected) > 0:
result_item.licenses = license_detected
Expand All @@ -153,8 +150,7 @@ def parsing_file_item(scancode_file_list, has_error, need_matched_license=False)
scancode_file_item.append(result_item)

except Exception as ex:
msg = f"* Error Parsing item: {ex}"
msg.append(f"Error Parsing item: {ex}")
rc = False
logger.debug(msg)

return rc, scancode_file_item, msg.strip(), license_list
msg = list(set(msg))
return rc, scancode_file_item, msg, license_list
5 changes: 5 additions & 0 deletions tests/test_files/dual.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright (c) 2020 LG Electronics Inc.
# Copyright (c) 2021 LG Electronics Inc.
# REUSE-IgnoreStart
# SPDX-License-Identifier: GPL-2.0 or MIT
# REUSE-IgnoreEnd
3 changes: 3 additions & 0 deletions tests/test_files/spdx_lic.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# REUSE-IgnoreStart
# SPDX-License-Identifier: licenseref-TEMP_LICENSE
# REUSE-IgnoreEnd