# HG changeset patch # User Dirk Olmes # Date 1272413388 -7200 # Node ID 9ede118b93efa93344104a4362b8bc55c2b13a86 # Parent e87c54b3a216eb9c43e1e1934d48e0aa774d6c01 move session creation into its own module diff -r e87c54b3a216 -r 9ede118b93ef database.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/database.py Wed Apr 28 02:09:48 2010 +0200 @@ -0,0 +1,22 @@ + +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") diff -r e87c54b3a216 -r 9ede118b93ef feedupdate-main.py --- a/feedupdate-main.py Tue Apr 27 20:18:22 2010 +0200 +++ b/feedupdate-main.py Wed Apr 28 02:09:48 2010 +0200 @@ -1,24 +1,12 @@ #!/usr/bin/env python -from ConfigParser import ConfigParser +from database import createSession from Feed import Feed from FeedUpdater import updateAllFeeds -import Mapping import logging -import socket -from sqlalchemy import create_engine -from sqlalchemy.orm import sessionmaker logger = logging.getLogger("feedupdater") -def loadDatabaseProperties(): - hostname = socket.gethostname() - filename = "database-%s.ini" % hostname - - parser = ConfigParser(); - parser.read(filename) - return parser.get("database", "url") - def createFeed(session): if len(session.query(Feed).all()) == 0: newFeed = Feed("Joel on Software", "http://www.joelonsoftware.com/rss.xml") @@ -33,11 +21,7 @@ print entry.title if __name__ == "__main__": - databaseUrl = loadDatabaseProperties() - engine = create_engine(databaseUrl,echo=True) - Mapping.createMapping(engine) - SessionMaker = sessionmaker(bind = engine) - session = SessionMaker() + session = createSession() createFeed(session) updateAllFeeds(session)