|
68 | 68 | RESOURCE_PATTERN = re.compile(r"^(\d*)(\D*)$")
|
69 | 69 |
|
70 | 70 |
|
| 71 | +TEMPLATES_PATH = Path(__file__).parent / "templates" |
| 72 | + |
| 73 | + |
71 | 74 | def new_resources():
|
72 | 75 | return {"cpu": 0, "memory": 0}
|
73 | 76 |
|
@@ -545,6 +548,8 @@ def generate_report(
|
545 | 548 |
|
546 | 549 | # the data collection might take a long time, so first write index.html
|
547 | 550 | # to give users feedback that Kubernetes Resource Report has started
|
| 551 | + # first copy CSS/JS/.. |
| 552 | + copy_static_assets(output_path) |
548 | 553 | write_loading_page(output_path)
|
549 | 554 |
|
550 | 555 | pickle_path = output_path / "dump.pickle"
|
@@ -670,14 +675,24 @@ def cluster_name(cluster_id):
|
670 | 675 | return cluster_summaries
|
671 | 676 |
|
672 | 677 |
|
| 678 | +def copy_static_assets(output_path: Path): |
| 679 | + assets_path = output_path / "assets" |
| 680 | + assets_path.mkdir(exist_ok=True) |
| 681 | + |
| 682 | + assets_source_path = TEMPLATES_PATH / "assets" |
| 683 | + |
| 684 | + for path in assets_source_path.iterdir(): |
| 685 | + if path.match("*.js") or path.match("*.css") or path.match("*.png"): |
| 686 | + shutil.copy(str(path), str(assets_path / path.name)) |
| 687 | + |
| 688 | + |
673 | 689 | def write_loading_page(output_path: Path):
|
674 | 690 | file_name = "index.html"
|
675 | 691 | file_path = output_path / file_name
|
676 | 692 |
|
677 | 693 | if not file_path.exists():
|
678 |
| - templates_path = Path(__file__).parent / "templates" |
679 | 694 | env = Environment(
|
680 |
| - loader=FileSystemLoader(str(templates_path)), |
| 695 | + loader=FileSystemLoader(str(TEMPLATES_PATH)), |
681 | 696 | autoescape=select_autoescape(["html", "xml"]),
|
682 | 697 | )
|
683 | 698 | env.filters["money"] = filters.money
|
@@ -868,9 +883,8 @@ def write_report(output_path: Path, start, notifications, cluster_summaries, nam
|
868 | 883 | ]
|
869 | 884 | )
|
870 | 885 |
|
871 |
| - templates_path = Path(__file__).parent / "templates" |
872 | 886 | env = Environment(
|
873 |
| - loader=FileSystemLoader(str(templates_path)), |
| 887 | + loader=FileSystemLoader(str(TEMPLATES_PATH)), |
874 | 888 | autoescape=select_autoescape(["html", "xml"]),
|
875 | 889 | trim_blocks=True,
|
876 | 890 | lstrip_blocks=True
|
@@ -988,12 +1002,3 @@ def write_report(output_path: Path, start, notifications, cluster_summaries, nam
|
988 | 1002 |
|
989 | 1003 | with (output_path / "application-metrics.json").open("w") as fd:
|
990 | 1004 | json.dump(applications, fd, default=json_default)
|
991 |
| - |
992 |
| - assets_path = output_path / "assets" |
993 |
| - assets_path.mkdir(exist_ok=True) |
994 |
| - |
995 |
| - assets_source_path = templates_path / "assets" |
996 |
| - |
997 |
| - for path in assets_source_path.iterdir(): |
998 |
| - if path.match("*.js") or path.match("*.css") or path.match("*.png"): |
999 |
| - shutil.copy(str(path), str(assets_path / path.name)) |
|
0 commit comments