30
30
SPDX_REPLACE_WORDS = ["(" , ")" ]
31
31
KEY_AND = r"(?<=\s)and(?=\s)"
32
32
KEY_OR = r"(?<=\s)or(?=\s)"
33
+ GPL_LICENSE_PATTERN = r'((a|l)?gpl|gfdl)' # GPL, LGPL, AGPL, GFDL
34
+
35
+
36
+ def is_gpl_family_license (licenses : list ) -> bool :
37
+ if not licenses :
38
+ return False
39
+
40
+ for license_name in licenses :
41
+ if not license_name :
42
+ continue
43
+
44
+ license_lower = license_name .lower ()
45
+ if re .search (GPL_LICENSE_PATTERN , license_lower ):
46
+ logger .debug (f"GPL family license detected: { license_name } " )
47
+ return True
48
+
49
+ return False
50
+
51
+
52
+ def should_remove_copyright_for_gpl_license_text (licenses : list , is_license_text : bool ) -> bool :
53
+ return is_license_text and is_gpl_family_license (licenses )
33
54
34
55
35
56
def get_error_from_header (header_item : list ) -> Tuple [bool , str ]:
@@ -100,8 +121,6 @@ def parsing_scancode_32_earlier(scancode_file_list: list, has_error: bool = Fals
100
121
pass
101
122
copyright_value_list .append (copyright_data )
102
123
103
- result_item .copyright = copyright_value_list
104
-
105
124
# Set the license value
106
125
license_detected = []
107
126
if licenses is None or licenses == "" :
@@ -165,14 +184,21 @@ def parsing_scancode_32_earlier(scancode_file_list: list, has_error: bool = Fals
165
184
if len (license_detected ) > 0 :
166
185
result_item .licenses = license_detected
167
186
187
+ if is_manifest_file (file_path ):
188
+ result_item .is_license_text = True
189
+
190
+ # Remove copyright info for license text file of GPL family
191
+ if should_remove_copyright_for_gpl_license_text (license_detected , result_item .is_license_text ):
192
+ logger .debug (f"Removing copyright for GPL family license text file: { file_path } " )
193
+ result_item .copyright = []
194
+ else :
195
+ result_item .copyright = copyright_value_list
196
+
168
197
if len (license_expression_list ) > 0 :
169
198
license_expression_list = list (
170
199
set (license_expression_list ))
171
200
result_item .comment = ',' .join (license_expression_list )
172
201
173
- if is_manifest_file (file_path ):
174
- result_item .is_license_text = True
175
-
176
202
if is_exclude_file (file_path , prev_dir , prev_dir_value ):
177
203
result_item .exclude = True
178
204
scancode_file_item .append (result_item )
@@ -227,7 +253,6 @@ def parsing_scancode_32_later(
227
253
except Exception :
228
254
pass
229
255
copyright_value_list .append (copyright_data )
230
- result_item .copyright = copyright_value_list
231
256
232
257
license_detected = []
233
258
licenses = file .get ("license_detections" , [])
@@ -263,6 +288,20 @@ def parsing_scancode_32_later(
263
288
license_list [lic_matched_key ] = lic_info
264
289
license_detected .append (found_lic )
265
290
result_item .licenses = license_detected
291
+
292
+ result_item .exclude = is_exclude_file (file_path )
293
+ result_item .is_license_text = file .get ("percentage_of_license_text" , 0 ) > 90 or is_notice_file (file_path )
294
+
295
+ if is_manifest_file (file_path ) and len (license_detected ) > 0 :
296
+ result_item .is_license_text = True
297
+
298
+ # Remove copyright info for license text file of GPL family
299
+ if should_remove_copyright_for_gpl_license_text (license_detected , result_item .is_license_text ):
300
+ logger .debug (f"Removing copyright for GPL family license text file: { file_path } " )
301
+ result_item .copyright = []
302
+ else :
303
+ result_item .copyright = copyright_value_list
304
+
266
305
if len (license_detected ) > 1 :
267
306
license_expression_spdx = file .get ("detected_license_expression_spdx" , "" )
268
307
license_expression = file .get ("detected_license_expression" , "" )
@@ -271,12 +310,6 @@ def parsing_scancode_32_later(
271
310
if license_expression :
272
311
result_item .comment = license_expression
273
312
274
- result_item .exclude = is_exclude_file (file_path )
275
- result_item .is_license_text = file .get ("percentage_of_license_text" , 0 ) > 90 or is_notice_file (file_path )
276
-
277
- if is_manifest_file (file_path ) and len (license_detected ) > 0 :
278
- result_item .is_license_text = True
279
-
280
313
scancode_file_item .append (result_item )
281
314
except Exception as ex :
282
315
msg .append (f"Error Parsing item: { ex } " )
0 commit comments