Include static and templates in the built package

This commit is contained in:
Daniel Parks 2017-09-13 11:03:25 -07:00
parent 63f7d12371
commit b96c7a17cf
No known key found for this signature in database
GPG key ID: 7335138B2B9829EB
13 changed files with 9 additions and 3 deletions

View file

@ -24,7 +24,10 @@ def output_html(inventory, directory):
if os.path.isdir(directory):
shutil.rmtree(directory)
os.mkdir(directory, 0o755)
shutil.copytree("static", "{}/static".format(directory))
shutil.copytree(
"{}/static".format(os.path.dirname(os.path.abspath(__file__))),
"{}/static".format(directory))
with open("{}/pygments.css".format(directory), "w", encoding="utf-8") as css:
css.write(pygments.formatters.HtmlFormatter().get_style_defs('.codehilite'))
@ -126,8 +129,9 @@ def output_html(inventory, directory):
def render_template(template_name, **kwargs):
data_path = os.path.dirname(os.path.abspath(__file__))
environment = jinja2.Environment(
loader=jinja2.FileSystemLoader("templates"),
loader=jinja2.FileSystemLoader("{}/templates".format(data_path)),
autoescape=jinja2.select_autoescape(default=True))
md = markdown2.Markdown(extras=[

View file

@ -0,0 +1,181 @@
@charset "utf-8";
body {
margin: 0;
padding: 0;
font-family: sans-serif;
font-size: 14px;
line-height: 1.5em;
background: #fff;
}
a {
text-decoration: none;
color: #00c;
}
a:hover {
color: #096;
}
main {
float: left; /* Ensure this expands to contain the table. */
min-width: 100%;
box-sizing: border-box;
padding: 1em;
border-top: 3px solid #000;
border-bottom: 3px solid #000;
}
footer {
clear: both;
position: relative;
overflow: hidden;
margin: 0;
padding: 1em 30px;
}
nav > ul {
margin: 0;
padding: 7px 15px;
}
nav > ul > li {
display: inline-block;
margin: 0;
padding: 0 10px;
list-style-type: none;
}
nav .infinitory-logo {
font-size: 24px;
font-family: Garamond, serif;
vertical-align: -3px;
line-height: 18px;
}
nav a,
footer a {
font-weight: bold;
color: #000;
}
nav a:after,
footer a:after {
font-family: "Arial Unicode MS", sans-serif;
content: "▸";
vertical-align: -1px;
padding-left: 1px;
}
nav a.backward:after,
footer a.backward:after {
content: "";
padding-left: 0;
}
nav a.backward:before,
footer a.backward:before {
font-family: "Arial Unicode MS", sans-serif;
content: "◂";
vertical-align: -1px;
padding-right: 1px;
}
#generated-at {
display: block;
float: right;
}
h1 {
margin: 0.75em 10px 1em 10px;
}
table {
min-width: 750px;
border-collapse: collapse;
margin: 1em 0 2em 0;
}
th, td {
vertical-align: top;
text-align: left;
padding: 5px 10px;
border-bottom: 1px solid #ccc;
}
thead th {
border-bottom: 1px solid #000;
}
thead th.key_fqdn {
min-width: 220px;
}
tbody th.key_fqdn {
line-height: 1.3em;
}
tbody th.key_fqdn b {
float: left;
}
tbody th.key_fqdn span {
color: transparent;
}
tbody th.key_fqdn i {
/* Show hostname and domain on two lines, but copying and pasting should
produce the FQDN without a newline */
clear: left;
float: left;
font-size: 90%;
font-style: normal;
font-weight: normal;
color: #666;
}
body#nodes .key_monitoring,
body#nodes .key_backups,
body#nodes .key_logging,
body#nodes .key_metrics {
text-align: center;
}
td ul,
td li {
margin: 0;
padding: 0;
}
td ul {
list-style-type: none;
}
td p {
margin: 0 0 1em 0;
}
.notes {
max-width: 40em;
}
.notes ol,
.notes ul {
list-style-position: inside;
margin: 1em 0;
padding: 0;
}
.notes ol { list-style-type: decimal }
.notes ul { list-style-type: disc }
.notes li {
margin: 0;
padding: 0;
}
body#node th,
body#service th {
width: 180px;
}

View file

@ -0,0 +1,16 @@
// Update generated at time at bottom of pages
(function(){
try {
var generated_at = document.getElementById("generated-at");
var m = moment(generated_at.innerText);
var update_generated_at = function () {
generated_at.innerText = "Generated on " + m.format("MMMM Do, YYYY")
+ " at " + m.format("h:mm a") + " (" + m.fromNow() + ")";
}
update_generated_at()
setInterval(update_generated_at, 60*1000);
} catch ( e ) {
console.error(e);
}
})();

4463
infinitory/static/moment.js Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,10 @@
{% extends "layout.html" %}
{% block title %}Puppet SRE Infrastructure{% endblock %}
{% block body %}
<h1>Puppet SRE Infrastructure</h1>
<ul>
<li><a href="nodes/index.html">Node inventory</a></li>
<li><a href="roles/index.html">Role inventory</a></li>
<li><a href="services/index.html">Service inventory</a></li>
</ul>
{% endblock %}

View file

