extras/iro.tac
branchdevel
changeset 237 eb3501d2cdc9
parent 229 1bd4c7f58b3f
child 270 665c3ea02d35
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/extras/iro.tac	Wed Mar 21 17:36:05 2012 +0100
@@ -0,0 +1,41 @@
+from twisted.application.service import Service, Application
+from twisted.application import internet
+from twisted.web import resource, server
+from twisted.internet import reactor
+from twisted.python import log
+
+from sqlalchemy import create_engine, pool
+
+from iro import config
+from iro.view import xmlrpc
+from iro.model import setEngine, setPool
+from iro.controller.pool import startPool, dbPool
+
+class IroService(Service):
+    def startService(self):
+        log.msg("Starting service...")
+        engine = create_engine(config.main.dburl,
+               poolclass = pool.SingletonThreadPool,  pool_size=dbPool.maxthreads, )
+
+        setEngine(engine)
+        startPool(reactor)
+        setPool(dbPool)
+        reactor.callWhenRunning(config.readConfig)
+
+
+def get_application():
+    app = Application("Iro")
+    config.init()
+
+    root = resource.Resource()
+    root = xmlrpc.appendResource(root)
+    
+    v2 = resource.Resource()
+    v2 = xmlrpc.appendResource(root)
+    root.putChild('2.0', v2)
+
+    internet.TCPServer(config.main.port, server.Site(root)).setServiceParent(app)
+    IroService().setServiceParent(app)
+    return app
+
+application = get_application()