comparison backend/sqlalchemy/Database.py @ 137:5b131f82057d

allow choosing the backend via commandline option
author Dirk Olmes <dirk@xanthippe.ping.de>
date Tue, 23 Aug 2011 14:36:58 +0200
parents 04a730f9d07d
children bb3c851b18b1
comparison
equal deleted inserted replaced
136:7217b060b39c 137:5b131f82057d
1 1
2 from sqlalchemy.engine import create_engine 2 from sqlalchemy.engine import create_engine
3 from sqlalchemy.orm import sessionmaker 3 from sqlalchemy.orm import sessionmaker
4 import Mapping 4 import Mapping
5 import sys 5 import argparse
6 import util 6 import util
7 7
8 # Keep the connection to the database only once. The feed updater and the GUI app will 8 # Keep the connection to the database only once. The feed updater and the GUI app will
9 # operate on a single engine/session but this comes in handy for interactive use 9 # operate on a single engine/session but this comes in handy for interactive use
10 engine = None 10 engine = None
17 Mapping.createMapping(engine) 17 Mapping.createMapping(engine)
18 initSessionMaker() 18 initSessionMaker()
19 return SessionMaker() 19 return SessionMaker()
20 20
21 def _getDatabaseUrl(): 21 def _getDatabaseUrl():
22 if len(sys.argv) < 2: 22 parser = argparse.ArgumentParser()
23 print("Usage: %s <database url>" % (sys.argv[0])) 23 parser.add_argument("--dburl", nargs="?", required=True, help="Database URL for the sqlalchemy backend")
24 sys.exit(1) 24 args = parser.parse_known_args()
25 return sys.argv[1] 25 return args[0].dburl
26 26
27 def initEngine(databaseUrl): 27 def initEngine(databaseUrl):
28 global engine 28 global engine
29 if engine is None: 29 if engine is None:
30 verbose = util.databaseLoggingEnabled() 30 verbose = util.databaseLoggingEnabled()