Skip to content
Snippets Groups Projects
Commit b7d1ed39 authored by jkerdreu's avatar jkerdreu
Browse files

Initial release


git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Python/branches/fork@1684 b32b6428-25c9-4566-ad07-03861ab6144f
parent 7350bc19
Branches
No related tags found
No related merge requests found
Showing
with 645 additions and 0 deletions
from setuptools import setup,find_packages
with open('README.rst') as f:
long_description = f.read()
VERSION = "0.1"
setup(
name='xaal.dashboard',
version=VERSION,
license='GPL License',
author='Jerome Kerdreux',
author_email='Jerome.Kerdreux@imt-atlantique.fr',
#url='',
description=('xAAL Dashboard'),
long_description=long_description,
classifiers=[
'Programming Language :: Python',
'Topic :: Software Development :: Libraries :: Python Modules',
],
keywords=['xaal', 'socketio','html','dashboard'],
platforms='any',
packages=find_packages(),
include_package_data=True,
install_requires=[
'xaal.lib',
'bottle',
'gevent',
'gevent-websocket',
]
)
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
from . import app
app.main()
from gevent import monkey; monkey.patch_all()
from bottle import default_app,debug,get,redirect,static_file
from gevent.pywsgi import WSGIServer
from geventwebsocket.handler import WebSocketHandler
from pages import default_pages
from core import xaal_core
@get('/static/<filename:path>')
def send_static(filename):
return static_file(filename, root='./static/')
@get('/')
def goto_home():
redirect('/test/')
def run():
""" start the xAAL stack & launch the HTTP stuff"""
xaal_core.setup()
app = default_app()
# debug disable template cache & enable error reporting
debug(True)
server = WSGIServer(("", 9090), app, handler_class=WebSocketHandler)
server.serve_forever()
def main():
try:
run()
except KeyboardInterrupt:
print("Bye Bye...")
#import pdb;pdb.set_trace()
if __name__ == '__main__':
main()
from xaal.lib import tools,Engine,Device
from xaal.monitor import Monitor
import platform
from gevent import Greenlet
import time
# dev-type that don't appear in results
BLACK_LIST=['cli.experimental',]
PACKAGE_NAME = "xaal.socketio"
logger = tools.get_logger(PACKAGE_NAME,'DEBUG')
# we use this global variable to share data with greenlet
monitor = None
# used for uptime
started = time.time()
def monitor_filter(msg):
""" Filter incomming messages. Return False if you don't want to use this device"""
if msg.devtype in BLACK_LIST:
return False
return True
def setup():
""" setup xAAL Engine & Device. And start it in a Greenlet"""
global monitor
engine = Engine()
cfg = tools.load_cfg_or_die(PACKAGE_NAME)
dev = Device("hmi.basic")
dev.address = cfg['config']['addr']
dev.vendor_id = "IHSEV"
dev.product_id = "WEB Interface"
dev.version = 0.1
dev.info = "%s@%s" % (PACKAGE_NAME,platform.node())
engine.add_device(dev)
monitor = Monitor(dev,filter_func=monitor_filter)
engine.start()
green_let = Greenlet(xaal_loop, engine)
green_let.start()
def xaal_loop(engine):
""" xAAL Engine Loop Greenlet"""
while 1:
engine.loop()
def get_uptime():
return int(time.time() - started)
#!/bin/sh
while true; do
python app.py &
PID=$!
hl "App started.."
sleep 1
inotifywait -r . -e modify -e create -e delete
hl "Killing app"
kill $PID
done
import bottle
# add the default template directory to the bottle search path
bottle.TEMPLATE_PATH.append('./templates/')
from .default import view,route,xaal_core
from bottle import request
import copy
@route('/stats')
@view('stats.mako')
def stats():
total = 0
results = {}
for dev in xaal_core.monitor.devices:
total = total + 1
try:
k = dev.devtype
results[k]=results[k]+1
except KeyError:
results.update({k:1})
return {"title":"Network stats","total":total,"devtypes":results,"uptime": xaal_core.get_uptime()}
@route('/bottle_info')
@view('bottle_info.mako')
def info():
environ = copy.copy(request.environ)
return {"title":"BottleInfo","headers" : request.headers,"query":request.query,"environ":environ}
from bottle import route
from bottle import mako_view as view
from core import xaal_core
from . import test
from . import base
from .default import view,route
from core import xaal_core
@route('/test')
@view('basic.mako')
def test_01():
f = ""
for d in xaal_core.monitor.devices:
f = f + "%s %s" % (d.address,d.devtype) +"\n"
f = f + str(d.attributes)
f = f + "\n\n"
return {"title":"Test","content":f}
@font-face {
font-family: defaultfont;
src: url(../fonts/sansation_light.woff);
}
body {
margin:0;
font-family: defaultfont;
}
pre {
background-color: #eee;
overflow-x:auto;
}
/*===========================================================================*/
/* TOP Menu */
/*===========================================================================*/
ul.menu {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
position: fixed; /* Set the navbar to fixed position */
top: 0; /* Position the navbar at the top of the page */
width: 100%; /* Full width */
box-shadow: 0px 4px 4px #aaaaaa;
}
ul.menu li {
float: left;
}
ul.menu li a {
display: block;
color: white;
padding: 10px;
text-decoration: none;
transition: all 0.2s ease;
font-weight: bold;
}
ul.menu li.active {
background-color: #bc4676;
}
ul.menu li a:hover {
background-color: #777;
}
.panel {
border: 1px solid #555;
min-width: 300px;
float: left;
margin: 5px;
}
.panel-heading {
background-color: #00bbd7;
color: #fff;
font-weight: bold;
}
#main {
transition: margin-left .5s;
padding: 16px;
margin-left: 1em;
margin-right: 1em;
margin-top: 40px;
}
/*===========================================================================*/
/* Side Nav */
/*===========================================================================*/
.sidenav {
height: 100%;
width: 0;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: #333;
overflow-x: hidden;
transition: 0.5s;
padding-top: 60px;
box-shadow: 2px 0px 4px #aaaaaa;
}
.sidenav a {
padding: 4px 4px 4px 32px;
text-decoration: none;
display: block;
transition: all 0.2s ease;
color: white;
font-weight: bold;
}
.sidenav a:hover, .offcanvas a:focus{
color: #f1f1f1;
background-color: #777;
}
.sidenav .closebtn {
position: absolute;
top: 0;
right: 25px;
margin-left: 50px;
}
@media screen and (max-height: 450px) {
.sidenav {padding-top: 15px;}
.sidenav a {font-size: 18px;}
}
h1,h2 {
color: #00bbd7;
}
table {
border-collapse: collapse;
width: 800;
}
th, td {
padding: 6px;
text-align: left;
border-bottom: 1px solid #ddd;
}
th {
background: #00bbd7;
color: white;
}
a:link {
text-decoration: none;
color: #00bbd7;
}
a:visited {
text-decoration: none;
color: #00bbd7;
}
a:hover {
text-decoration: underline;
}
a:active {
text-decoration: underline;
}
File added
This diff is collapsed.
File added
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment