MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / generate_output

Function generate_output

src/formattedcode/output_html.py:187–264  ·  view source on GitHub ↗

Yield unicode strings from incrementally rendering `results` and `version` with the Jinja `template` object.

(results, license_references, version, template)

Source from the content-addressed store, hash-verified

185
186
187def generate_output(results, license_references, version, template):
188 """
189 Yield unicode strings from incrementally rendering `results` and `version`
190 with the Jinja `template` object.
191 """
192 # FIXME: This code is highly coupled with actual scans and may not
193 # support adding new scans at all
194
195 from licensedcode.cache import get_licenses_db
196
197 converted = {}
198 converted_infos = {}
199 converted_packages = {}
200 licenses = {}
201
202 LICENSES = 'license_detections'
203 COPYRIGHTS = 'copyrights'
204 PACKAGES = 'package_data'
205
206 # Create a flattened data dict keyed by path
207 for scanned_file in results:
208 scanned_file = dict(scanned_file)
209 path = scanned_file['path']
210 results = []
211 if COPYRIGHTS in scanned_file:
212 for entry in scanned_file[COPYRIGHTS]:
213 results.append({
214 'start': entry['start_line'],
215 'end': entry['end_line'],
216 'what': 'copyright',
217 'value': entry['copyright'],
218 })
219 if LICENSES in scanned_file:
220 for match in get_matches_from_detection_mappings(scanned_file[LICENSES]):
221 # make copy
222 match = dict(match)
223 if TRACE:
224 logger_debug(f"match: {match}")
225 license_expression = match['license_expression']
226 results.append({
227 'start': match['start_line'],
228 'end': match['end_line'],
229 'what': 'license',
230 'value': license_expression,
231 })
232
233 if not license_references and license_expression not in licenses:
234 license_object = get_licenses_db().get(license_expression)
235 if license_object != None:
236 licenses[license_expression] = license_object
237
238 if results:
239 converted[path] = sorted(results, key=itemgetter('start'))
240
241 # TODO: this is klunky: we need to drop templates entirely or we
242 # should rather just pass a the list of files from the scan
243 # results and let the template handle this rather than
244 # denormalizing the list here??

Callers 1

write_templatedFunction · 0.70

Calls 7

get_licenses_dbFunction · 0.90
logger_debugFunction · 0.70
getMethod · 0.65
appendMethod · 0.45
valuesMethod · 0.45
generateMethod · 0.45

Tested by

no test coverage detected