~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/smart.py

  • Committer: John Arbash Meinel
  • Date: 2006-10-16 01:25:46 UTC
  • mfrom: (2071 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2080.
  • Revision ID: john@arbash-meinel.com-20061016012546-d01a0740671b4d73
[merge] bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
552
552
    """
553
553
 
554
554
    def __init__(self):
555
 
        self._homedir = os.getcwd()
 
555
        self._homedir = urlutils.local_path_to_url(os.getcwd())[7:]
556
556
        # The server is set up by default like for ssh access: the client
557
557
        # passes filesystem-absolute paths; therefore the server must look
558
558
        # them up relative to the root directory.  it might be better to act
559
559
        # a public server and have the server rewrite paths into the test
560
560
        # directory.
561
 
        SmartTCPServer.__init__(self, transport.get_transport("file:///"))
 
561
        SmartTCPServer.__init__(self,
 
562
            transport.get_transport(urlutils.local_path_to_url('/')))
562
563
        
563
564
    def setUp(self):
564
565
        """Set up server for testing"""
570
571
    def get_url(self):
571
572
        """Return the url of the server"""
572
573
        host, port = self._server_socket.getsockname()
573
 
        # XXX: I think this is likely to break on windows -- self._homedir will
574
 
        # have backslashes (and maybe a drive letter?).
575
 
        #  -- Andrew Bennetts, 2006-08-29
576
574
        return "bzr://%s:%d%s" % (host, port, urlutils.escape(self._homedir))
577
575
 
578
576
    def get_bogus_url(self):
1029
1027
        if self._socket is not None:
1030
1028
            self._socket.close()
1031
1029
 
1032
 
try:
1033
 
    from bzrlib.transport import sftp, ssh
1034
 
except errors.ParamikoNotPresent:
1035
 
    # no paramiko, no SSHTransport.
1036
 
    pass
1037
 
else:
1038
 
    class SmartSSHTransport(SmartTransport):
1039
 
        """Connection to smart server over SSH."""
1040
 
 
1041
 
        def __init__(self, url, clone_from=None):
1042
 
            # TODO: all this probably belongs in the parent class.
1043
 
            super(SmartSSHTransport, self).__init__(url, clone_from)
1044
 
            try:
1045
 
                if self._port is not None:
1046
 
                    self._port = int(self._port)
1047
 
            except (ValueError, TypeError), e:
1048
 
                raise errors.InvalidURL(path=url, extra="invalid port %s" % self._port)
1049
 
 
1050
 
        def _connect_to_server(self):
1051
 
            executable = os.environ.get('BZR_REMOTE_PATH', 'bzr')
1052
 
            vendor = ssh._get_ssh_vendor()
1053
 
            self._ssh_connection = vendor.connect_ssh(self._username,
1054
 
                    self._password, self._host, self._port,
1055
 
                    command=[executable, 'serve', '--inet', '--directory=/',
1056
 
                             '--allow-writes'])
1057
 
            return self._ssh_connection.get_filelike_channels()
1058
 
 
1059
 
        def disconnect(self):
1060
 
            super(SmartSSHTransport, self).disconnect()
1061
 
            self._ssh_connection.close()
 
1030
 
 
1031
class SmartSSHTransport(SmartTransport):
 
1032
    """Connection to smart server over SSH."""
 
1033
 
 
1034
    def __init__(self, url, clone_from=None):
 
1035
        # TODO: all this probably belongs in the parent class.
 
1036
        super(SmartSSHTransport, self).__init__(url, clone_from)
 
1037
        try:
 
1038
            if self._port is not None:
 
1039
                self._port = int(self._port)
 
1040
        except (ValueError, TypeError), e:
 
1041
            raise errors.InvalidURL(path=url, extra="invalid port %s" % self._port)
 
1042
 
 
1043
    def _connect_to_server(self):
 
1044
        from bzrlib.transport import ssh
 
1045
        executable = os.environ.get('BZR_REMOTE_PATH', 'bzr')
 
1046
        vendor = ssh._get_ssh_vendor()
 
1047
        self._ssh_connection = vendor.connect_ssh(self._username,
 
1048
                self._password, self._host, self._port,
 
1049
                command=[executable, 'serve', '--inet', '--directory=/',
 
1050
                         '--allow-writes'])
 
1051
        return self._ssh_connection.get_filelike_channels()
 
1052
 
 
1053
    def disconnect(self):
 
1054
        super(SmartSSHTransport, self).disconnect()
 
1055
        self._ssh_connection.close()
1062
1056
 
1063
1057
 
1064
1058
def get_test_permutations():