30
30
31
31
userlog = logging .getLogger ("scancode-evaluate" )
32
32
33
+
33
34
class ReturnCode (Enum ):
34
35
"""Return codes."""
35
36
@@ -55,7 +56,7 @@ def path_leaf(path):
55
56
56
57
57
58
def has_permissive_text_in_scancode_output (scancode_output_data_file_licenses ):
58
- """Returns true if at list one license in the scancode output is permissive. """
59
+ """Returns true if at least one license in the scancode output is permissive"""
59
60
return any (
60
61
scancode_output_data_file_license ['category' ] == 'Permissive'
61
62
for scancode_output_data_file_license in scancode_output_data_file_licenses
@@ -75,6 +76,22 @@ def has_spdx_text_in_analysed_file(scanned_file_content):
75
76
return bool (re .findall ("SPDX-License-Identifier:?" , scanned_file_content ))
76
77
77
78
79
+ def has_binary_license (scanned_file_content ):
80
+ """Returns true if the file analysed by ScanCode contains a Permissive Binary License."""
81
+ return bool (re .findall ("Permissive Binary License" , scanned_file_content ))
82
+
83
+
84
+ def get_file_text (scancode_output_data_file ):
85
+ """Returns file text for scancode output file"""
86
+ file_path = os .path .abspath (scancode_output_data_file ['path' ])
87
+ try :
88
+ with open (file_path , 'r' ) as read_file :
89
+ return read_file .read ()
90
+ except UnicodeDecodeError :
91
+ userlog .warning ("Unable to decode file text in: %s" % file_path )
92
+ # Ignore files that cannot be decoded
93
+
94
+
78
95
def license_check (scancode_output_path ):
79
96
"""Check licenses in the scancode json file for specified directory.
80
97
@@ -85,7 +102,7 @@ def license_check(scancode_output_path):
85
102
86
103
Returns:
87
104
0 if nothing found
88
- >0 - count how many license isses found
105
+ >0 - count how many license issues found
89
106
ReturnCode.ERROR.value if any error in file licenses found
90
107
"""
91
108
@@ -113,24 +130,20 @@ def license_check(scancode_output_path):
113
130
continue
114
131
115
132
if not has_permissive_text_in_scancode_output (scancode_output_data_file ['licenses' ]):
116
- scancode_output_data_file ['fail_reason' ] = MISSING_PERMISSIVE_LICENSE_TEXT
117
- license_offenders .append (scancode_output_data_file )
133
+ scanned_file_content = get_file_text (scancode_output_data_file )
134
+ if not (scanned_file_content and has_binary_license (scanned_file_content )):
135
+ scancode_output_data_file ['fail_reason' ] = MISSING_PERMISSIVE_LICENSE_TEXT
136
+ license_offenders .append (scancode_output_data_file )
118
137
119
138
if not has_spdx_text_in_scancode_output (scancode_output_data_file ['licenses' ]):
120
139
# Scancode does not recognize license notice in Python file headers.
121
140
# Issue: https://github.com/nexB/scancode-toolkit/issues/1913
122
141
# Therefore check if the file tested by ScanCode actually has a licence notice.
123
- file_path = os .path .abspath (scancode_output_data_file ['path' ])
124
- try :
125
- with open (file_path , 'r' ) as read_file :
126
- scanned_file_content = read_file .read ()
127
- except UnicodeDecodeError :
128
- userlog .warning ("Unable to look for SPDX text in `{}`:" .format (file_path ))
129
- # Ignore files that cannot be decoded
130
- # check the next file in the scancode output
131
- continue
142
+ scanned_file_content = get_file_text (scancode_output_data_file )
132
143
133
- if not has_spdx_text_in_analysed_file (scanned_file_content ):
144
+ if not scanned_file_content :
145
+ continue
146
+ elif not has_spdx_text_in_analysed_file (scanned_file_content ):
134
147
scancode_output_data_file ['fail_reason' ] = MISSING_SPDX_TEXT
135
148
spdx_offenders .append (scancode_output_data_file )
136
149
0 commit comments