start documenting with reST syntax.
#!/usr/bin/env python2.7
from twisted.python import log
from sqlalchemy import create_engine, pool
from sqlalchemy.exc import ArgumentError
import sys
import logging
from iro.controller.pool import dbPool
from iro import config, __version__, install
observer = log.PythonLoggingObserver()
observer.start()
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(name)s(%(processName)s)-%(levelname)s: %(message)s')
import argparse
parser = argparse.ArgumentParser(description='Iro main routine.', version=__version__)
parser.add_argument('--install', action='store_true',
help='will create the right database layout.')
parser.add_argument('--update', action='store_true',
help='will install all routes and providers.')
args = parser.parse_args()
if not install.checkConfig():
install.createSampleConfig()
logging.info("Please edit iro.conf")
sys.exit(1)
config.init()
try:
engine = create_engine(config.main.dburl,
poolclass = pool.SingletonThreadPool, pool_size=dbPool.maxthreads, )
except ArgumentError:
logging.error("Can't connect to database")
logging.info("Please edit iro.conf")
sys.exit(1)
if not install.checkDatabaseConnection():
logging.error("Can't connect to database")
logging.info("Please edit iro.conf")
sys.exit(1)
if not install.checkDatabase():
logging.error("Database not in right format.")
if args.install:
install.createDatabase()
logging.info("Database layout created.")
logging.info("Now you can run "+sys.argv[0])
else:
logging.info("Please edit iro.conf and run %s --install"%sys.argv[0])
sys.exit(1)
routes = [ s for s in config.configParser.sections() if not s in ["main",]]
ao = install.getAllRoutes(routes, False)
for o in ao["orphand"]:
logging.info("Offer(%s) is orphand (no route using this offer)."%o)
if ao["added"]:
if args.install or args.update:
ao = install.getAllRoutes(routes,True)
for a in ao["added"]:
logging.info("Added Offer(%s)"%a)
logging.info('Updated offerlist.')
logging.info("Now you can run "+sys.argv[0])
else:
logging.warning('offerlist is not up-to-date.')
logging.info("Please run %s --update"%sys.argv[0])
sys.exit(1)
if args.install or args.update:
logging.info('Nothing todo for me.')
logging.info("Now you can run "+sys.argv[0])
sys.exit(1)
logging.info("You can just start your iro server.")
#start via cmdline
#root = resource.Resource()
#root = xmlrpc.appendResource(root)
#v2 = resource.Resource()
#v2 = xmlrpc.appendResource(root)
#root.putChild('2.0', v2)
#reactor.callLater(0.2, config.readConfig)
#main.runReactor(reactor, engine, config.main.port, root)