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

Commit

Permalink
#81 copy assets before generating HTML
Browse files Browse the repository at this point in the history
  • Loading branch information
hjacobs committed May 16, 2019
1 parent eb5aa58 commit 90e4e98
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions kube_resource_report/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@
RESOURCE_PATTERN = re.compile(r"^(\d*)(\D*)$")


TEMPLATES_PATH = Path(__file__).parent / "templates"


def new_resources():
return {"cpu": 0, "memory": 0}

Expand Down Expand Up @@ -545,6 +548,8 @@ def generate_report(

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

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


def copy_static_assets(output_path: Path):
assets_path = output_path / "assets"
assets_path.mkdir(exist_ok=True)

assets_source_path = TEMPLATES_PATH / "assets"

for path in assets_source_path.iterdir():
if path.match("*.js") or path.match("*.css") or path.match("*.png"):
shutil.copy(str(path), str(assets_path / path.name))


def write_loading_page(output_path: Path):
file_name = "index.html"
file_path = output_path / file_name

if not file_path.exists():
templates_path = Path(__file__).parent / "templates"
env = Environment(
loader=FileSystemLoader(str(templates_path)),
loader=FileSystemLoader(str(TEMPLATES_PATH)),
autoescape=select_autoescape(["html", "xml"]),
)
env.filters["money"] = filters.money
Expand Down Expand Up @@ -868,9 +883,8 @@ def write_report(output_path: Path, start, notifications, cluster_summaries, nam
]
)

templates_path = Path(__file__).parent / "templates"
env = Environment(
loader=FileSystemLoader(str(templates_path)),
loader=FileSystemLoader(str(TEMPLATES_PATH)),
autoescape=select_autoescape(["html", "xml"]),
trim_blocks=True,
lstrip_blocks=True
Expand Down Expand Up @@ -988,12 +1002,3 @@ def write_report(output_path: Path, start, notifications, cluster_summaries, nam

with (output_path / "application-metrics.json").open("w") as fd:
json.dump(applications, fd, default=json_default)

assets_path = output_path / "assets"
assets_path.mkdir(exist_ok=True)

assets_source_path = templates_path / "assets"

for path in assets_source_path.iterdir():
if path.match("*.js") or path.match("*.css") or path.match("*.png"):
shutil.copy(str(path), str(assets_path / path.name))

0 comments on commit 90e4e98

Please sign in to comment.