Mercurial > hg > Feedworm
comparison BackendFactory.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 | |
children | bb3c851b18b1 |
comparison
equal
deleted
inserted
replaced
136:7217b060b39c | 137:5b131f82057d |
---|---|
1 | |
2 import argparse | |
3 | |
4 SQLALCHEMY_BACKEND = "sqlalchemy" | |
5 COUCHDB_BACKEND = "couchdb" | |
6 | |
7 def _parseArguments(): | |
8 parser = argparse.ArgumentParser() | |
9 parser.add_argument("--backend", nargs="?", choices=[SQLALCHEMY_BACKEND, COUCHDB_BACKEND], | |
10 required=True, help="Specify the backend to use: either sqlalchemy or couchdb") | |
11 return parser.parse_known_args() | |
12 | |
13 def createBackend(): | |
14 args = _parseArguments() | |
15 backend = args[0].backend | |
16 if backend == SQLALCHEMY_BACKEND: | |
17 from backend.sqlalchemy.SqlAlchemyBackend import SqlAlchemyBackend | |
18 return SqlAlchemyBackend() | |
19 elif backend == COUCHDB_BACKEND: | |
20 from backend.couchdb.CouchDbBackend import CouchDbBackend | |
21 return CouchDbBackend() | |
22 else: | |
23 raise Exception("no backend configured") |