extras/iro.tac
branchdevel
changeset 286 ec5a280707f3
parent 270 665c3ea02d35
child 294 0e75bd39767d
equal deleted inserted replaced
285:9eb5b7ff0e38 286:ec5a280707f3
     1 from twisted.application.service import Service, Application
     1 from twisted.application.service import 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 
     2 
     7 from sqlalchemy import create_engine, pool
     3 from iro import iro
     8 
       
     9 from iro import config, install
       
    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         Service.startService(self)
       
    25 
       
    26 
     4 
    27 def get_application():
     5 def get_application():
    28     app = Application("Iro")
     6     app = Application("Iro")
    29     if not install.checkConfig():
     7     cfg={"config":"iro.conf"}
    30         log.err("You can create a sample configuration file by running iro-install")
     8     iro.makeService(cfg).setServiceParent(app)
    31         raise Exception("Please update or create your configuration file iro.conf.")
       
    32     config.init()
       
    33 
       
    34     if not install.checkDatabaseConnection():
       
    35         raise Exception("Can't connect to database")
       
    36     
       
    37     if not install.checkDatabase():
       
    38         raise Exception("Database not in right format. Please run iro-install --install")
       
    39 
       
    40     routes = [ s for s in config.configParser.sections() if not s in ["main",]]
       
    41     ao =  install.getAllRoutes(routes, False)
       
    42     for o in  ao["orphand"]:
       
    43         log.msg("Offer(%s) is orphand (no route using this offer)."%o)
       
    44     if ao["added"]:
       
    45         raise Exception("offerlist is not up-to-date.\nPlease run iro-install --update")
       
    46 
       
    47     root = resource.Resource()
       
    48     root = xmlrpc.appendResource(root)
       
    49     
       
    50     v2 = resource.Resource()
       
    51     v2 = xmlrpc.appendResource(root)
       
    52     root.putChild('2.0', v2)
       
    53 
       
    54     internet.TCPServer(config.main.port, server.Site(root)).setServiceParent(app)
       
    55     IroService().setServiceParent(app)
       
    56     return app
     9     return app
    57 
    10 
    58 application = get_application()
    11 application = get_application()