/[papo]/gnue/common/src/GConnections.py
ViewVC logotype

Diff of /gnue/common/src/GConnections.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.6 by styxman, Fri Nov 15 15:32:54 2002 UTC revision 1.6.2.1 by anthonyl, Tue Mar 4 22:09:32 2003 UTC
# Line 16  Line 16 
16  # write to the Free Software Foundation, Inc., 59 Temple Place  # write to the Free Software Foundation, Inc., 59 Temple Place
17  # - Suite 330, Boston, MA 02111-1307, USA.  # - Suite 330, Boston, MA 02111-1307, USA.
18  #  #
19  # Copyright 2000-2002 Free Software Foundation  # Copyright 2000-2003 Free Software Foundation
20  #  #
21  # FILE:  # FILE:
22  # GConnections.py  # GConnections.py
# Line 66  class GConnections: Line 66  class GConnections:
66      self._loginHandler = loginHandler      self._loginHandler = loginHandler
67      self._parser = ConfigParser()      self._parser = ConfigParser()
68      self._location = location      self._location = location
69        self._authenticatedUsers = {}
70    
71      GDebug.printMesg(1,'Conn File: "%s"' % location)      GDebug.printMesg(1,'Conn File: "%s"' % location)
72    
# Line 75  class GConnections: Line 76  class GConnections:
76        try:        try:
77          self._parser.readfp(fileHandle)          self._parser.readfp(fileHandle)
78        except DuplicateSectionError:        except DuplicateSectionError:
79          raise InvalidFormatError, \          tmsg =  _('The connections file has duplicate source definitions.\n\nFile: %s') \
            _('The connections file has duplicate source definitions.\n\nFile: %s') \  
80                % location                % location
81            raise InvalidFormatError, tmsg
82        except MissingSectionHeaderError:        except MissingSectionHeaderError:
83          raise InvalidFormatError, \          tmsg = _('The connections file has no source definitions.\n\nFile: %s') \
            _('The connections file has no source definitions.\n\nFile: %s') \  
84                % location                % location
85            raise InvalidFormatError, tmsg
86        except:        except:
87          raise InvalidFormatError, \          tmsg =  _('The connections file cannot be parsed.\n\nFile: %s') % location
88             _('The connections file cannot be parsed.\n\nFile: %s') % location          raise InvalidFormatError, tmsg
89    
90      self._openConnections = {}      self._openConnections = {}
91    
# Line 132  class GConnections: Line 133  class GConnections:
133        except:        except:
134          return default          return default
135      except KeyError:      except KeyError:
136        raise NotFoundError, \        tmsg = _('The connections file does not contain a definition \n       for "%s".\n\nFile: %s') \
          _('The connections file does not contain a definition \n       for "%s".\n\nFile: %s') \  
137              % (connection_name, self._location)              % (connection_name, self._location)
138          raise NotFoundError, tmsg
139    
140    
141    #    #
# Line 167  class GConnections: Line 168  class GConnections:
168      try:      try:
169        return copy.deepcopy(self._definitions[connection_name])        return copy.deepcopy(self._definitions[connection_name])
170      except KeyError:      except KeyError:
171        raise NotFoundError, \        tmsg = _('The connections file does not contain a definition \n       for "%s".\n\nFile: %s') \
          _('The connections file does not contain a definition \n       for "%s".\n\nFile: %s') \  
