#!/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.")
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.')
else:
logging.warning('offerlist is not up-to-date.')
logging.info("Please run %s --update"%sys.argv[0])
sys.exit(1)
logging.info("You can just start your iro server.")