5
5
# http://binux.me
6
6
# Created on 2014-10-08 15:04:08
7
7
8
- import os , requests , json
8
+ import os
9
+ import json
10
+ import requests
9
11
from six .moves .urllib .parse import urlparse , parse_qs
10
12
11
13
@@ -55,48 +57,38 @@ def _connect_database(url): # NOQA
55
57
scheme = parsed .scheme .split ('+' )
56
58
if len (scheme ) == 1 :
57
59
raise Exception ('wrong scheme format: %s' % parsed .scheme )
58
- else :
59
- engine , dbtype = scheme [0 ], scheme [- 1 ]
60
- other_scheme = "+" .join (scheme [1 :- 1 ])
60
+ engine , dbtype = scheme [0 ], scheme [- 1 ]
61
+ other_scheme = "+" .join (scheme [1 :- 1 ])
61
62
62
63
if dbtype not in ('taskdb' , 'projectdb' , 'resultdb' ):
63
64
raise LookupError ('unknown database type: %s, '
64
65
'type should be one of ["taskdb", "projectdb", "resultdb"]' , dbtype )
65
66
66
67
if engine == 'mysql' :
67
68
return _connect_mysql (parsed ,dbtype )
68
-
69
- elif engine == 'sqlite' :
69
+ if engine == 'sqlite' :
70
70
return _connect_sqlite (parsed ,dbtype )
71
- elif engine == 'mongodb' :
71
+ if engine == 'mongodb' :
72
72
return _connect_mongodb (parsed ,dbtype ,url )
73
-
74
- elif engine == 'sqlalchemy' :
73
+ if engine == 'sqlalchemy' :
75
74
return _connect_sqlalchemy (parsed , dbtype , url , other_scheme )
76
-
77
-
78
- elif engine == 'redis' :
75
+ if engine == 'redis' :
79
76
if dbtype == 'taskdb' :
80
77
from .redis .taskdb import TaskDB
81
78
return TaskDB (parsed .hostname , parsed .port ,
82
79
int (parsed .path .strip ('/' ) or 0 ))
83
- else :
84
- raise LookupError ('not supported dbtype: %s' , dbtype )
85
- elif engine == 'local' :
80
+ raise LookupError ('not supported dbtype: %s' , dbtype )
81
+ if engine == 'local' :
86
82
scripts = url .split ('//' , 1 )[1 ].split (',' )
87
83
if dbtype == 'projectdb' :
88
84
from .local .projectdb import ProjectDB
89
85
return ProjectDB (scripts )
90
- else :
91
- raise LookupError ('not supported dbtype: %s' , dbtype )
92
- elif engine == 'elasticsearch' or engine == 'es' :
86
+ raise LookupError ('not supported dbtype: %s' , dbtype )
87
+ if engine == 'elasticsearch' or engine == 'es' :
93
88
return _connect_elasticsearch (parsed , dbtype )
94
-
95
- elif engine == 'couchdb' :
89
+ if engine == 'couchdb' :
96
90
return _connect_couchdb (parsed , dbtype , url )
97
-
98
- else :
99
- raise Exception ('unknown engine: %s' % engine )
91
+ raise Exception ('unknown engine: %s' % engine )
100
92
101
93
102
94
def _connect_mysql (parsed ,dbtype ):
@@ -115,14 +107,13 @@ def _connect_mysql(parsed,dbtype):
115
107
if dbtype == 'taskdb' :
116
108
from .mysql .taskdb import TaskDB
117
109
return TaskDB (** parames )
118
- elif dbtype == 'projectdb' :
110
+ if dbtype == 'projectdb' :
119
111
from .mysql .projectdb import ProjectDB
120
112
return ProjectDB (** parames )
121
- elif dbtype == 'resultdb' :
113
+ if dbtype == 'resultdb' :
122
114
from .mysql .resultdb import ResultDB
123
115
return ResultDB (** parames )
124
- else :
125
- raise LookupError
116
+ raise LookupError
126
117
127
118
128
119
def _connect_sqlite (parsed ,dbtype ):
@@ -138,14 +129,13 @@ def _connect_sqlite(parsed,dbtype):
138
129
if dbtype == 'taskdb' :
139
130
from .sqlite .taskdb import TaskDB
140
131
return TaskDB (path )
141
- elif dbtype == 'projectdb' :
132
+ if dbtype == 'projectdb' :
142
133
from .sqlite .projectdb import ProjectDB
143
134
return ProjectDB (path )
144
- elif dbtype == 'resultdb' :
135
+ if dbtype == 'resultdb' :
145
136
from .sqlite .resultdb import ResultDB
146
137
return ResultDB (path )
147
- else :
148
- raise LookupError
138
+ raise LookupError
149
139
150
140
151
141
def _connect_mongodb (parsed ,dbtype ,url ):
@@ -157,14 +147,13 @@ def _connect_mongodb(parsed,dbtype,url):
157
147
if dbtype == 'taskdb' :
158
148
from .mongodb .taskdb import TaskDB
159
149
return TaskDB (url , ** parames )
160
- elif dbtype == 'projectdb' :
150
+ if dbtype == 'projectdb' :
161
151
from .mongodb .projectdb import ProjectDB
162
152
return ProjectDB (url , ** parames )
163
- elif dbtype == 'resultdb' :
153
+ if dbtype == 'resultdb' :
164
154
from .mongodb .resultdb import ResultDB
165
155
return ResultDB (url , ** parames )
166
- else :
167
- raise LookupError
156
+ raise LookupError
168
157
169
158
170
159
def _connect_sqlalchemy (parsed , dbtype ,url , other_scheme ):
@@ -174,14 +163,13 @@ def _connect_sqlalchemy(parsed, dbtype,url, other_scheme):
174
163
if dbtype == 'taskdb' :
175
164
from .sqlalchemy .taskdb import TaskDB
176
165
return TaskDB (url )
177
- elif dbtype == 'projectdb' :
166
+ if dbtype == 'projectdb' :
178
167
from .sqlalchemy .projectdb import ProjectDB
179
168
return ProjectDB (url )
180
- elif dbtype == 'resultdb' :
169
+ if dbtype == 'resultdb' :
181
170
from .sqlalchemy .resultdb import ResultDB
182
171
return ResultDB (url )
183
- else :
184
- raise LookupError
172
+ raise LookupError
185
173
186
174
187
175
def _connect_elasticsearch (parsed , dbtype ):
@@ -198,10 +186,10 @@ def _connect_elasticsearch(parsed, dbtype):
198
186
if dbtype == 'projectdb' :
199
187
from .elasticsearch .projectdb import ProjectDB
200
188
return ProjectDB ([parsed .netloc ], index = index )
201
- elif dbtype == 'resultdb' :
189
+ if dbtype == 'resultdb' :
202
190
from .elasticsearch .resultdb import ResultDB
203
191
return ResultDB ([parsed .netloc ], index = index )
204
- elif dbtype == 'taskdb' :
192
+ if dbtype == 'taskdb' :
205
193
from .elasticsearch .taskdb import TaskDB
206
194
return TaskDB ([parsed .netloc ], index = index )
207
195
@@ -220,11 +208,10 @@ def _connect_couchdb(parsed, dbtype, url):
220
208
if dbtype == 'taskdb' :
221
209
from .couchdb .taskdb import TaskDB
222
210
return TaskDB (url , ** params )
223
- elif dbtype == 'projectdb' :
211
+ if dbtype == 'projectdb' :
224
212
from .couchdb .projectdb import ProjectDB
225
213
return ProjectDB (url , ** params )
226
- elif dbtype == 'resultdb' :
214
+ if dbtype == 'resultdb' :
227
215
from .couchdb .resultdb import ResultDB
228
216
return ResultDB (url , ** params )
229
- else :
230
- raise LookupError
217
+ raise LookupError
0 commit comments