@@ -114,41 +114,69 @@ def generate(abouts, is_about_input, license_dict, scancode, min_license_score,
114114 if scancode :
115115 meet_score_licenses_list = []
116116 for about in abouts :
117+ # See if the input has 'matched_text'
118+ matched_text_exist = False
119+ try :
120+ if about .matched_text :
121+ matched_text_exist = True
122+ except :
123+ pass
117124 # We will use a dictionary to keep the unique license key
118125 # which the dictionary key is the license key and the dictionary value
119- # is (lic_score, lic_name)
126+ # is (lic_score, lic_name) or (lic_score, lic_name, matched_text)
120127 if about .license_key .value :
121128 updated_dict = {}
122129 lic_key = about .license_key .value
123130 lic_name = about .license_name .value
124131 lic_score = about .license_score .value
132+ if matched_text_exist :
133+ matched_text = about .matched_text .value
134+ assert len (lic_key ) == len (matched_text )
125135 assert len (lic_key ) == len (lic_name )
126136 assert len (lic_key ) == len (lic_score )
127137 if lic_key :
128138 index = 0
129139 for key in lic_key :
130140 if key in updated_dict :
131- previous_score , _name = updated_dict [key ]
141+ if matched_text_exist :
142+ previous_score , _name , _detected_text = updated_dict [key ]
143+ else :
144+ previous_score , _name = updated_dict [key ]
132145 current_score = lic_score [index ]
133146 if current_score > previous_score :
134- updated_dict [key ] = (lic_score [index ], lic_name [index ])
147+ if matched_text_exist :
148+ updated_dict [key ] = (lic_score [index ], lic_name [index ], matched_text [index ])
149+ else :
150+ updated_dict [key ] = (lic_score [index ], lic_name [index ])
135151 else :
136- updated_dict [key ] = (lic_score [index ], lic_name [index ])
152+ if matched_text_exist :
153+ updated_dict [key ] = (lic_score [index ], lic_name [index ], matched_text [index ])
154+ else :
155+ updated_dict [key ] = (lic_score [index ], lic_name [index ])
137156 index = index + 1
138157 updated_lic_key = []
139158 updated_lic_name = []
140159 updated_lic_score = []
160+ if matched_text_exist :
161+ updated_matched_text = []
141162 for lic in updated_dict :
142- score , name = updated_dict [lic ]
163+ if matched_text_exist :
164+ score , name , text = updated_dict [lic ]
165+ else :
166+ score , name = updated_dict [lic ]
143167 if score >= min_license_score :
144168 updated_lic_key .append (lic )
145169 updated_lic_score .append (score )
146170 updated_lic_name .append (name )
171+ if matched_text_exist :
172+ updated_matched_text .append (text )
147173 if not lic in meet_score_licenses_list :
148174 meet_score_licenses_list .append (lic )
149175 about .license_key .value = updated_lic_key
150176 about .license_name .value = updated_lic_name
151177 about .license_score .value = updated_lic_score
178+ if matched_text_exist :
179+ about .matched_text .value = updated_matched_text
152180
153181 for lic in licenses_list :
154182 if not lic .key in meet_score_licenses_list :
@@ -180,7 +208,6 @@ def generate(abouts, is_about_input, license_dict, scancode, min_license_score,
180208
181209 # Sort the license object by key
182210 licenses_list = sorted (licenses_list , key = lambda x : x .key )
183-
184211 rendered = template .render (
185212 abouts = abouts ,
186213 common_licenses = COMMON_LICENSES ,
0 commit comments