view database.py @ 12:9ede118b93ef

move session creation into its own module
author Dirk Olmes <dirk@xanthippe.ping.de>
date Wed, 28 Apr 2010 02:09:48 +0200
parents
children
line wrap: on
line source


from ConfigParser import ConfigParser
import Mapping
import socket
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

def createSession():
    databaseUrl = loadDatabaseUrl()
    engine = create_engine(databaseUrl,echo=True)
    Mapping.createMapping(engine)
    SessionMaker = sessionmaker(bind = engine)
    session = SessionMaker()
    return session

def loadDatabaseUrl():
    hostname = socket.gethostname()
    filename = "database-%s.ini" % hostname

    parser = ConfigParser();
    parser.read(filename)
    return parser.get("database", "url")