Mercurial > hg > Feedworm
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/BackendFactory.py Tue Aug 23 14:36:58 2011 +0200 @@ -0,0 +1,23 @@ + +import argparse + +SQLALCHEMY_BACKEND = "sqlalchemy" +COUCHDB_BACKEND = "couchdb" + +def _parseArguments(): + parser = argparse.ArgumentParser() + parser.add_argument("--backend", nargs="?", choices=[SQLALCHEMY_BACKEND, COUCHDB_BACKEND], + required=True, help="Specify the backend to use: either sqlalchemy or couchdb") + return parser.parse_known_args() + +def createBackend(): + args = _parseArguments() + backend = args[0].backend + if backend == SQLALCHEMY_BACKEND: + from backend.sqlalchemy.SqlAlchemyBackend import SqlAlchemyBackend + return SqlAlchemyBackend() + elif backend == COUCHDB_BACKEND: + from backend.couchdb.CouchDbBackend import CouchDbBackend + return CouchDbBackend() + else: + raise Exception("no backend configured")