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

Function write_templated

src/formattedcode/output_html.py:147–168  ·  view source on GitHub ↗

Write scan output `results` to the `output_file` opened file using a template file at `template_loc`. Raise an exception on errors.

(output_file, results, license_references, version, template_loc)

Source from the content-addressed store, hash-verified

145
146
147def write_templated(output_file, results, license_references, version, template_loc):
148 """
149 Write scan output `results` to the `output_file` opened file using a template
150 file at `template_loc`.
151 Raise an exception on errors.
152 """
153 template = get_template(template_loc)
154
155 for template_chunk in generate_output(
156 results=results,
157 license_references=license_references,
158 version=version,
159 template=template,
160 ):
161 assert isinstance(template_chunk, str)
162 try:
163 output_file.write(template_chunk)
164 except Exception:
165 import traceback
166 msg = 'ERROR: Failed to write output for: ' + repr(template_chunk)
167 msg += '\n' + traceback.format_exc()
168 raise Exception(msg)
169
170
171def get_template(location):

Callers 2

process_codebaseMethod · 0.85
process_codebaseMethod · 0.85

Calls 3

get_templateFunction · 0.85
generate_outputFunction · 0.70
writeMethod · 0.45

Tested by

no test coverage detected