Mercurial > hg > Feedworm
annotate BackendFactory.py @ 254:156edbd0733a pyqt5
the pyqt5 branch was merged into the default branch
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Fri, 10 Nov 2017 01:45:55 +0100 |
parents | e34c53a3e407 |
children | f79be01821c4 |
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() |
233
e34c53a3e407
fixes from eric's style check
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
217
diff
changeset
|
9 parser.add_argument("--backend", nargs="?", choices=[SQLALCHEMY_BACKEND, COUCHDB_BACKEND], |
137
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") |