comparison util.py @ 13:591ecc2a99bd

move logging configuration to the util module, configure logging for sqlalchemy
author Dirk Olmes <dirk@xanthippe.ping.de>
date Wed, 28 Apr 2010 02:23:00 +0200
parents database.py@9ede118b93ef
children 72dfae865899
comparison
equal deleted inserted replaced
12:9ede118b93ef 13:591ecc2a99bd
1
2 from ConfigParser import ConfigParser
3 import logging
4 import Mapping
5 import socket
6 from sqlalchemy import create_engine
7 from sqlalchemy.orm import sessionmaker
8
9 logger = logging.getLogger("database")
10
11 def configureLogging():
12 logging.basicConfig(level=logging.DEBUG)
13 logging.getLogger("sqlalchemy").setLevel(logging.INFO)
14 logging.getLogger("sqlalchemy.orm").setLevel(logging.WARN)
15
16 def createSession():
17 databaseUrl = loadDatabaseUrl()
18 engine = create_engine(databaseUrl,echo=True)
19 Mapping.createMapping(engine)
20 SessionMaker = sessionmaker(bind = engine)
21 session = SessionMaker()
22 return session
23
24 def loadDatabaseUrl():
25 hostname = socket.gethostname()
26 filename = "database-%s.ini" % hostname
27 logger.debug("loading database configuration from " + filename)
28
29 parser = ConfigParser();
30 parser.read(filename)
31 return parser.get("database", "url")