iro/main.py
changeset 302 3f4bdea2abbf
parent 298 503ed1a61543
child 308 a891fdd0c1a9
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/iro/main.py	Thu Sep 27 17:15:46 2012 +0200
@@ -0,0 +1,69 @@
+# Copyright (c) 2012 netzguerilla.net <iro@netzguerilla.net>
+# 
+# This file is part of Iro.
+# 
+# Permission is hereby granted, free of charge, to any person obtaining a copy of
+# this software and associated documentation files (the "Software"), to deal in
+# the Software without restriction, including without limitation the rights to use,
+# copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
+# #Software, and to permit persons to whom the Software is furnished to do so,
+# subject to the following conditions:
+# 
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+# 
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
+# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+from twisted.web import resource, server
+from twisted.internet import reactor
+from twisted.python import log
+
+from sqlalchemy import create_engine, pool
+
+from .model import setEngine, setPool
+from .controller.pool import startPool, dbPool
+from .view import xmlrpc, jsonrpc, jsonresource
+from . import config
+
+def runReactor(reactor, engine, port, root):
+    """start reactor.
+    
+    :param reactor: twisted reactor
+    :param engine: sqlalchemy engine
+    :param integer port: port to listen to
+    :param `twisted.web.resource.Resource` root: resource to share
+    """
+    setEngine(engine)
+    startPool(reactor)
+    setPool(dbPool)
+    
+    reactor.listenTCP(port, server.Site(root))
+    log.msg("Server is running now...")
+    reactor.run()
+
+
+if __name__ == '__main__':
+   
+    config.readConfig()
+
+    engine = create_engine(config.main.dburl,
+           poolclass = pool.SingletonThreadPool,  pool_size=dbPool.maxthreads, pool_recycle=3600)
+
+
+    root = resource.Resource()
+    xmlrpc.appendResource(root)
+    jsonrpc.appendResource(root)
+    jsonresource.appendResource(root)
+    
+    v2 = resource.Resource()
+    xmlrpc.appendResource(v2)
+    jsonrpc.pappendResource(v2)
+    jsonresource.pappendResource(v2)
+    root.putChild('1.0a', v2)
+
+    runReactor(reactor, engine, config.main.port, root)