2012-02-20 00:52:33 -05:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
import nilmdb
|
2012-05-08 13:40:11 -04:00
|
|
|
import argparse
|
|
|
|
|
2013-01-01 23:03:53 -05:00
|
|
|
formatter = argparse.ArgumentDefaultsHelpFormatter
|
|
|
|
parser = argparse.ArgumentParser(description='Run the NILM server',
|
|
|
|
formatter_class = formatter)
|
2012-05-08 13:40:11 -04:00
|
|
|
parser.add_argument('-p', '--port', help='Port number', type=int, default=12380)
|
2013-01-01 23:03:53 -05:00
|
|
|
parser.add_argument('-d', '--database', help='Database directory', default="db")
|
2012-05-08 13:40:11 -04:00
|
|
|
parser.add_argument('-y', '--yappi', help='Run with yappi profiler',
|
|
|
|
action='store_true')
|
|
|
|
args = parser.parse_args()
|
2012-02-20 00:52:33 -05:00
|
|
|
|
|
|
|
# Start web app on a custom port
|
2013-01-01 23:03:53 -05:00
|
|
|
db = nilmdb.NilmDB(args.database)
|
2012-02-20 00:52:33 -05:00
|
|
|
server = nilmdb.Server(db, host = "127.0.0.1",
|
2012-05-08 13:40:11 -04:00
|
|
|
port = args.port,
|
2012-04-03 14:01:56 -04:00
|
|
|
embedded = False)
|
2012-05-03 15:17:48 -04:00
|
|
|
|
2012-05-08 13:40:11 -04:00
|
|
|
|
|
|
|
if args.yappi:
|
|
|
|
print "Running in yappi"
|
2012-05-03 15:17:48 -04:00
|
|
|
try:
|
|
|
|
import yappi
|
|
|
|
yappi.start()
|
|
|
|
server.start(blocking = True)
|
|
|
|
finally:
|
|
|
|
yappi.stop()
|
2012-05-08 13:40:11 -04:00
|
|
|
print "Try: yappi.print_stats(sort_type=yappi.SORTTYPE_TTOT,limit=50)"
|
2012-05-03 15:17:48 -04:00
|
|
|
from IPython import embed
|
|
|
|
embed()
|
2012-05-08 13:40:11 -04:00
|
|
|
else:
|
|
|
|
server.start(blocking = True)
|
2012-02-20 00:52:33 -05:00
|
|
|
db.close()
|