|
|
@@ -1,20 +1,53 @@ |
|
|
|
import cherrypy |
|
|
|
import sys |
|
|
|
import tables |
|
|
|
import nilmdb |
|
|
|
|
|
|
|
class 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 index(self, id = None): |
|
|
|
return "Base app" |
|
|
|
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': 8080 |
|
|
|
}) |
|
|
|
|
|
|
|
cherrypy.tree.mount(NilmDB(), "/") |
|
|
|
db = nilmdb.nilmdb() |
|
|
|
cherrypy.tree.mount(Root(db), "/") |
|
|
|
cherrypy.tree.mount(Stream(db), "/stream") |
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
cherrypy.server.quickstart() |
|
|
|
cherrypy.engine.start() |
|
|
|
cherrypy.engine.block() |