/[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.5 by charlie, Tue Aug 27 18:15:51 2002 UTC revision 1.6 by styxman, Fri Nov 15 15:32:54 2002 UTC
# Line 35  import sys, string, copy, netrc Line 35  import sys, string, copy, netrc
35  import GDebug  import GDebug
36  import GDataObjects  import GDataObjects
37  import GLoginHandler  import GLoginHandler
38  from gnue.common import openResource, dyn_import  from gnue.common.FileUtils import openResource, dyn_import
39    
40  class Error(StandardError):  class Error(StandardError):
41    # Base error    # Base error
# Line 56  class InvalidFormatError (Error): Line 56  class InvalidFormatError (Error):
56    # in an unreadable format.    # in an unreadable format.
57    pass    pass
58    
59    LoginError = GDataObjects.LoginError
60    
61    
62  class GConnections:  class GConnections:
63    
# Line 76  class GConnections: Line 78  class GConnections:
78          raise InvalidFormatError, \          raise InvalidFormatError, \
79             _('The connections file has duplicate source definitions.\n\nFile: %s') \             _('The connections file has duplicate source definitions.\n\nFile: %s') \
80                % location                % location
81        except MissingSectionError:        except MissingSectionHeaderError:
82          raise InvalidFormatError, \          raise InvalidFormatError, \
83             _('The connections file has no source definitions.\n\nFile: %s') \             _('The connections file has no source definitions.\n\nFile: %s') \
84                % location                % location
# Line 209  class GConnections: Line 211  class GConnections:
211        GDebug.printMesg(5,'Reusing data connection to %s' % connection_name)        GDebug.printMesg(5,'Reusing data connection to %s' % connection_name)
212    
213      else:      else:
214          
215        # Get the parameters from the Connections Definition File        # Get the parameters from the Connections Definition File
216        loginData = self.getConnectionParameters(connection_name)        loginData = self.getConnectionParameters(connection_name)
217        netrcData = None  
218        try:        try:
219          # load the user's netrc file          # load the user's netrc file:
220          netrcData = netrc.netrc().authenticators("'gnue://%s/%s/%s'" %          # a sample .netrc could look like:
221                                                   ( loginData['host'],          # <.netrc begin>
222                                                     loginData['provider'],          # machine 'gnue://my_connection/'
223                                                     loginData['dbname'],          # login 'mylogin'
224                                                     )          # password 'mypassword'
225                                                   )          # EOF
226          GDebug.printMesg(5, 'Read the user\'s .netrc file')          # (Remark: if .netrc should work under Win32 you have to
227        except IOError:          #  set the HOME environement variable [SET HOME=...])
228    
229            netrcData = netrc.netrc().authenticators(
230                  "'gnue://%s/'" % connection_name )
231            if netrcData!=None:
232              GDebug.printMesg(5, 'Read the user\'s .netrc file')
233              loginData['_username'] = netrcData[0][1:-1]
234              loginData['_password'] = netrcData[2][1:-1]
235              GDebug.printMesg(5, 'Found useful stuff for connection %s in the user\'s .netrc file' % connection_name)
236          except (IOError,netrc.NetrcParseError,KeyError):
237          pass          pass
238    
       if (netrcData):  
         loginData['username'] = netrcData[0][1:-1]  
         loginData['password'] = netrcData[2][1:-1]  
         GDebug.printMesg(5, 'Found useful stuff for connection %s in the user\'s .netrc file' % connection_name)  
   
239        if (loginData.has_key('username')):        if (loginData.has_key('username')):
240          loginData['_username'] = loginData['username']          loginData['_username'] = loginData['username']
241          del loginData['username']          del loginData['username']
# Line 238  class GConnections: Line 244  class GConnections:
244          loginData['_password'] = loginData['password']          loginData['_password'] = loginData['password']
245          del loginData['password']          del loginData['password']
246    
247        loginData.setdefault('_username')        # Load
248        loginData.setdefault('_password')        if loginData.has_key('custom_auth'):
249                  authenticator = dyn_import(loginData['custom_auth']).Authenticator()
250        try:          checkFields = authenticator.getLoginFields(dataObject.getLoginFields())
251          else:
252          dataObject.connect(loginData)          checkFields = dataObject.getLoginFields()
253            authenticator = None
254    
255          haveAllInformation = 1
256          for rf, dummy1, dummy2 in checkFields:
257            if not (loginData.has_key(rf) and loginData[rf] != None):
258              haveAllInformation = 0
259              break
260    
261          if haveAllInformation:
262            if authenticator:
263              dataObject.connect(authenticator.login(loginData))
264            else:
265              dataObject.connect(loginData)
266          GDebug.printMesg(5, 'I had enough information to connect to %s without asking the user' % connection_name)          GDebug.printMesg(5, 'I had enough information to connect to %s without asking the user' % connection_name)
267          # Save the newly opened connection for future datasources          # Save the newly opened connection for future datasources
268          self._openConnections[connection_name] = dataObject.getDataConnection()          self._openConnections[connection_name] = dataObject.getDataConnection()
269    
270        except GDataObjects.LoginError:        else:
271          attempts = 4          attempts = 4
272    
273          GDebug.printMesg(5,'Getting new data connection to %s' % connection_name)          GDebug.printMesg(5,'Getting new data connection to %s' % connection_name)
# Line 268  class GConnections: Line 287  class GConnections:
287              dataObject.connect(loginData)              dataObject.connect(loginData)
288    
289              # Save the newly opened connection for future datasources              # Save the newly opened connection for future datasources
290              self._openConnections[connection_name] = dataObject.getDataConnection()              self._openConnections[connection_name] = \
291                    dataObject.getDataConnection()
292    
293              # We're done!              # We're done!
294              attempts = 0              attempts = 0
# Line 291  class GConnections: Line 311  class GConnections:
311              # Guess they changed their minds. Treat as a login error.              # Guess they changed their minds. Treat as a login error.
312              self._loginHandler.destroyLoginDialog()              self._loginHandler.destroyLoginDialog()
313              raise GDataObjects.LoginError, _("User canceled the login request.")              raise GDataObjects.LoginError, _("User canceled the login request.")
           
314    
315    
316    

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

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