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)
| 145 | |
| 146 | |
| 147 | def 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 | |
| 171 | def get_template(location): |
no test coverage detected