|
21 | 21 |
|
22 | 22 |
|
23 | 23 | class ServiceManager():
|
24 |
| - def __init__(self, debug=False): |
| 24 | + def __init__(self, debug=False, conn_dict = None): |
25 | 25 | self.debug = debug
|
26 | 26 | f = self._get_file('r')
|
27 | 27 | self._conn_dicts = []
|
28 | 28 | self.version = 0
|
29 | 29 | self._connection_format = "%s+%s://%s:%s@%s/%s"
|
30 | 30 |
|
31 | 31 | # Read all lines (connections) in the connection.cfg file
|
32 |
| - while True: |
33 |
| - line = f.readline() |
34 |
| - if not line: |
35 |
| - break |
36 |
| - else: |
37 |
| - line = line.split() |
38 |
| - #logger.debug(line) |
39 |
| - |
40 |
| - if len(line) >= 5: |
41 |
| - line_dict = {} |
42 |
| - |
43 |
| - line_dict['engine'] = line[0] |
44 |
| - line_dict['user'] = line[1] |
45 |
| - line_dict['password'] = line[2] |
46 |
| - line_dict['address'] = line[3] |
47 |
| - line_dict['db'] = line[4] |
48 |
| - self._conn_dicts.append(line_dict) |
| 32 | + if conn_dict is None: |
| 33 | + while True: |
| 34 | + line = f.readline() |
| 35 | + if not line: |
| 36 | + break |
| 37 | + else: |
| 38 | + line = line.split() |
| 39 | + #logger.debug(line) |
| 40 | + |
| 41 | + if len(line) >= 5: |
| 42 | + line_dict = {} |
| 43 | + |
| 44 | + line_dict['engine'] = line[0] |
| 45 | + line_dict['user'] = line[1] |
| 46 | + line_dict['password'] = line[2] |
| 47 | + line_dict['address'] = line[3] |
| 48 | + line_dict['db'] = line[4] |
| 49 | + self._conn_dicts.append(line_dict) |
| 50 | + else: |
| 51 | + self._conn_dicts.append(conn_dict) |
49 | 52 |
|
50 | 53 | if len(self._conn_dicts) is not 0:
|
51 | 54 | # The current connection defaults to the most recent (i.e. the last written to the file)
|
@@ -152,7 +155,7 @@ def get_cv_service(self):
|
152 | 155 | return CVService(conn_string, self.debug)
|
153 | 156 |
|
154 | 157 | def get_edit_service(self, series_id, connection):
|
155 |
| - |
| 158 | + |
156 | 159 | return EditService(series_id, connection=connection, debug=self.debug)
|
157 | 160 |
|
158 | 161 | def get_record_service(self, script, series_id, connection):
|
@@ -186,81 +189,27 @@ def _get_file(self, mode):
|
186 | 189 | return config_file
|
187 | 190 |
|
188 | 191 | def _build_connection_string(self, conn_dict):
|
189 |
| -<<<<<<< Updated upstream |
190 |
| - # driver = "" |
191 |
| - # connformat= self._connection_format |
192 |
| - # if conn_dict['engine'] == 'mssql' and sys.platform != 'win32': |
193 |
| - # driver = "pyodbc" |
194 |
| - # quoted = urllib.quote_plus('DRIVER={FreeTDS};DSN=%s;UID=%s;PWD=%s;' % (conn_dict['address'], conn_dict['user'], conn_dict['password'])) |
195 |
| - # conn_string = 'mssql+pyodbc:///?odbc_connect={}'.format(quoted) |
196 |
| - # |
197 |
| - # else: |
198 |
| - # if conn_dict['engine'] == 'mssql': |
199 |
| - # driver = "pyodbc" |
200 |
| - # connformat=self._connection_format = "%s+%s://%s:%s@%s/%s?driver=SQL+Server+Native+Client+10.0" |
201 |
| - # elif conn_dict['engine'] == 'mysql': |
202 |
| - # driver = "pymysql" |
203 |
| - # elif conn_dict['engine'] == 'postgresql': |
204 |
| - # driver = "psycopg2" |
205 |
| - # else: |
206 |
| - # driver = "None" |
207 |
| - # |
208 |
| - # conn_string = connformat % ( |
209 |
| - # conn_dict['engine'], driver, conn_dict['user'], conn_dict['password'], conn_dict['address'], |
210 |
| - # conn_dict['db']) |
211 |
| - # return conn_string |
212 |
| - # driver = "" |
213 |
| - # print "****", conn_dict |
214 |
| -======= |
215 |
| - self._connection_format = "%s+%s://%s:%s@%s/%s" |
216 |
| ->>>>>>> Stashed changes |
| 192 | + driver = "" |
| 193 | + connformat= self._connection_format |
217 | 194 | if conn_dict['engine'] == 'mssql' and sys.platform != 'win32':
|
218 | 195 | driver = "pyodbc"
|
219 |
| - quoted = urllib.quote_plus('DRIVER={FreeTDS};DSN=%s;UID=%s;PWD=%s;' % (conn_dict['address'], conn_dict['user'], |
220 |
| - conn_dict['password'])) |
221 |
| - # quoted = urllib.quote_plus('DRIVER={FreeTDS};DSN=%s;UID=%s;PWD=%s;DATABASE=%s' % |
222 |
| - # (conn_dict['address'], conn_dict['user'], conn_dict['password'],conn_dict['db'], |
223 |
| - # )) |
| 196 | + quoted = urllib.quote_plus('DRIVER={FreeTDS};DSN=%s;UID=%s;PWD=%s;' % (conn_dict['address'], conn_dict['user'], conn_dict['password'])) |
224 | 197 | conn_string = 'mssql+pyodbc:///?odbc_connect={}'.format(quoted)
|
| 198 | + elif conn_dict['engine']=='sqlite': |
| 199 | + connformat = "%s:///%s" |
| 200 | + conn_string = connformat%(conn_dict['engine'], conn_dict['address']) |
225 | 201 | else:
|
226 | 202 | if conn_dict['engine'] == 'mssql':
|
227 | 203 | driver = "pyodbc"
|
228 |
| - conn = "%s+%s://%s:%s@%s/%s?driver=SQL+Server" |
229 |
| - if "sqlncli11.dll" in os.listdir("C:\\Windows\\System32"): |
230 |
| - conn = "%s+%s://%s:%s@%s/%s?driver=SQL+Server+Native+Client+11.0" |
231 |
| - self._connection_format = conn |
232 |
| - conn_string = self._connection_format % ( |
233 |
| - conn_dict['engine'], driver, conn_dict['user'], conn_dict['password'], conn_dict['address'], |
234 |
| - conn_dict['db']) |
| 204 | + connformat=self._connection_format = "%s+%s://%s:%s@%s/%s?driver=SQL+Server+Native+Client+10.0" |
235 | 205 | elif conn_dict['engine'] == 'mysql':
|
236 | 206 | driver = "pymysql"
|
237 |
| - conn_string = self.constringBuilder(conn_dict, driver) |
238 | 207 | elif conn_dict['engine'] == 'postgresql':
|
239 | 208 | driver = "psycopg2"
|
240 |
| - conn_string = self.constringBuilder(conn_dict, driver) |
241 | 209 | else:
|
242 | 210 | driver = "None"
|
243 |
| - conn_string = self.constringBuilder(conn_dict, driver) |
244 |
| -<<<<<<< Updated upstream |
245 |
| - |
246 | 211 |
|
247 |
| - # print "******", conn_string |
248 |
| - return conn_string |
249 |
| - |
250 |
| -======= |
251 |
| - |
252 |
| - |
253 |
| - # print "******", conn_string |
254 |
| - return conn_string |
255 |
| - |
256 |
| ->>>>>>> Stashed changes |
257 |
| - def constringBuilder(self, conn_dict, driver): |
258 |
| - if conn_dict['password'] is None or not conn_dict['password']: |
259 |
| - conn_string = self._connection_format_nopassword % ( |
260 |
| - conn_dict['engine'], driver, conn_dict['user'], conn_dict['address'], |
261 |
| - conn_dict['db']) |
262 |
| - else: |
263 |
| - conn_string = self._connection_format % ( |
| 212 | + conn_string = connformat % ( |
264 | 213 | conn_dict['engine'], driver, conn_dict['user'], conn_dict['password'], conn_dict['address'],
|
265 | 214 | conn_dict['db'])
|
266 | 215 | return conn_string
|
|
0 commit comments