Jim Paris
ef2db81d11
git-svn-id: https://bucket.mit.edu/svn/nilm/nilmdb@10367 ddd99763-3ecb-0310-9145-efcb8ce7c51f
54 lines
1009 B
Python
Executable File
54 lines
1009 B
Python
Executable File
import sys
|
|
import tables
|
|
import nilmdb
|
|
|
|
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):
|
|
"""NILM Database"""
|
|
|
|
server_version = "1.0"
|
|
|
|
@cherrypy.expose
|
|
def index(self):
|
|
raise cherrypy.NotFound()
|
|
|
|
@cherrypy.expose
|
|
def favicon_ico(self):
|
|
raise cherrypy.NotFound()
|
|
|
|
@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
|
|
|
|
cherrypy.config.update({
|
|
'server.socket_host': '127.0.0.1',
|
|
'server.socket_port': 12380
|
|
})
|
|
|
|
db = nilmdb.nilmdb()
|
|
cherrypy.tree.mount(Root(db), "/")
|
|
cherrypy.tree.mount(Stream(db), "/stream")
|
|
|
|
if __name__ == "__main__":
|
|
cherrypy.engine.start()
|
|
cherrypy.engine.block()
|