172              % (connection_name, self._location)              % (connection_name, self._location)
173          raise NotFoundError, tmsg
174    
175    
176    #    #
# Line 259  class GConnections: Line 260  class GConnections:
260            break            break
261    
262        if haveAllInformation:        if haveAllInformation:
263          if authenticator:          try:
264              self._authenticatedUsers[connection] = loginData['_username']
265            except KeyError:
266              self._authenticatedUsers[connection] = None
267    
268            if authenticator:
269            dataObject.connect(authenticator.login(loginData))            dataObject.connect(authenticator.login(loginData))
270          else:          else:
271            dataObject.connect(loginData)            dataObject.connect(loginData)
# Line 281  class GConnections: Line 287  class GConnections:
287              loginData.update(self._loginHandler.getLogin(              loginData.update(self._loginHandler.getLogin(
288                [connection_name,                [connection_name,
289                 self.getConnectionParameter(connection_name,'comment',''),                 self.getConnectionParameter(connection_name,'comment',''),
290                 dataObject.getLoginFields()], errortext))                 checkFields], errortext))
291    
292                # Add to authenticated user list
293                try:
294                  self._authenticatedUsers[connection] = loginData['_username']
295                except KeyError:
296                  self._authenticatedUsers[connection] = None
297    
298              # Ask the data object to connect to the database              # Ask the data object to connect to the database
299              dataObject.connect(loginData)              if authenticator:
300                  dataObject.connect(authenticator.login(loginData))
301                else:
302                  dataObject.connect(loginData)
303    
304              # Save the newly opened connection for future datasources              # Save the newly opened connection for future datasources
305              self._openConnections[connection_name] = \              self._openConnections[connection_name] = \
# Line 304  class GConnections: Line 319  class GConnections:
319              if not attempts:              if not attempts:
320                # Four times is plenty...                # Four times is plenty...
321                self._loginHandler.destroyLoginDialog()                self._loginHandler.destroyLoginDialog()
322                raise GDataObjects.LoginError, \                tmsg = _("Unable to log in after 4 attempts.\n\nError: %s") % error
323                      _("Unable to log in after 4 attempts.\n\nError: %s") % error                raise GDataObjects.LoginError, tmsg
324    
325            except GLoginHandler.UserCanceledLogin:            except GLoginHandler.UserCanceledLogin:
326              # Guess they changed their minds. Treat as a login error.              # Guess they changed their minds. Treat as a login error.
327              self._loginHandler.destroyLoginDialog()              self._loginHandler.destroyLoginDialog()
328              raise GDataObjects.LoginError, _("User canceled the login request.")              tmsg = _("User canceled the login request.")
329                raise GDataObjects.LoginError, tmsg
330    
331      def getAuthenticatedUser(self, connection=None):
332        try:
333          if connection == None:
334            return self._authenticatedUsers[self._authenticatedUsers.keys()[0]]
335          else:
336            return self._authenticatedUsers[connection]
337        except (KeyError, IndexError):
338          return None
339    
340    
341    
# Line 324  def _load_dbdriver(driver, type, connect Line 348  def _load_dbdriver(driver, type, connect
348    except ImportError, err:    except ImportError, err:
349      GDebug.printMesg(1,'ImportError importing driver %s' % (driver))      GDebug.printMesg(1,'ImportError importing driver %s' % (driver))
350      GDebug.printMesg(1,err)      GDebug.printMesg(1,err)
351      raise GDataObjects.ProviderNotSupportedError, \      tmsg = _("No database driver found for provider type '%s'") % driver
352         _("No database driver found for provider type '%s'") % driver      raise GDataObjects.ProviderNotSupportedError, tmsg
353    
354    try:    try:
355      dd = dbdriver.supportedDataObjects[type]()      dd = dbdriver.supportedDataObjects[type]()
356      GDebug.printMesg (1,'Attaching to %s (%s)' % (driver,dd.__class__.__name__))      GDebug.printMesg (1,'Attaching to %s (%s)' % (driver,dd.__class__.__name__))
357      return dd      return dd
358    except KeyError:    except KeyError:
359      raise GDataObjects.ObjectTypeNotAvailableError, \      tmsg = _("DB Driver '%s' does not support source type '%s'") % (driver, type)
360         _("DB Driver '%s' does not support source type '%s'") % (driver, type)      raise GDataObjects.ObjectTypeNotAvailableError, tmsg
361    
362    

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.6.2.1

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26