3939
4040DEFAULT_LICENSE_SCORE = 100
4141
42+
4243def generate (abouts , is_about_input , license_dict , scancode , min_license_score , template = None , vartext = None ):
4344 """
4445 Generate an attribution text from an `abouts` list of About objects, a
@@ -55,7 +56,8 @@ def generate(abouts, is_about_input, license_dict, scancode, min_license_score,
5556 lineno , message = template_error
5657 error = Error (
5758 CRITICAL ,
58- 'Template validation error at line: {lineno}: "{message}"' .format (** locals ())
59+ 'Template validation error at line: {lineno}: "{message}"' .format (
60+ ** locals ())
5961 )
6062 errors .append (error )
6163 return error , None
@@ -87,10 +89,11 @@ def generate(abouts, is_about_input, license_dict, scancode, min_license_score,
8789 filename = list (about .license_file .value .keys ())[index ]
8890 text = list (about .license_file .value .values ())[index ]
8991 else :
90- error = Error (CRITICAL , 'No license file found for ' + name )
92+ error = Error (
93+ CRITICAL , 'No license file found for ' + name )
9194 errors .append (error )
9295 break
93- if about .license_url .value :
96+ if about .license_url .value :
9497 url = about .license_url .value [index ]
9598 else :
9699 url = ''
@@ -106,7 +109,6 @@ def generate(abouts, is_about_input, license_dict, scancode, min_license_score,
106109 license_object = License (key , name , filename , url , text )
107110 licenses_list .append (license_object )
108111
109-
110112 # We need special treatment for scancode input.
111113 # Each about_object may have duplicated license key and same/different license score
112114 # We will only keep the unique license key with the highest license score.
@@ -145,14 +147,18 @@ def generate(abouts, is_about_input, license_dict, scancode, min_license_score,
145147 current_score = lic_score [index ]
146148 if current_score > previous_score :
147149 if matched_text_exist :
148- updated_dict [key ] = (lic_score [index ], lic_name [index ], matched_text [index ])
150+ updated_dict [key ] = (
151+ lic_score [index ], lic_name [index ], matched_text [index ])
149152 else :
150- updated_dict [key ] = (lic_score [index ], lic_name [index ])
153+ updated_dict [key ] = (
154+ lic_score [index ], lic_name [index ])
151155 else :
152156 if matched_text_exist :
153- updated_dict [key ] = (lic_score [index ], lic_name [index ], matched_text [index ])
157+ updated_dict [key ] = (
158+ lic_score [index ], lic_name [index ], matched_text [index ])
154159 else :
155- updated_dict [key ] = (lic_score [index ], lic_name [index ])
160+ updated_dict [key ] = (
161+ lic_score [index ], lic_name [index ])
156162 index = index + 1
157163 updated_lic_key = []
158164 updated_lic_name = []
@@ -200,7 +206,8 @@ def generate(abouts, is_about_input, license_dict, scancode, min_license_score,
200206 lic_name_expression = ' ' .join (lic_name_expression_list )
201207
202208 # Add the license name expression string into the about object as a custom field
203- custom_field = StringField (name = 'license_name_expression' , value = lic_name_expression , present = True )
209+ custom_field = StringField (
210+ name = 'license_name_expression' , value = lic_name_expression , present = True )
204211 setattr (about , 'license_name_expression' , custom_field )
205212
206213 # Sort the about objects by name
@@ -219,6 +226,7 @@ def generate(abouts, is_about_input, license_dict, scancode, min_license_score,
219226
220227 return errors , rendered
221228
229+
222230def get_license_file_key (license_text_name ):
223231 if license_text_name .endswith ('.LICENSE' ):
224232 # See https://github.com/nexB/aboutcode-toolkit/issues/439
@@ -274,11 +282,16 @@ def generate_and_save(abouts, is_about_input, license_dict, output_location, sca
274282 for about in abouts :
275283 if not about .license_expression .value :
276284 continue
277- special_char_in_expression , lic_list = parse_license_expression (about .license_expression .value )
285+ special_char_in_expression , lic_list , invalid_lic_exp = parse_license_expression (
286+ about .license_expression .value )
278287 if special_char_in_expression :
279288 msg = (u"The following character(s) cannot be in the license_expression: " +
280289 str (special_char_in_expression ))
281290 errors .append (Error (ERROR , msg ))
291+ if invalid_lic_exp :
292+ msg = (about .about_file_path + u": The following license_expression is invalid: " +
293+ invalid_lic_exp )
294+ errors .append (Error (ERROR , msg ))
282295 rendering_error , rendered = generate_from_file (
283296 abouts ,
284297 is_about_input ,
0 commit comments