|
30 | 30 | from lobster.common.version import LOBSTER_VERSION |
31 | 31 | from lobster.htmldoc import htmldoc |
32 | 32 | from lobster.common.report import Report |
| 33 | +from lobster.common.io import ensure_output_directory |
33 | 34 | from lobster.common.location import (Void_Reference, |
34 | 35 | File_Reference, |
35 | 36 | Github_Reference, |
@@ -286,6 +287,14 @@ def generate_custom_data(report) -> str: |
286 | 287 | return "".join(content) |
287 | 288 |
|
288 | 289 |
|
| 290 | +def write_html_to_file(html_content: str, output_path: str) -> None: |
| 291 | + """Write HTML content to file, creating parent directories if needed.""" |
| 292 | + ensure_output_directory(output_path) |
| 293 | + with open(output_path, "w", encoding="UTF-8") as fd: |
| 294 | + fd.write(html_content) |
| 295 | + fd.write("\n") |
| 296 | + |
| 297 | + |
289 | 298 | def write_html(report, dot, high_contrast, render_md) -> str: |
290 | 299 | assert isinstance(report, Report) |
291 | 300 |
|
@@ -613,9 +622,7 @@ def _run_impl(self, options: argparse.Namespace) -> int: |
613 | 622 | high_contrast = options.high_contrast, |
614 | 623 | render_md = options.render_md, |
615 | 624 | ) |
616 | | - with open(options.out, "w", encoding="UTF-8") as fd: |
617 | | - fd.write(html_content) |
618 | | - fd.write("\n") |
| 625 | + write_html_to_file(html_content, options.out) |
619 | 626 | print(f"LOBSTER HTML report written to {options.out}") |
620 | 627 |
|
621 | 628 | return 0 |
@@ -646,9 +653,7 @@ def lobster_html_report( |
646 | 653 | high_contrast=high_contrast, |
647 | 654 | render_md=render_md, |
648 | 655 | ) |
649 | | - with open(output_html_path, "w", encoding="UTF-8") as fd: |
650 | | - fd.write(html_content) |
651 | | - fd.write("\n") |
| 656 | + write_html_to_file(html_content, output_html_path) |
652 | 657 |
|
653 | 658 |
|
654 | 659 | def main(args: Optional[Sequence[str]] = None) -> int: |
|
0 commit comments