1 from twisted.web import resource, server |
1 from twisted.web import resource, server |
2 from twisted.internet import reactor |
2 from twisted.internet import reactor |
3 from twisted.python import log |
3 from twisted.python import log |
4 import sys |
|
5 |
4 |
6 from sqlalchemy import create_engine, pool |
5 from sqlalchemy import create_engine, pool |
7 |
|
8 import logging |
|
9 |
6 |
10 from .model import setEngine, setPool |
7 from .model import setEngine, setPool |
11 from .controller.pool import startPool, dbPool |
8 from .controller.pool import startPool, dbPool |
12 from .view import xmlrpc |
9 from .view import xmlrpc |
13 from . import config |
10 from . import config |
14 from .install import check, createSampleConfig |
|
15 |
11 |
16 def runReactor(reactor, engine, port, root): |
12 def runReactor(reactor, engine, port, root): |
17 setEngine(engine) |
13 setEngine(engine) |
18 startPool(reactor) |
14 startPool(reactor) |
19 setPool(dbPool) |
15 setPool(dbPool) |
20 |
16 |
21 reactor.listenTCP(port, server.Site(root)) |
17 reactor.listenTCP(port, server.Site(root)) |
22 logging.info("Server is running now...") |
18 log.msg("Server is running now...") |
23 reactor.run() |
19 reactor.run() |
24 |
20 |
25 |
21 |
26 if __name__ == '__main__': |
22 if __name__ == '__main__': |
27 |
23 |
28 if not check(): |
|
29 createSampleConfig() |
|
30 log.msg("Please edit iro.conf and run %s --install"%sys.argv[0]) |
|
31 |
|
32 config.readConfig() |
24 config.readConfig() |
33 |
25 |
34 engine = create_engine(config.main.dburl, |
26 engine = create_engine(config.main.dburl, |
35 poolclass = pool.SingletonThreadPool, pool_size=dbPool.maxthreads, ) |
27 poolclass = pool.SingletonThreadPool, pool_size=dbPool.maxthreads, ) |
36 |
28 |
38 root = resource.Resource() |
30 root = resource.Resource() |
39 root = xmlrpc.appendResource(root) |
31 root = xmlrpc.appendResource(root) |
40 |
32 |
41 v2 = resource.Resource() |
33 v2 = resource.Resource() |
42 v2 = xmlrpc.appendResource(root) |
34 v2 = xmlrpc.appendResource(root) |
43 root.addChild('2.0', v2) |
35 root.putChild('2.0', v2) |
44 |
36 |
45 |
|
46 runReactor(reactor, engine, config.main.port, root) |
37 runReactor(reactor, engine, config.main.port, root) |