bin/iro-install
author Sandro Knauß <knauss@netzguerilla.net>
Fri, 06 Jul 2012 13:11:20 +0200
branchdevel
changeset 284 f3be8a77b3e2
parent 270 665c3ea02d35
child 294 0e75bd39767d
permissions -rwxr-xr-x
iro-install: using nicer output

#!/usr/bin/env python2.7
from twisted.python import log

from sqlalchemy import create_engine, pool
from sqlalchemy.exc import ArgumentError
import sys,os

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 installer.')
parser.add_argument('-v', '--version', action='version', version="%s %s"%(os.path.basename(sys.argv[0]),__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"%os.path.basename(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"%os.path.basename(sys.argv[0]))
        sys.exit(1)

logging.info("You can just start your iro server.")