Mercurial > hg > Feedworm
annotate BackendFactory.py @ 231:16fa9f090c36
hard-code python2
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Thu, 25 Sep 2014 08:06:51 +0200 |
parents | bb3c851b18b1 |
children | e34c53a3e407 |
rev | line source |
---|---|
217
bb3c851b18b1
add source file endcoding header
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
137
diff
changeset
|
1 # -*- coding: utf-8 -*- |
137
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") |