|
1 # Copyright (c) 2012 netzguerilla.net <iro@netzguerilla.net> |
|
2 # |
|
3 # This file is part of Iro. |
|
4 # |
|
5 # Permission is hereby granted, free of charge, to any person obtaining a copy of |
|
6 # this software and associated documentation files (the "Software"), to deal in |
|
7 # the Software without restriction, including without limitation the rights to use, |
|
8 # copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the |
|
9 # #Software, and to permit persons to whom the Software is furnished to do so, |
|
10 # subject to the following conditions: |
|
11 # |
|
12 # The above copyright notice and this permission notice shall be included in |
|
13 # all copies or substantial portions of the Software. |
|
14 # |
|
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, |
|
16 # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A |
|
17 # PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
18 # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
|
19 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
|
20 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|
21 |
|
22 from twisted.web import resource, server |
|
23 from twisted.internet import reactor |
|
24 from twisted.python import log |
|
25 |
|
26 from sqlalchemy import create_engine, pool |
|
27 |
|
28 from .model import setEngine, setPool |
|
29 from .controller.pool import startPool, dbPool |
|
30 from .view import xmlrpc, jsonrpc, jsonresource |
|
31 from . import config |
|
32 |
|
33 def runReactor(reactor, engine, port, root): |
|
34 """start reactor. |
|
35 |
|
36 :param reactor: twisted reactor |
|
37 :param engine: sqlalchemy engine |
|
38 :param integer port: port to listen to |
|
39 :param `twisted.web.resource.Resource` root: resource to share |
|
40 """ |
|
41 setEngine(engine) |
|
42 startPool(reactor) |
|
43 setPool(dbPool) |
|
44 |
|
45 reactor.listenTCP(port, server.Site(root)) |
|
46 log.msg("Server is running now...") |
|
47 reactor.run() |
|
48 |
|
49 |
|
50 if __name__ == '__main__': |
|
51 |
|
52 config.readConfig() |
|
53 |
|
54 engine = create_engine(config.main.dburl, |
|
55 poolclass = pool.SingletonThreadPool, pool_size=dbPool.maxthreads, pool_recycle=3600) |
|
56 |
|
57 |
|
58 root = resource.Resource() |
|
59 xmlrpc.appendResource(root) |
|
60 jsonrpc.appendResource(root) |
|
61 jsonresource.appendResource(root) |
|
62 |
|
63 v2 = resource.Resource() |
|
64 xmlrpc.appendResource(v2) |
|
65 jsonrpc.pappendResource(v2) |
|
66 jsonresource.pappendResource(v2) |
|
67 root.putChild('1.0a', v2) |
|
68 |
|
69 runReactor(reactor, engine, config.main.port, root) |