Mercurial > hg > Feedworm
annotate BackendFactory.py @ 146:8ec20377bcb0
move getting the entries for a feed to the backend so that the couchdb backend can use a custom view for feed entries
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Thu, 25 Aug 2011 07:01:45 +0200 |
parents | 5b131f82057d |
children | bb3c851b18b1 |
rev | line source |
---|---|
137
5b131f82057d
allow choosing the backend via commandline option
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
1 |
5b131f82057d
allow choosing the backend via commandline option
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
2 import argparse |
5b131f82057d
allow choosing the backend via commandline option
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
3 |
5b131f82057d
allow choosing the backend via commandline option
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
4 SQLALCHEMY_BACKEND = "sqlalchemy" |
5b131f82057d
allow choosing the backend via commandline option
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
5 COUCHDB_BACKEND = "couchdb" |
5b131f82057d
allow choosing the backend via commandline option
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
6 |
5b131f82057d
allow choosing the backend via commandline option
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
7 def _parseArguments(): |
5b131f82057d
allow choosing the backend via commandline option
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
8 parser = argparse.ArgumentParser() |
5b131f82057d
allow choosing the backend via commandline option
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
9 parser.add_argument("--backend", nargs="?", choices=[SQLALCHEMY_BACKEND, COUCHDB_BACKEND], |
5b131f82057d
allow choosing the backend via commandline option
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
10 required=True, help="Specify the backend to use: either sqlalchemy or couchdb") |
5b131f82057d
allow choosing the backend via commandline option
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
11 return parser.parse_known_args() |
5b131f82057d
allow choosing the backend via commandline option
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
12 |
5b131f82057d
allow choosing the backend via commandline option
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
13 def createBackend(): |
5b131f82057d
allow choosing the backend via commandline option
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
14 args = _parseArguments() |
5b131f82057d
allow choosing the backend via commandline option
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
15 backend = args[0].backend |
5b131f82057d
allow choosing the backend via commandline option
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
16 if backend == SQLALCHEMY_BACKEND: |
5b131f82057d
allow choosing the backend via commandline option
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
17 from backend.sqlalchemy.SqlAlchemyBackend import SqlAlchemyBackend |
5b131f82057d
allow choosing the backend via commandline option
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
18 return SqlAlchemyBackend() |
5b131f82057d
allow choosing the backend via commandline option
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
19 elif backend == COUCHDB_BACKEND: |
5b131f82057d
allow choosing the backend via commandline option
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
20 from backend.couchdb.CouchDbBackend import CouchDbBackend |
5b131f82057d
allow choosing the backend via commandline option
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
21 return CouchDbBackend() |
5b131f82057d
allow choosing the backend via commandline option
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
22 else: |
5b131f82057d
allow choosing the backend via commandline option
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
23 raise Exception("no backend configured") |