Add static site generator
parent
3820cb60a5
commit
e29ca1be0d
|
@ -0,0 +1,38 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import pkg_resources
|
||||||
|
import shutil
|
||||||
|
|
||||||
|
import mqtt_dash.app
|
||||||
|
from mqtt_dash.app import app
|
||||||
|
|
||||||
|
args = argparse.ArgumentParser()
|
||||||
|
|
||||||
|
args.add_argument('config', default='config.py', help='Configuration file')
|
||||||
|
|
||||||
|
options = args.parse_args()
|
||||||
|
|
||||||
|
app.secret_key = os.urandom(12)
|
||||||
|
app.config.from_pyfile(os.path.abspath(options.config))
|
||||||
|
|
||||||
|
|
||||||
|
missing_config_fields = False
|
||||||
|
for opt in ('URL', 'MQTT_BROKER', 'PAGE_TITLE', 'WIDGETS'):
|
||||||
|
if opt not in app.config:
|
||||||
|
print(f'Error: field {opt} missing in configuration')
|
||||||
|
missing_config_fields = True
|
||||||
|
if missing_config_fields:
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
client = app.test_client()
|
||||||
|
r = client.get('/')
|
||||||
|
with open("dashboard.html", "wb") as f:
|
||||||
|
f.write(r.data)
|
||||||
|
|
||||||
|
static_assets = pkg_resources.resource_filename('mqtt_dash', 'static')
|
||||||
|
shutil.copytree(static_assets, "static")
|
||||||
|
|
|
@ -5,10 +5,10 @@
|
||||||
<meta name="viewport" content="width=device-width,initial-scale=0.8"/>
|
<meta name="viewport" content="width=device-width,initial-scale=0.8"/>
|
||||||
<!-- http://paletton.com/#uid=13w0u0kllllaFw0g0qFqFg0w0aF -->
|
<!-- http://paletton.com/#uid=13w0u0kllllaFw0g0qFqFg0w0aF -->
|
||||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.8.0/css/bulma.min.css">
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.8.0/css/bulma.min.css">
|
||||||
<link rel="stylesheet" href="/static/style.css">
|
<link rel="stylesheet" href="static/style.css">
|
||||||
|
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/paho-mqtt/1.0.2/mqttws31.min.js" type="text/javascript"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/paho-mqtt/1.0.2/mqttws31.min.js" type="text/javascript"></script>
|
||||||
<script src="/static/main.js"></script>
|
<script src="static/main.js"></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
window.onload = function() { init("{{mqtt_broker}}")};
|
window.onload = function() { init("{{mqtt_broker}}")};
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -9,6 +9,6 @@ setup(
|
||||||
author='0xee',
|
author='0xee',
|
||||||
author_email='mqtt-dash@0xee.eu',
|
author_email='mqtt-dash@0xee.eu',
|
||||||
packages=['mqtt_dash'],
|
packages=['mqtt_dash'],
|
||||||
scripts=['mqtt-dash'],
|
scripts=['mqtt-dash', 'make-static-site'],
|
||||||
package_data={'mqtt_dash': ['templates/*.html', 'static/*']},
|
package_data={'mqtt_dash': ['templates/*.html', 'static/*']},
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue