2012-01-21 17:39:51 -05:00
|
|
|
import sys
|
|
|
|
import tables
|
|
|
|
import nilmdb
|
2012-01-20 17:41:32 -05:00
|
|
|
|
2012-01-21 17:39:51 -05:00
|
|
|
try:
|
|
|
|
import cherrypy
|
|
|
|
cherrypy.tools.json_out
|
|
|
|
except:
|
|
|
|
sys.stderr.write("Cherrypy 3.2+ required\n")
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
class NilmApp:
|
|
|
|
def __init__(self, db):
|
|
|
|
self.db = db
|
|
|
|
|
|
|
|
class Root(NilmApp):
|
2012-01-20 17:41:32 -05:00
|
|
|
"""NILM Database"""
|
|
|
|
|
2012-01-21 17:39:51 -05:00
|
|
|
server_version = "1.0"
|
|
|
|
|
|
|
|
@cherrypy.expose
|
|
|
|
def index(self):
|
|
|
|
raise cherrypy.NotFound()
|
|
|
|
|
2012-01-20 17:41:32 -05:00
|
|
|
@cherrypy.expose
|
2012-01-21 17:39:51 -05:00
|
|
|
def favicon_ico(self):
|
|
|
|
raise cherrypy.NotFound()
|
2012-01-20 17:41:32 -05:00
|
|
|
|
2012-01-21 17:39:51 -05:00
|
|
|
@cherrypy.expose
|
|
|
|
@cherrypy.tools.json_out()
|
|
|
|
def version(self):
|
|
|
|
return self.server_version
|
|
|
|
|
|
|
|
class Stream(NilmApp):
|
|
|
|
"""Stream operations"""
|
|
|
|
|
|
|
|
@cherrypy.expose
|
|
|
|
@cherrypy.tools.json_out()
|
|
|
|
def list(self):
|
|
|
|
return
|
|
|
|
|
2012-01-20 17:41:32 -05:00
|
|
|
cherrypy.config.update({
|
|
|
|
'server.socket_host': '127.0.0.1',
|
2012-02-08 13:01:05 -05:00
|
|
|
'server.socket_port': 12380
|
2012-01-20 17:41:32 -05:00
|
|
|
})
|
|
|
|
|
2012-01-21 17:39:51 -05:00
|
|
|
db = nilmdb.nilmdb()
|
|
|
|
cherrypy.tree.mount(Root(db), "/")
|
|
|
|
cherrypy.tree.mount(Stream(db), "/stream")
|
2012-01-20 17:41:32 -05:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
cherrypy.engine.start()
|
|
|
|
cherrypy.engine.block()
|