Skip to content

Commit d2359d6

Browse files
committed
Print the matched text for unknown spdx
1 parent 93dd796 commit d2359d6

File tree

6 files changed

+51
-4
lines changed

6 files changed

+51
-4
lines changed

LICENSES/LicenseRef-MIT-like.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# This License text is the License text for testing unknown-spdx.
2+
3+
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:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
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.

src/fosslight_source/_parsing_scancode_file_item.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import os
77
import logging
8+
import re
89
import fosslight_util.constant as constant
910

1011
logger = logging.getLogger(constant.LOGGER_NAME)
@@ -123,6 +124,7 @@ def parsing_file_item(scancode_file_list, has_error):
123124

124125
prev_dir = ""
125126
prev_dir_value = False
127+
regex = re.compile(r'licenseref-(\S)+')
126128

127129
for file in scancode_file_list:
128130
try:
@@ -182,6 +184,16 @@ def parsing_file_item(scancode_file_list, has_error):
182184
license_value = spdx.lower()
183185

184186
if license_value != "":
187+
if key == "unknown-spdx":
188+
try:
189+
if "matched_text" in lic_item:
190+
matched_txt = lic_item["matched_text"].lower()
191+
matched = regex.search(matched_txt)
192+
if matched:
193+
license_value = str(matched.group())
194+
except Exception:
195+
pass
196+
185197
for word in _replace_word:
186198
if word in license_value:
187199
license_value = license_value.replace(word, "")

src/fosslight_source/run_scancode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def run_scan(path_to_scan, output_file_name="",
9797
copyright=True, return_results=True,
9898
processes=num_cores,
9999
output_json_pp=output_json_file,
100-
only_findings=True)
100+
only_findings=True, license_text=True)
101101

102102
if not rc:
103103
msg = "Source code analysis failed."

tests/cli_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ def main():
2727

2828
ret = run_scan(path_to_find_bin, fosslight_report_name, True, -1, True)
2929

30-
logger.warn("[Scan] Result: %s" % (ret[0]))
31-
logger.warn("[Scan] Result_msg: %s" % (ret[1]))
30+
logger.warning("[Scan] Result: %s" % (ret[0]))
31+
logger.warning("[Scan] Result_msg: %s" % (ret[1]))
3232

3333
if len(ret) > 2:
3434
try:
3535
for scan_item in ret[2]:
36-
logger.warn(scan_item.get_row_to_print())
36+
logger.warning(scan_item.get_row_to_print())
3737
except Exception as ex:
3838
logger.error("Error:"+str(ex))
3939

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
# Copyright (c) 2020 LG Electronics Inc.
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
import os
7+
8+
9+
def main():
10+
print("Sample Python File")
11+
12+
13+
if __name__ == '__main__':
14+
main()
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
# Copyright (c) 2020 LG Electronics Inc.
4+
# SPDX-License-Identifier: LicenseRef-MIT-like
5+
6+
import os
7+
8+
9+
def main():
10+
print("Sample Python File")
11+
12+
13+
if __name__ == '__main__':
14+
main()

0 commit comments

Comments
 (0)