Skip to content

Commit d331634

Browse files
Merge pull request #152 from fosslight/dev_scancode_filename
Check notice file name for scancode
2 parents e272df7 + 68f4767 commit d331634

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/fosslight_source/_parsing_scancode_file_item.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from ._scan_item import is_exclude_dir
1313
from ._scan_item import is_exclude_file
1414
from ._scan_item import replace_word
15+
from ._scan_item import is_notice_file
1516

1617
logger = logging.getLogger(constant.LOGGER_NAME)
1718
_exclude_directory = ["test", "tests", "doc", "docs"]
@@ -265,7 +266,7 @@ def parsing_scancode_32_later(scancode_file_list, has_error=False):
265266
result_item.comment = license_expression
266267

267268
result_item.exclude = is_exclude_file(file_path)
268-
result_item.is_license_text = file.get("percentage_of_license_text", 0) > 90
269+
result_item.is_license_text = file.get("percentage_of_license_text", 0) > 90 or is_notice_file(file_path)
269270
scancode_file_item.append(result_item)
270271
except Exception as ex:
271272
msg.append(f"Error Parsing item: {ex}")

src/fosslight_source/_scan_item.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@
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)
1112
replace_word = ["-only", "-old-style", "-or-later", "licenseref-scancode-", "licenseref-"]
13+
_notice_filename = ['licen[cs]e[s]?', 'notice[s]?', 'legal', 'copyright[s]?', 'copying*', 'patent[s]?', 'unlicen[cs]e', 'eula',
14+
'[a,l]?gpl[-]?[1-3]?[.,-,_]?[0-1]?', 'mit', 'bsd[-]?[0-4]?', 'bsd[-]?[0-4][-]?clause[s]?',
15+
'apache[-,_]?[1-2]?[.,-,_]?[0-2]?']
1216
_exclude_filename = ["changelog", "config.guess", "config.sub", "changes", "ltmain.sh",
1317
"configure", "configure.ac", "depcomp", "compile", "missing", "makefile"]
1418
_exclude_extension = [".m4", ".in", ".po"]
@@ -119,3 +123,10 @@ def is_exclude_file(file_path, prev_dir=None, prev_dir_exclude_value=None):
119123
else: # running SCANOSS
120124
return is_exclude_dir(dir_path)
121125
return False
126+
127+
128+
def is_notice_file(file_path):
129+
pattern = r"({})(?<!w)".format("|".join(_notice_filename))
130+
file_path = file_path.lower()
131+
filename = os.path.basename(file_path)
132+
return bool(re.match(pattern, filename))

0 commit comments

Comments
 (0)