Mercurial > hg > Feedworm
comparison Database.py @ 37:22214d79ed41
database URL must be given as commandline argument now, no need for creating complicated config files. Add a menu entry for opening the selected article in browser.
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Fri, 14 May 2010 06:16:05 +0200 |
parents | 5813e3c10f14 |
children | 254d5b89a6ca |
comparison
equal
deleted
inserted
replaced
36:74b8c9a9d5de | 37:22214d79ed41 |
---|---|
1 | 1 |
2 import Mapping | 2 import Mapping |
3 import sqlalchemy | 3 import sqlalchemy |
4 import sqlalchemy.orm | 4 import sqlalchemy.orm |
5 import util | 5 import sys |
6 | 6 |
7 # Keep the connection to the database only once. The feed updater and the GUI app will | 7 # Keep the connection to the database only once. The feed updater and the GUI app will |
8 # operate on a single engine/session but this comes in handy for interactive use | 8 # operate on a single engine/session but this comes in handy for interactive use |
9 engine = None | 9 engine = None |
10 SessionMaker = None | 10 SessionMaker = None |
11 | 11 |
12 def createSession(): | 12 def createSession(): |
13 databaseUrl = util.loadDatabaseUrl() | 13 databaseUrl = _getDatabaseUrl() |
14 initEngine(databaseUrl) | 14 initEngine(databaseUrl) |
15 Mapping.createMapping(engine) | 15 Mapping.createMapping(engine) |
16 initSessionMaker() | 16 initSessionMaker() |
17 return SessionMaker() | 17 return SessionMaker() |
18 | 18 |
19 def _getDatabaseUrl(): | |
20 if len(sys.argv) < 2: | |
21 print("Usage: %s <database url>" % (sys.argv[0])) | |
22 sys.exit(1) | |
23 return sys.argv[1] | |
24 | |
19 def initEngine(databaseUrl): | 25 def initEngine(databaseUrl): |
20 global engine | 26 global engine |
21 if engine is None: | 27 if engine is None: |
22 engine = sqlalchemy.create_engine(databaseUrl, echo=False) | 28 engine = sqlalchemy.create_engine(databaseUrl, echo=True) |
23 | 29 |
24 def initSessionMaker(): | 30 def initSessionMaker(): |
25 global SessionMaker | 31 global SessionMaker |
26 if SessionMaker is None: | 32 if SessionMaker is None: |
27 SessionMaker = sqlalchemy.orm.sessionmaker(bind=engine) | 33 SessionMaker = sqlalchemy.orm.sessionmaker(bind=engine) |