Mercurial > hg > Feedworm
view Database.py @ 71:228da10cc98b
MainWindow relies on FeedList to get the feeds to display now. FeedList has two inner/private classes: one for returning all known feeds and one to return only feeds with unread entries.
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Wed, 11 Aug 2010 03:10:32 +0200 |
parents | 842727971796 |
children |
line wrap: on
line source
import Mapping import sqlalchemy import sqlalchemy.orm import sys import util # Keep the connection to the database only once. The feed updater and the GUI app will # operate on a single engine/session but this comes in handy for interactive use engine = None SessionMaker = None def createSession(databaseUrl=None): if databaseUrl is None: databaseUrl = _getDatabaseUrl() initEngine(databaseUrl) Mapping.createMapping(engine) initSessionMaker() return SessionMaker() def _getDatabaseUrl(): if len(sys.argv) < 2: print("Usage: %s <database url>" % (sys.argv[0])) sys.exit(1) return sys.argv[1] def initEngine(databaseUrl): global engine if engine is None: verbose = util.databaseLoggingEnabled() engine = sqlalchemy.create_engine(databaseUrl, echo=verbose) def initSessionMaker(): global SessionMaker if SessionMaker is None: SessionMaker = sqlalchemy.orm.sessionmaker(bind=engine)