-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
executable file
·44 lines (34 loc) · 1.18 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Basic run script"""
import sys
import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web
import tornado.autoreload
from tornado.options import options
from tornado_sqlalchemy import make_session_factory
from settings import settings
from cheesypi.urls import url_patterns
from cheesypi.handlers.hardware_io import (
hardware_io_loop,
HydrometerPooler,
RelayController,
)
from cheesypi.models.base import Base
class TornadoApplication(tornado.web.Application):
def __init__(self):
tornado.web.Application.__init__(self, url_patterns, **settings)
def main(argv):
tornado.options.parse_command_line(args=argv)
session_factory = make_session_factory(options.dbname)
Base.metadata.create_all(session_factory._engine)
for HardwareIoClass in (HydrometerPooler, RelayController):
tornado.ioloop.IOLoop.current().spawn_callback(hardware_io_loop, HardwareIoClass, session_factory)
settings['session_factory'] = session_factory
app = TornadoApplication()
app.listen(options.port)
tornado.ioloop.IOLoop.current().start()
if __name__ == "__main__":
main(sys.argv)