1 from twisted.application.service import Service, Application |
|
2 from twisted.application import internet |
|
3 from twisted.web import resource, server |
|
4 from twisted.internet import reactor |
|
5 from twisted.python import log |
|
6 |
|
7 from sqlalchemy import create_engine, pool |
|
8 |
|
9 from iro import config |
|
10 from iro.view import xmlrpc |
|
11 from iro.model import setEngine, setPool |
|
12 from iro.controller.pool import startPool, dbPool |
|
13 |
|
14 class IroService(Service): |
|
15 def startService(self): |
|
16 log.msg("Starting service...") |
|
17 engine = create_engine(config.main.dburl, |
|
18 poolclass = pool.SingletonThreadPool, pool_size=dbPool.maxthreads, ) |
|
19 |
|
20 setEngine(engine) |
|
21 startPool(reactor) |
|
22 setPool(dbPool) |
|
23 reactor.callWhenRunning(config.readConfig) |
|
24 |
|
25 |
|
26 def get_application(): |
|
27 app = Application("Iro") |
|
28 config.init() |
|
29 |
|
30 root = resource.Resource() |
|
31 root = xmlrpc.appendResource(root) |
|
32 |
|
33 v2 = resource.Resource() |
|
34 v2 = xmlrpc.appendResource(root) |
|
35 root.putChild('2.0', v2) |
|
36 |
|
37 internet.TCPServer(config.main.port, server.Site(root)).setServiceParent(app) |
|
38 IroService().setServiceParent(app) |
|
39 return app |
|
40 |
|
41 application = get_application() |
|