/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/sftp.py

remove all trailing whitespace from bzr source

Show diffs side-by-side

added added

removed removed

Lines of Context:
95
95
 
96
96
class SFTPLock(object):
97
97
    """This fakes a lock in a remote location.
98
 
    
 
98
 
99
99
    A present lock is indicated just by the existence of a file.  This
100
 
    doesn't work well on all transports and they are only used in 
 
100
    doesn't work well on all transports and they are only used in
101
101
    deprecated storage formats.
102
102
    """
103
 
    
 
103
 
104
104
    __slots__ = ['path', 'lock_path', 'lock_file', 'transport']
105
105
 
106
106
    def __init__(self, path, transport):
346
346
 
347
347
    def _remote_path(self, relpath):
348
348
        """Return the path to be passed along the sftp protocol for relpath.
349
 
        
 
349
 
350
350
        :param relpath: is a urlencoded string.
351
351
        """
352
352
        relative = urlutils.unescape(relpath).encode('utf-8')
498
498
            #      sticky bit. So it is probably best to stop chmodding, and
499
499
            #      just tell users that they need to set the umask correctly.
500
500
            #      The attr.st_mode = mode, in _sftp_open_exclusive
501
 
            #      will handle when the user wants the final mode to be more 
502
 
            #      restrictive. And then we avoid a round trip. Unless 
 
501
            #      will handle when the user wants the final mode to be more
 
502
            #      restrictive. And then we avoid a round trip. Unless
503
503
            #      paramiko decides to expose an async chmod()
504
504
 
505
505
            # This is designed to chmod() right before we close.
506
 
            # Because we set_pipelined() earlier, theoretically we might 
 
506
            # Because we set_pipelined() earlier, theoretically we might
507
507
            # avoid the round trip for fout.close()
508
508
            if mode is not None:
509
509
                self._get_sftp().chmod(tmp_abspath, mode)
551
551
                                                 ': unable to open')
552
552
 
553
553
                # This is designed to chmod() right before we close.
554
 
                # Because we set_pipelined() earlier, theoretically we might 
 
554
                # Because we set_pipelined() earlier, theoretically we might
555
555
                # avoid the round trip for fout.close()
556
556
                if mode is not None:
557
557
                    self._get_sftp().chmod(abspath, mode)
652
652
    def open_write_stream(self, relpath, mode=None):
653
653
        """See Transport.open_write_stream."""
654
654
        # initialise the file to zero-length
655
 
        # this is three round trips, but we don't use this 
656
 
        # api more than once per write_group at the moment so 
 
655
        # this is three round trips, but we don't use this
 
656
        # api more than once per write_group at the moment so
657
657
        # it is a tolerable overhead. Better would be to truncate
658
658
        # the file after opening. RBC 20070805
659
659
        self.put_bytes_non_atomic(relpath, "", mode)
682
682
        :param failure_exc: Paramiko has the super fun ability to raise completely
683
683
                           opaque errors that just set "e.args = ('Failure',)" with
684
684
                           no more information.
685
 
                           If this parameter is set, it defines the exception 
 
685
                           If this parameter is set, it defines the exception
686
686
                           to raise in these cases.
687
687
        """
688
688
        # paramiko seems to generate detailless errors.
729
729
 
730
730
    def _rename_and_overwrite(self, abs_from, abs_to):
731
731
        """Do a fancy rename on the remote server.
732
 
        
 
732
 
733
733
        Using the implementation provided by osutils.
734
734
        """
735
735
        try:
754
754
            self._get_sftp().remove(path)
755
755
        except (IOError, paramiko.SSHException), e:
756
756
            self._translate_io_exception(e, path, ': unable to delete')
757
 
            
 
757
 
758
758
    def external_url(self):
759
759
        """See bzrlib.transport.Transport.external_url."""
760
760
        # the external path for SFTP is the base
837
837
        """
838
838
        # TODO: jam 20060816 Paramiko >= 1.6.2 (probably earlier) supports
839
839
        #       using the 'x' flag to indicate SFTP_FLAG_EXCL.
840
 
        #       However, there is no way to set the permission mode at open 
 
840
        #       However, there is no way to set the permission mode at open
841
841
        #       time using the sftp_client.file() functionality.
842
842
        path = self._get_sftp()._adjust_cwd(abspath)
843
843
        # mutter('sftp abspath %s => %s', abspath, path)
844
844
        attr = SFTPAttributes()
845
845
        if mode is not None:
846
846
            attr.st_mode = mode
847
 
        omode = (SFTP_FLAG_WRITE | SFTP_FLAG_CREATE 
 
847
        omode = (SFTP_FLAG_WRITE | SFTP_FLAG_CREATE
848
848
                | SFTP_FLAG_TRUNC | SFTP_FLAG_EXCL)
849
849
        try:
850
850
            t, msg = self._get_sftp()._request(CMD_OPEN, path, omode, attr)
928
928
                # probably a failed test; unit test thread will log the
929
929
                # failure/error
930
930
                sys.excepthook(*sys.exc_info())
931
 
                warning('Exception from within unit test server thread: %r' % 
 
931
                warning('Exception from within unit test server thread: %r' %
932
932
                        x)
933
933
 
934
934
 
945
945
 
946
946
    Not all methods are implemented, this is deliberate as this class is not a
947
947
    replacement for the builtin sockets layer. fileno is not implemented to
948
 
    prevent the proxy being bypassed. 
 
948
    prevent the proxy being bypassed.
949
949
    """
950
950
 
951
951
    simulated_time = 0
953
953
        "close", "getpeername", "getsockname", "getsockopt", "gettimeout",
954
954
        "setblocking", "setsockopt", "settimeout", "shutdown"])
955
955
 
956
 
    def __init__(self, sock, latency, bandwidth=1.0, 
 
956
    def __init__(self, sock, latency, bandwidth=1.0,
957
957
                 really_sleep=True):
958
 
        """ 
 
958
        """
959
959
        :param bandwith: simulated bandwith (MegaBit)
960
960
        :param really_sleep: If set to false, the SocketDelay will just
961
961
        increase a counter, instead of calling time.sleep. This is useful for
964
964
        self.sock = sock
965
965
        self.latency = latency
966
966
        self.really_sleep = really_sleep
967
 
        self.time_per_byte = 1 / (bandwidth / 8.0 * 1024 * 1024) 
 
967
        self.time_per_byte = 1 / (bandwidth / 8.0 * 1024 * 1024)
968
968
        self.new_roundtrip = False
969
969
 
970
970
    def sleep(self, s):
1032
1032
 
1033
1033
    def _run_server_entry(self, sock):
1034
1034
        """Entry point for all implementations of _run_server.
1035
 
        
 
1035
 
1036
1036
        If self.add_latency is > 0.000001 then sock is given a latency adding
1037
1037
        decorator.
1038
1038
        """
1055
1055
        event = threading.Event()
1056
1056
        ssh_server.start_server(event, server)
1057
1057
        event.wait(5.0)
1058
 
    
 
1058
 
1059
1059
    def setUp(self, backing_server=None):
1060
1060
        # XXX: TODO: make sftpserver back onto backing_server rather than local
1061
1061
        # disk.