Generating report with jinja2

This commit is contained in:
geoffrey 2023-06-12 21:28:03 +02:00
parent 39e83d2336
commit b0d1df83e3
8 changed files with 188 additions and 3 deletions

3
.gitignore vendored

@ -1,5 +1,4 @@
__pycache__/
__pycache__/**
**.swp
reports/
reports/**
reports/**.html

@ -1,14 +1,33 @@
#!/usr/bin/env python3
from datetime import datetime
import jinja2
def generateHtmlReport(data):
today = datetime.now().isoformat()[0:10].replace("-", "_")
html = _getHeader()
html += "<body>" \
f"<h1>Reports of {today}</h1>"
dataJinja2 = dict()
dataJinja2['plugins'] = list()
# Env jinja2
env = jinja2.Environment(
loader=jinja2.PackageLoader("reports"),
autoescape=jinja2.select_autoescape()
)
# print(env.list_templates())
tmplIndex = env.get_template("index.html.j2")
body = str()
for plugin in data['system']:
print(plugin)
dataJinja2['plugins'].append(f"{plugin}.html.j2")
dataJinja2['year'] = '2023'
rdr = tmplIndex.render(data=dataJinja2)
# For sysctl
#for entry in data['sysctl']:
# body += f"<h2>Sysctl</h2>"
@ -34,7 +53,7 @@ def generateHtmlReport(data):
#print(body)
html += "</body></html>"
with open(f"reports/reports_{today}.html", "w") as f:
f.write(html)
f.write(rdr)
def _getHeader() -> str:
header = "<!doctype html>" \

File diff suppressed because one or more lines are too long

6
reports/templates/bootstrap.min.css vendored Normal file

File diff suppressed because one or more lines are too long

@ -0,0 +1,11 @@
<footer class="pt-3 mt-4 text-body-secondary border-top">
&copy; {{ data['year'] }}
</footer>
</div>
</main>
<script src="./templates/bootstrap.bundle.min.js"></script>
</body>
</html>

@ -0,0 +1,113 @@
<!doctype html>
<html lang="en" data-bs-theme="auto">
<head><script src="../assets/js/color-modes.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="Mark Otto, Jacob Thornton, and Bootstrap contributors">
<meta name="generator" content="Hugo 0.112.5">
<title>Jumbotron example · Bootstrap v5.3</title>
<link rel="canonical" href="https://getbootstrap.com/docs/5.3/examples/jumbotron/">
<link href="./templates/bootstrap.min.css" rel="stylesheet">
<style>
.bd-placeholder-img {
font-size: 1.125rem;
text-anchor: middle;
-webkit-user-select: none;
-moz-user-select: none;
user-select: none;
}
@media (min-width: 768px) {
.bd-placeholder-img-lg {
font-size: 3.5rem;
}
}
.b-example-divider {
width: 100%;
height: 3rem;
background-color: rgba(0, 0, 0, .1);
border: solid rgba(0, 0, 0, .15);
border-width: 1px 0;
box-shadow: inset 0 .5em 1.5em rgba(0, 0, 0, .1), inset 0 .125em .5em rgba(0, 0, 0, .15);
}
.b-example-vr {
flex-shrink: 0;
width: 1.5rem;
height: 100vh;
}
.bi {
vertical-align: -.125em;
fill: currentColor;
}
.nav-scroller {
position: relative;
z-index: 2;
height: 2.75rem;
overflow-y: hidden;
}
.nav-scroller .nav {
display: flex;
flex-wrap: nowrap;
padding-bottom: 1rem;
margin-top: -1px;
overflow-x: auto;
text-align: center;
white-space: nowrap;
-webkit-overflow-scrolling: touch;
}
.btn-bd-primary {
--bd-violet-bg: #712cf9;
--bd-violet-rgb: 112.520718, 44.062154, 249.437846;
--bs-btn-font-weight: 600;
--bs-btn-color: var(--bs-white);
--bs-btn-bg: var(--bd-violet-bg);
--bs-btn-border-color: var(--bd-violet-bg);
--bs-btn-hover-color: var(--bs-white);
--bs-btn-hover-bg: #6528e0;
--bs-btn-hover-border-color: #6528e0;
--bs-btn-focus-shadow-rgb: var(--bd-violet-rgb);
--bs-btn-active-color: var(--bs-btn-hover-color);
--bs-btn-active-bg: #5a23c8;
--bs-btn-active-border-color: #5a23c8;
}
.bd-mode-toggle {
z-index: 1500;
}
</style>
</head>
<body>
<main>
<div class="container py-4">
<header class="pb-3 mb-4 border-bottom">
<span class="d-flex align-items-center text-body-emphasis text-decoration-none; fs-4">Report</span>
</header>
<div class="p-5 mb-4 bg-body-tertiary rounded-3">
<div class="container-fluid py-5">
<h1 class="display-5 fw-bold">Report</h1>
<p class="col-md-8 fs-4">Report of the day... blablabla</p>
</div>
</div>
{% for plugin in data['plugins'] %}
{% include plugin %}
{% endfor %}
{% include 'footer.html.j2' %}

@ -0,0 +1,29 @@
<h3 class="fs-3">Postfix</h3>
<div class="accordion" id="accordionExample">
<div class="accordion-item">
<h2 class="accordion-header">
<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
Accordion Item #1
</button>
</h2>
<div id="collapseOne" class="accordion-collapse collapse show" data-bs-parent="#accordionExample">
<div class="accordion-body">
<strong>This is the first item's accordion body.</strong> It is shown by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-body</code>, though the transition does limit overflow.
</div>
</div>
</div>
<div class="accordion-item">
<h2 class="accordion-header">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
Accordion Item #2
</button>
</h2>
<div id="collapseTwo" class="accordion-collapse collapse" data-bs-parent="#accordionExample">
<div class="accordion-body">
<strong>This is the second item's accordion body.</strong> It is hidden by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-body</code>, though the transition does limit overflow.
</div>
</div>
</div>
</div>

@ -0,0 +1 @@
<h3 class="fs-3">Sysctl</h3>