@ -0,0 +1,29 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>∞ {% block title %}{% endblock %}</title>
<link rel="stylesheet" href="{{ path }}static/general.css">
<link rel="stylesheet" href="{{ path }}pygments.css">
<script src="{{ path }}../static/moment.js" defer></script>
<script src="{{ path }}../static/general.js" defer></script>
</head>
<body id="{{ body_id }}">
<nav>
<ul>
<li><a href="{{ path }}index.html" class="backward">Home</a></li>
<li class="infinitory-logo"></li>
<li><a href="{{ path }}nodes/index.html">Nodes</a></li>
<li><a href="{{ path }}roles/index.html">Roles</a></li>
<li><a href="{{ path }}services/index.html">Services</a></li>
</ul>
</nav>
<main>
{% block body %}{% endblock %}
</main>
<footer>
{% block footer %}{% endblock %}
<div id="generated-at">{{ generation_time }}</div>
</footer>
</body>
</html>

View file

@ -0,0 +1,15 @@
{% extends "layout.html" %}
{% block title %}Node {{ node["facts"]["fqdn"] }}{% endblock %}
{% block body %}
<h1>Node {{ node["facts"]["fqdn"] }}</h1>
<table>
<tbody>
{% for cell in columns %}
<tr>
{{ cell.head_html() }}
{{ cell.body_html(node) }}
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}

View file

@ -0,0 +1,26 @@
{% extends "layout.html" %}
{% block title %}Node inventory{% endblock %}
{% block body %}
<h1>Node inventory</h1>
<table>
<thead>
<tr>
{% for cell in columns %}
{{ cell.head_html() }}
{% endfor %}
</tr>
</thead>
<tbody>
{% for node in nodes %}
<tr>
{% for cell in columns %}
{{ cell.body_html(node) }}
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
{% block footer %}
<a href="../nodes.csv">Download CSV</a>
{% endblock %}

View file

@ -0,0 +1,27 @@
{% extends "layout.html" %}
{% block title %}Role inventory{% endblock %}
{% block body %}
<h1>Role inventory</h1>
<table>
<thead>
<tr>
<th>Role</th>
<th>Nodes</th>
</tr>
</thead>
<tbody>
{% for role, nodes in roles %}
<tr id="{{ role }}">
<th>{{ role }}</th>
<td>
<ul>
{% for node in nodes | sort(attribute="facts.fqdn") %}
<li><a href="../nodes/{{ node["certname"] }}.html">{{ node["facts"]["fqdn"] }}</a></li>
{% endfor %}
</ul>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}

View file

@ -0,0 +1,79 @@
{% extends "layout.html" %}
{% block title %}Service {{ service["human_name"] }}{% endblock %}
{% block body %}
<h1>Service {{ service["human_name"] }}</h1>
<table>
<tbody>
<tr>
<th>Class</th>
<td>{{ service["class_name"] }}</td>
</tr>
<tr>
<th>Documentation</th>
<td>
<ul>
{% for url in service["doc_urls"] %}
<li><a href="{{ url }}">{{url}}</a></li>
{% endfor %}
</ul>
</td>
</tr>
<tr>
<th>Downtime impact</th>
<td>{{ service["downtime_impact"] | unundef }}</td>
</tr>
<tr>
<th>End users</th>
<td>
{% if service["end_users"] != ":undef" %}
<ul>
{% for email in service["end_users"] %}
<li><a href="mailto:{{ email }}">{{email}}</a></li>
{% endfor %}
</ul>
{% endif %}
</td>
</tr>
<tr>
<th>Escalation period</th>
<td>{{ service["escalation_period"] | unundef }}</td>
</tr>
<tr>
<th>Notes</th>
<td>
<div class="notes">
{{ service["notes"] | unundef | markdown }}
</div>
</td>
</tr>
<tr>
<th>Other FQDNs</th>
<td>
<ul>
{% for fqdn in service["other_fqdns"] %}
<li>{{ fqdn }}</li>
{% endfor %}
</ul>
</td>
</tr>
<tr>
<th>Owner</th>
<td>{{ service["owner_uid"] | unundef }}</td>
</tr>
<tr>
<th>Team</th>
<td>{{ service["team"] | unundef }}</td>
</tr>
<tr>
<th>Nodes</th>
<td>
<ul>
{% for node in service["nodes"] | sort(attribute='facts.fqdn') %}
<li><a href="../nodes/{{ node["certname"] }}.html">{{ node["facts"]["fqdn"] }}</a></li>
{% endfor %}
</ul>
</td>
</tr>
</tbody>
</table>
{% endblock %}

View file

@ -0,0 +1,29 @@
{% extends "layout.html" %}
{% block title %}Service inventory{% endblock %}
{% block body %}
<h1>Service inventory</h1>
<table>
<thead>
<tr>
<th>Service</th>
<th>Nodes</th>
</tr>
</thead>
<tbody>
{% for service in services %}
<tr id="{{ service }}">
<th>
<a href="./{{ service["class_name"] }}.html">{{ service["human_name"] }}</a>
</th>
<td>
<ul>
{% for node in service["nodes"] | sort(attribute="facts.fqdn") %}
<li><a href="../nodes/{{ node["certname"] }}.html">{{ node["facts"]["fqdn"] }}</a></li>
{% endfor %}
</ul>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}