~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/smart.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-09-19 03:52:02 UTC
  • mfrom: (2018.1.11 bzr+ssh:// testing)
  • Revision ID: pqm@pqm.ubuntu.com-20060919035202-8174b4dc7ff91add
(Andrew Bennetts, Robert Collins) Add bzr+ssh:// url support and turn the smart server into a anonymous readonly server by default.

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
"""
50
50
 
51
51
 
 
52
# TODO: _translate_error should be on the client, not the transport because
 
53
#     error coding is wire protocol specific.
52
54
 
53
55
# TODO: A plain integer from query_version is too simple; should give some
54
56
# capabilities too?
465
467
            # This handles UnicodeEncodeError or UnicodeDecodeError
466
468
            return SmartServerResponse((e.__class__.__name__,
467
469
                    e.encoding, val, str(e.start), str(e.end), e.reason))
 
470
        except errors.TransportNotPossible, e:
 
471
            if e.msg == "readonly transport":
 
472
                return SmartServerResponse(('ReadOnlyError', ))
 
473
            else:
 
474
                raise
468
475
 
469
476
 
470
477
class SmartTCPServer(object):
829
836
 
830
837
    def _translate_error(self, resp, orig_path=None):
831
838
        """Raise an exception from a response"""
832
 
        what = resp[0]
 
839
        if resp is None:
 
840
            what = None
 
841
        else:
 
842
            what = resp[0]
833
843
        if what == 'ok':
834
844
            return
835
845
        elif what == 'NoSuchFile':
861
871
                raise UnicodeDecodeError(encoding, val, start, end, reason)
862
872
            elif what == 'UnicodeEncodeError':
863
873
                raise UnicodeEncodeError(encoding, val, start, end, reason)
 
874
        elif what == "ReadOnlyError":
 
875
            raise errors.TransportNotPossible('readonly transport')
864
876
        else:
865
877
            raise errors.SmartProtocolError('unexpected smart server error: %r' % (resp,))
866
878
 
1015
1027
            self._socket.close()
1016
1028
 
1017
1029
try:
1018
 
    from bzrlib.transport import sftp
 
1030
    from bzrlib.transport import sftp, ssh
1019
1031
except errors.ParamikoNotPresent:
1020
1032
    # no paramiko, no SSHTransport.
1021
1033
    pass
1033
1045
                raise errors.InvalidURL(path=url, extra="invalid port %s" % self._port)
1034
1046
 
1035
1047
        def _connect_to_server(self):
1036
 
            # XXX: don't hardcode vendor
1037
 
            # XXX: cannot pass password to SSHSubprocess yet
1038
 
            if self._password is not None:
1039
 
                raise errors.InvalidURL("SSH smart transport doesn't handle passwords")
1040
 
            self._ssh_connection = sftp.SSHSubprocess(self._host, 'openssh',
1041
 
                    port=self._port, user=self._username,
1042
 
                    command=['bzr', 'serve', '--inet'])
 
1048
            executable = os.environ.get('BZR_REMOTE_PATH', 'bzr')
 
1049
            vendor = ssh._get_ssh_vendor()
 
1050
            self._ssh_connection = vendor.connect_ssh(self._username,
 
1051
                    self._password, self._host, self._port,
 
1052
                    command=[executable, 'serve', '--inet', '--directory=/',
 
1053
                             '--allow-writes'])
1043
1054
            return self._ssh_connection.get_filelike_channels()
1044
1055
 
1045
1056
        def disconnect(self):