@@ -113,94 +113,12 @@ def generate(abouts, is_about_input, license_dict, scancode, min_license_score,
113113 # We will only keep the unique license key with the highest license score.
114114 # The process will update the license_key, license_name and license_score.
115115 if scancode :
116- meet_score_licenses_list = []
117- for about in abouts :
118- # We will use a dictionary to keep the unique license key
119- # which the dictionary key is the license key and the dictionary value
120- # is (lic_score, lic_name) or (lic_score, lic_name, matched_text)
121- if about .license_key .value :
122- updated_dict = {}
123- lic_key = about .license_key .value
124- lic_name = []
125- if about .license_name .value :
126- lic_name = about .license_name .value
127- else :
128- lic_name = []
129- for key_list in lic_key :
130- lic_name_list = []
131- for k in key_list :
132- try :
133- lic_name_list .append (license_dict [k ][0 ])
134- except :
135- lic_name_list .append (k )
136- lic_name .append (lic_name_list )
137- about .license_name .value = lic_name
138-
139- if not lic_name :
140- lic_name = []
141- for key in lic_key :
142- lic_name .append (license_dict [key ][0 ])
143- lic_score = about .license_score .value
144- assert len (lic_key ) == len (lic_name )
145- assert len (lic_key ) == len (lic_score )
146-
147- lic_key_expression = about .license_key_expression .value
148- if lic_key_expression :
149- updated_lic_key_expression = []
150- removed_index = []
151- for index , key in enumerate (lic_key_expression ):
152- if key in updated_dict :
153- previous_score , _name = updated_dict [key ]
154- current_score = lic_score [index ]
155- if current_score > previous_score :
156- updated_dict [key ] = (
157- lic_score [index ], lic_name [index ])
158- # Track the duplicated index
159- removed_index .append (index )
160- else :
161- updated_dict [key ] = (
162- lic_score [index ], lic_name [index ])
163- updated_lic_key_expression .append (key )
164- # Remove the duplication
165- for index , key in enumerate (about .license_key .value ):
166- if index in removed_index :
167- del about .license_key .value [index ]
168- del about .license_name .value [index ]
169- del about .license_score .value [index ]
170-
171- lic_key_expression = updated_lic_key_expression
172- updated_lic_key = []
173- updated_lic_name = []
174- updated_lic_score = []
175- for index , lic in enumerate (updated_dict ):
176- _sp_char , lic_keys = parse_license_expression (lic )
177- score , name = updated_dict [lic ]
178- if score >= min_license_score :
179- for lic_key in lic_keys :
180- if not lic_key in meet_score_licenses_list :
181- meet_score_licenses_list .append (lic_key )
182-
183- updated_lic_key .append (lic_keys )
184- updated_lic_name .append (name )
185- updated_lic_score .append (score )
186-
187- # Remove items that don't meet to score
188- for index , score in enumerate (updated_lic_score ):
189- if score < min_license_score :
190- del updated_lic_key [index ]
191- del updated_lic_name [index ]
192- del updated_lic_score [index ]
193- del lic_key_expression [index ]
194-
195- about .license_key .value = updated_lic_key
196- about .license_name .value = updated_lic_name
197- about .license_score .value = updated_lic_score
198- about .license_key_expression .value = lic_key_expression
199-
116+ abouts , meet_score_licenses_list = generate_sctk_input (
117+ abouts , min_license_score , license_dict )
200118 # Remove the license object
201119 remove_list = []
202120 for lic in licenses_list :
203- if not lic .key in meet_score_licenses_list :
121+ if lic .key not in meet_score_licenses_list :
204122 remove_list .append (lic )
205123
206124 for lic in remove_list :
@@ -246,6 +164,93 @@ def generate(abouts, is_about_input, license_dict, scancode, min_license_score,
246164 return errors , rendered
247165
248166
167+ def generate_sctk_input (abouts , min_license_score , license_dict ):
168+ meet_score_licenses_list = []
169+ for about in abouts :
170+ # We will use a dictionary to keep the unique license key
171+ # which the dictionary key is the license key and the dictionary value
172+ # is (lic_score, lic_name)
173+ if about .license_key .value :
174+ updated_dict = {}
175+ lic_key = about .license_key .value
176+ lic_name = []
177+ if about .license_name .value :
178+ lic_name = about .license_name .value
179+ else :
180+ lic_name = []
181+ for key_list in lic_key :
182+ lic_name_list = []
183+ for k in key_list :
184+ try :
185+ lic_name_list .append (license_dict [k ][0 ])
186+ except :
187+ lic_name_list .append (k )
188+ lic_name .append (lic_name_list )
189+ about .license_name .value = lic_name
190+
191+ if not lic_name :
192+ lic_name = []
193+ for key in lic_key :
194+ lic_name .append (license_dict [key ][0 ])
195+ lic_score = about .license_score .value
196+ assert len (lic_key ) == len (lic_name )
197+ assert len (lic_key ) == len (lic_score )
198+
199+ lic_key_expression = about .license_key_expression .value
200+ if lic_key_expression :
201+ updated_lic_key_expression = []
202+ removed_index = []
203+ for index , key in enumerate (lic_key_expression ):
204+ if key in updated_dict :
205+ previous_score , _name = updated_dict [key ]
206+ current_score = lic_score [index ]
207+ if current_score > previous_score :
208+ updated_dict [key ] = (
209+ lic_score [index ], lic_name [index ])
210+ # Track the duplicated index
211+ removed_index .append (index )
212+ else :
213+ updated_dict [key ] = (
214+ lic_score [index ], lic_name [index ])
215+ updated_lic_key_expression .append (key )
216+ # Remove the duplication
217+ for index , key in enumerate (about .license_key .value ):
218+ if index in removed_index :
219+ del about .license_key .value [index ]
220+ del about .license_name .value [index ]
221+ del about .license_score .value [index ]
222+
223+ lic_key_expression = updated_lic_key_expression
224+ updated_lic_key = []
225+ updated_lic_name = []
226+ updated_lic_score = []
227+ for index , lic in enumerate (updated_dict ):
228+ _sp_char , lic_keys = parse_license_expression (lic )
229+ score , name = updated_dict [lic ]
230+ if score >= min_license_score :
231+ for lic_key in lic_keys :
232+ if not lic_key in meet_score_licenses_list :
233+ meet_score_licenses_list .append (lic_key )
234+
235+ updated_lic_key .append (lic_keys )
236+ updated_lic_name .append (name )
237+ updated_lic_score .append (score )
238+
239+ # Remove items that don't meet to score
240+ for index , score in enumerate (updated_lic_score ):
241+ if score < min_license_score :
242+ del updated_lic_key [index ]
243+ del updated_lic_name [index ]
244+ del updated_lic_score [index ]
245+ del lic_key_expression [index ]
246+
247+ about .license_key .value = updated_lic_key
248+ about .license_name .value = updated_lic_name
249+ about .license_score .value = updated_lic_score
250+ about .license_key_expression .value = lic_key_expression
251+ return abouts , meet_score_licenses_list
252+
253+
249254def get_license_file_key (license_text_name ):
250255 if license_text_name .endswith ('.LICENSE' ):
251256 # See https://github.com/nexB/aboutcode-toolkit/issues/439
0 commit comments