/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/transport/ssh.py

  • Committer: Martin Pool
  • Date: 2010-10-07 07:51:54 UTC
  • mfrom: (5463 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5476.
  • Revision ID: mbp@sourcefrog.net-20101007075154-a9ork2j441v6n3uv
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
126
126
        elif 'SSH Secure Shell' in version:
127
127
            trace.mutter('ssh implementation is SSH Corp.')
128
128
            vendor = SSHCorpSubprocessVendor()
 
129
        elif 'lsh' in version:
 
130
            trace.mutter('ssh implementation is GNU lsh.')
 
131
            vendor = LSHSubprocessVendor()
129
132
        # As plink user prompts are not handled currently, don't auto-detect
130
133
        # it by inspection below, but keep this vendor detection for if a path
131
134
        # is given in BZR_SSH. See https://bugs.launchpad.net/bugs/414743
132
135
        elif 'plink' in version and progname == 'plink':
133
136
            # Checking if "plink" was the executed argument as Windows
134
 
            # sometimes reports 'ssh -V' incorrectly with 'plink' in it's
 
137
            # sometimes reports 'ssh -V' incorrectly with 'plink' in its
135
138
            # version.  See https://bugs.launchpad.net/bzr/+bug/107155
136
139
            trace.mutter("ssh implementation is Putty's plink.")
137
140
            vendor = PLinkSubprocessVendor()
336
339
            self._raise_connection_error(host, port=port, orig_error=e,
337
340
                                         msg='Unable to invoke remote bzr')
338
341
 
 
342
_ssh_connection_errors = (EOFError, OSError, IOError, socket.error)
339
343
if paramiko is not None:
340
344
    vendor = ParamikoVendor()
341
345
    register_ssh_vendor('paramiko', vendor)
342
346
    register_ssh_vendor('none', vendor)
343
347
    register_default_ssh_vendor(vendor)
344
 
    _sftp_connection_errors = (EOFError, paramiko.SSHException)
 
348
    _ssh_connection_errors += (paramiko.SSHException,)
345
349
    del vendor
346
 
else:
347
 
    _sftp_connection_errors = (EOFError,)
348
350
 
349
351
 
350
352
class SubprocessVendor(SSHVendor):
375
377
                                                  subsystem='sftp')
376
378
            sock = self._connect(argv)
377
379
            return SFTPClient(SocketAsChannelAdapter(sock))
378
 
        except _sftp_connection_errors, e:
379
 
            self._raise_connection_error(host, port=port, orig_error=e)
380
 
        except (OSError, IOError, socket.error), e:
381
 
            # If the machine is fast enough, ssh can actually exit
382
 
            # before we try and send it the sftp request, which
383
 
            # raises a Broken Pipe
384
 
            if e.errno not in (errno.EPIPE,):
385
 
                raise
 
380
        except _ssh_connection_errors, e:
386
381
            self._raise_connection_error(host, port=port, orig_error=e)
387
382
 
388
383
    def connect_ssh(self, username, password, host, port, command):
390
385
            argv = self._get_vendor_specific_argv(username, host, port,
391
386
                                                  command=command)
392
387
            return self._connect(argv)
393
 
        except (EOFError), e:
394
 
            self._raise_connection_error(host, port=port, orig_error=e)
395
 
        except (OSError, IOError, socket.error), e:
396
 
            # If the machine is fast enough, ssh can actually exit
397
 
            # before we try and send it the sftp request, which
398
 
            # raises a Broken Pipe
399
 
            if e.errno not in (errno.EPIPE,):
400
 
                raise
 
388
        except _ssh_connection_errors, e:
401
389
            self._raise_connection_error(host, port=port, orig_error=e)
402
390
 
403
391
    def _get_vendor_specific_argv(self, username, host, port, subsystem=None,
454
442
register_ssh_vendor('sshcorp', SSHCorpSubprocessVendor())
455
443
 
456
444
 
 
445
class LSHSubprocessVendor(SubprocessVendor):
 
446
    """SSH vendor that uses the 'lsh' executable from GNU"""
 
447
 
 
448
    executable_path = 'lsh'
 
449
 
 
450
    def _get_vendor_specific_argv(self, username, host, port, subsystem=None,
 
451
                                  command=None):
 
452
        args = [self.executable_path]
 
453
        if port is not None:
 
454
            args.extend(['-p', str(port)])
 
455
        if username is not None:
 
456
            args.extend(['-l', username])
 
457
        if subsystem is not None:
 
458
            args.extend(['--subsystem', subsystem, host])
 
459
        else:
 
460
            args.extend([host] + command)
 
461
        return args
 
462
 
 
463
register_ssh_vendor('lsh', LSHSubprocessVendor())
 
464
 
 
465
 
457
466
class PLinkSubprocessVendor(SubprocessVendor):
458
467
    """SSH vendor that uses the 'plink' executable from Putty."""
459
468