33 |
from ConfigParser import * |
from ConfigParser import * |
34 |
import sys, string, copy, netrc |
import sys, string, copy, netrc |
35 |
from gnue.common.apps import GDebug |
from gnue.common.apps import GDebug |
36 |
from gnue.common.datasources import GDataObjects |
from gnue.common.datasources import Exceptions |
37 |
from gnue.common.datasources import GLoginHandler |
from gnue.common.datasources import GLoginHandler |
38 |
from gnue.common.datasources.drivers import DRIVERS as ALLDRIVERS |
from gnue.common.datasources.drivers import DRIVERS as ALLDRIVERS |
39 |
from gnue.common.utils.FileUtils import openResource, dyn_import |
from gnue.common.utils.FileUtils import openResource, dyn_import |
56 |
# in an unreadable format. |
# in an unreadable format. |
57 |
pass |
pass |
58 |
|
|
59 |
LoginError = GDataObjects.LoginError |
LoginError = Exceptions.LoginError |
60 |
|
|
61 |
|
|
62 |
class GConnections: |
class GConnections: |
185 |
|
|
186 |
def getConnection(self, connection_name): |
def getConnection(self, connection_name): |
187 |
|
|
|
print "getConnection: %s" % (connection_name) |
|
188 |
|
|
189 |
connection_name = connection_name.lower() |
connection_name = connection_name.lower() |
190 |
|
|
200 |
# their own transactions, etc. |
# their own transactions, etc. |
201 |
connection_base = connection_name.split(':')[0] |
connection_base = connection_name.split(':')[0] |
202 |
|
|
|
print "connection_base=%s" % connection_base |
|
|
|
|
203 |
# This will throw a GConnections.NotFoundError if an unknown |
# This will throw a GConnections.NotFoundError if an unknown |
204 |
# connection name is specified. The calling method should |
# connection name is specified. The calling method should |
205 |
# catch this exception and handle it properly (exit w/message) |
# catch this exception and handle it properly (exit w/message) |
215 |
basedriver = driver |
basedriver = driver |
216 |
extradriver = "" |
extradriver = "" |
217 |
|
|
|
print "basedriver: %s; extradriver=%s" % (basedriver, extradriver) |
|
|
|
|
218 |
path = [] |
path = [] |
219 |
|
|
220 |
dbdriver = None |
dbdriver = None |
221 |
|
|
222 |
basemodule = _find_base_driver(basedriver, ALLDRIVERS) |
basemodule = _find_base_driver(basedriver, ALLDRIVERS) |
|
print "basemodule=%s" % basemodule |
|
223 |
GDebug.printMesg(1,'Using %s as base driver for %s' % (basemodule, driver)) |
GDebug.printMesg(1,'Using %s as base driver for %s' % (basemodule, driver)) |
224 |
|
|
225 |
if basemodule: |
if basemodule: |
227 |
|
|
228 |
if not dbdriver: |
if not dbdriver: |
229 |
tmsg = _("No database driver found for provider type '%s'") % driver |
tmsg = _("No database driver found for provider type '%s'") % driver |
230 |
raise GDataObjects.ProviderNotSupportedError, tmsg |
raise Exceptions.ProviderNotSupportedError, tmsg |
231 |
|
|
232 |
|
|
233 |
conn = dbdriver.Connection(self, connection_name, parameters) |
conn = dbdriver.Connection(self, connection_name, parameters) |
241 |
# |
# |
242 |
def getDataObject(self, connection_name, connection_type): |
def getDataObject(self, connection_name, connection_type): |
243 |
|
|
|
print "getDataObject: %s %s" % (connection_name, connection_type) |
|
|
|
|
244 |
# This will throw a GConnections.NotFoundError if an unknown |
# This will throw a GConnections.NotFoundError if an unknown |
245 |
# connection name is specified. The calling method should |
# connection name is specified. The calling method should |
246 |
# catch this exception and handle it properly (exit w/message) |
# catch this exception and handle it properly (exit w/message) |
247 |
connection = self.getConnection(connection_name) |
connection = self.getConnection(connection_name) |
248 |
|
|
249 |
try: |
try: |
250 |
dd = connection._supportedDataObjects[connection_type](connection) |
dd = connection.supportedDataObjects[connection_type](connection) |
251 |
GDebug.printMesg (1,'Attaching to %s (%s)' % (dd.__class__.__name__, connection_type)) |
GDebug.printMesg (1,'Attaching to %s (%s)' % (dd.__class__.__name__, connection_type)) |
252 |
return dd |
return dd |
253 |
except KeyError: |
except KeyError: |
254 |
tmsg = _("DB Driver '%s' does not support source type '%s'") % (connection, connection_type) |
tmsg = _("DB Driver '%s' does not support source type '%s'") % (connection, connection_type) |
255 |
raise GDataObjects.ObjectTypeNotAvailableError, tmsg |
raise Exceptions.ObjectTypeNotAvailableError, tmsg |
256 |
|
|
257 |
|
|
258 |
|
|
269 |
# |
# |
270 |
def requestConnection(self, dataObject): |
def requestConnection(self, dataObject): |
271 |
|
|
272 |
print "requestConnection: %s" % dataObject |
print """TODO: once this branch makes it into CVS head, |
273 |
|
eliminate the GConnections.requestConnection logic!""" |
274 |
|
|
275 |
# Support for multiple open connections |
# Support for multiple open connections |
276 |
# to same database. |
# to same database. |
279 |
# their own transactions, etc. |
# their own transactions, etc. |
280 |
|
|
281 |
self.loginToConnection(dataObject._connection) |
self.loginToConnection(dataObject._connection) |
282 |
|
dataObject.connect() |
283 |
|
|
284 |
|
|
285 |
def loginToConnection(self, connection): |
def loginToConnection(self, connection): |
287 |
connection_name = connection.name |
connection_name = connection.name |
288 |
connection_base = connection_name.split(':')[0] |
connection_base = connection_name.split(':')[0] |
289 |
|
|
|
print "loginToConnection: %s" % connection |
|
290 |
try: |
try: |
291 |
connected = connection.__connected |
connected = connection.__connected |
292 |
except AttributeError: |
except AttributeError: |
380 |
attempts = 0 |
attempts = 0 |
381 |
self._loginHandler.destroyLoginDialog() |
self._loginHandler.destroyLoginDialog() |
382 |
|
|
383 |
except GDataObjects.LoginError, error: |
except Exceptions.LoginError, error: |
384 |
# Oops, they must have entered an invalid user/password. |
# Oops, they must have entered an invalid user/password. |
385 |
# Those silly users. |
# Those silly users. |
386 |
# user: Hey! Who are you calling silly?!!! |
# user: Hey! Who are you calling silly?!!! |
393 |
# Four times is plenty... |
# Four times is plenty... |
394 |
#self._loginHandler.destroyLoginDialog() |
#self._loginHandler.destroyLoginDialog() |
395 |
tmsg = _("Unable to log in after 4 attempts.\n\nError: %s") % error |
tmsg = _("Unable to log in after 4 attempts.\n\nError: %s") % error |
396 |
raise GDataObjects.LoginError, tmsg |
raise Exceptions.LoginError, tmsg |
397 |
|
|
398 |
except GLoginHandler.UserCanceledLogin: |
except GLoginHandler.UserCanceledLogin: |
399 |
# Guess they changed their minds. Treat as a login error. |
# Guess they changed their minds. Treat as a login error. |
400 |
self._loginHandler.destroyLoginDialog() |
self._loginHandler.destroyLoginDialog() |
401 |
tmsg = _("User canceled the login request.") |
tmsg = _("User canceled the login request.") |
402 |
raise GDataObjects.LoginError, tmsg |
raise Exceptions.LoginError, tmsg |
403 |
|
|
404 |
connection.__connected = 1 |
connection.__connected = 1 |
405 |
|
|