Skip to content

Commit b739c06

Browse files
author
sreeder
committed
update db connection to ehlp switch connections
1 parent 50c53a0 commit b739c06

File tree

2 files changed

+41
-8
lines changed

2 files changed

+41
-8
lines changed

odmtools/odmservices/service_manager.py

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def __init__(self, debug=False):
2626
f = self._get_file('r')
2727
self._conn_dicts = []
2828
self.version = 0
29-
self._connection_format = "%s+%s://%s:%s@%s/%s"
29+
3030

3131
# Read all lines (connections) in the connection.cfg file
3232
while True:
@@ -185,30 +185,62 @@ def _get_file(self, mode):
185185

186186
return config_file
187187

188+
# def _build_connection_string(self, conn_dict):
189+
# driver = ""
190+
# connformat= self._connection_format
191+
# if conn_dict['engine'] == 'mssql' and sys.platform != 'win32':
192+
# driver = "pyodbc"
193+
# quoted = urllib.quote_plus('DRIVER={FreeTDS};DSN=%s;UID=%s;PWD=%s;' % (conn_dict['address'], conn_dict['user'], conn_dict['password']))
194+
# conn_string = 'mssql+pyodbc:///?odbc_connect={}'.format(quoted)
195+
#
196+
# else:
197+
# if conn_dict['engine'] == 'mssql':
198+
# driver = "pyodbc"
199+
# connformat=self._connection_format = "%s+%s://%s:%s@%s/%s?driver=SQL+Server+Native+Client+10.0"
200+
# elif conn_dict['engine'] == 'mysql':
201+
# driver = "pymysql"
202+
# elif conn_dict['engine'] == 'postgresql':
203+
# driver = "psycopg2"
204+
# else:
205+
# driver = "None"
206+
#
207+
# conn_string = connformat % (
208+
# conn_dict['engine'], driver, conn_dict['user'], conn_dict['password'], conn_dict['address'],
209+
# conn_dict['db'])
210+
# return conn_string
188211
def _build_connection_string(self, conn_dict):
189-
driver = ""
190-
connformat= self._connection_format
212+
# driver = ""
213+
# print "****", conn_dict
214+
191215
if conn_dict['engine'] == 'mssql' and sys.platform != 'win32':
192216
driver = "pyodbc"
217+
#'DRIVER={FreeTDS};DSN=%s;UID=%s;PWD=%s;' % (conn_dict['address'], conn_dict['user'], conn_dict['password'])
193218
quoted = urllib.quote_plus('DRIVER={FreeTDS};DSN=%s;UID=%s;PWD=%s;' % (conn_dict['address'], conn_dict['user'], conn_dict['password']))
194219
conn_string = 'mssql+pyodbc:///?odbc_connect={}'.format(quoted)
195-
196220
else:
221+
self._connection_format = "%s+%s://%s:%s@%s/%s"
197222
if conn_dict['engine'] == 'mssql':
198223
driver = "pyodbc"
199-
connformat=self._connection_format = "%s+%s://%s:%s@%s/%s?driver=SQL+Server+Native+Client+10.0"
224+
#self._connection_format = "%s+%s://%s:%s@%s/%s?driver=SQL+Server+Native+Client+10.0"
225+
conn = "%s+%s://%s:%s@%s/%s?driver=SQL+Server"
226+
if "sqlncli11.dll" in os.listdir("C:\\Windows\\System32"):
227+
conn = "%s+%s://%s:%s@%s/%s?driver=SQL+Server+Native+Client+11.0"
228+
self._connection_format = conn
200229
elif conn_dict['engine'] == 'mysql':
201230
driver = "pymysql"
202231
elif conn_dict['engine'] == 'postgresql':
203232
driver = "psycopg2"
204233
else:
205234
driver = "None"
206235

207-
conn_string = connformat % (
236+
conn_string = self._connection_format % (
208237
conn_dict['engine'], driver, conn_dict['user'], conn_dict['password'], conn_dict['address'],
209238
conn_dict['db'])
239+
240+
# print "******", conn_string
210241
return conn_string
211242

243+
212244
def _save_connections(self):
213245
f = self._get_file('w')
214246
for conn in self._conn_dicts:

requirements.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__author__ = 'stephanie'
1+
22
pyodbc
33
pymysql
44
numpy
@@ -8,4 +8,5 @@ sqlalchemy
88
matplotlib
99
pandas
1010
geoalchemy2
11-
wxpython
11+
#wxpython
12+

0 commit comments

Comments
 (0)