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

- rest can now run with fakeinput (on the same pkgrun instance)

git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Python/branches/0.7@2924 b32b6428-25c9-4566-ad07-03861ab6144f
parent 39878bec
No related branches found
No related tags found
No related merge requests found
......@@ -4,7 +4,7 @@ from gevent import monkey; monkey.patch_all(thread=False)
from xaal.lib import Engine,Device,helpers,tools,cbor
from xaal.monitor import Monitor
from bottle import default_app,debug,get,request,response,redirect,static_file
from bottle import Bottle,debug,get,request,response,redirect,static_file
from . import json
import os
......@@ -23,6 +23,7 @@ logger = logging.getLogger(PACKAGE_NAME)
monitor = None
cfg = None
server = None
app = Bottle()
def monitor_filter(msg):
""" Filter incomming messages. Return False if you don't want to use this device"""
......@@ -69,18 +70,18 @@ def search_device(addr):
dev=monitor.devices.get_with_addr(uid)
return dev
@get('/static/<filename:path>')
@app.get('/static/<filename:path>')
def send_static(filename):
root = os.path.dirname(__file__)
root = os.path.join(root,'static')
return static_file(filename, root=root)
@get('/')
@app.get('/')
def goto_html():
redirect('/static/index.html')
@get('/devices')
@get('/devices/')
@app.get('/devices')
@app.get('/devices/')
def list_devices():
""" Return the list of devices in JSON"""
l = []
......@@ -93,7 +94,7 @@ def list_devices():
response.headers['Content-Type'] = 'application/json'
return json_encode(l)
@get('/devices/<addr>')
@app.get('/devices/<addr>')
def get_device(addr):
""" Return the full description of a device """
response.headers['Content-Type'] = 'application/json'
......@@ -109,7 +110,7 @@ def get_device(addr):
response.status=404
return json_encode(res)
@get('/devices/<addr>/<action>')
@app.get('/devices/<addr>/<action>')
def send_request(addr,action):
""" quick & dirty way to send request to device"""
body = {}
......@@ -142,7 +143,6 @@ def run():
global server
helpers.set_console_title(PACKAGE_NAME)
helpers.setup_console_logger(level=logging.INFO)
app = default_app()
debug(True)
port = int(cfg.get('config').get('port',8080))
logger.info("HTTP Server running on port : %d" % port)
......@@ -150,7 +150,6 @@ def run():
server.serve_forever()
def stop():
global server
server.stop()
def main():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment