Skip to content
This repository was archived by the owner on Oct 3, 2020. It is now read-only.

Commit 90e4e98

Browse files
committed
#81 copy assets before generating HTML
1 parent eb5aa58 commit 90e4e98

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

kube_resource_report/report.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@
6868
RESOURCE_PATTERN = re.compile(r"^(\d*)(\D*)$")
6969

7070

71+
TEMPLATES_PATH = Path(__file__).parent / "templates"
72+
73+
7174
def new_resources():
7275
return {"cpu": 0, "memory": 0}
7376

@@ -545,6 +548,8 @@ def generate_report(
545548

546549
# the data collection might take a long time, so first write index.html
547550
# to give users feedback that Kubernetes Resource Report has started
551+
# first copy CSS/JS/..
552+
copy_static_assets(output_path)
548553
write_loading_page(output_path)
549554

550555
pickle_path = output_path / "dump.pickle"
@@ -670,14 +675,24 @@ def cluster_name(cluster_id):
670675
return cluster_summaries
671676

672677

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+
673689
def write_loading_page(output_path: Path):
674690
file_name = "index.html"
675691
file_path = output_path / file_name
676692

677693
if not file_path.exists():
678-
templates_path = Path(__file__).parent / "templates"
679694
env = Environment(
680-
loader=FileSystemLoader(str(templates_path)),
695+
loader=FileSystemLoader(str(TEMPLATES_PATH)),
681696
autoescape=select_autoescape(["html", "xml"]),
682697
)
683698
env.filters["money"] = filters.money
@@ -868,9 +883,8 @@ def write_report(output_path: Path, start, notifications, cluster_summaries, nam
868883
]
869884
)
870885

871-
templates_path = Path(__file__).parent / "templates"
872886
env = Environment(
873-
loader=FileSystemLoader(str(templates_path)),
887+
loader=FileSystemLoader(str(TEMPLATES_PATH)),
874888
autoescape=select_autoescape(["html", "xml"]),
875889
trim_blocks=True,
876890
lstrip_blocks=True
@@ -988,12 +1002,3 @@ def write_report(output_path: Path, start, notifications, cluster_summaries, nam
9881002

9891003
with (output_path / "application-metrics.json").open("w") as fd:
9901004
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

Comments
 (0)