~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/ftp/__init__.py

  • Committer: Martin Pool
  • Date: 2010-04-01 04:41:18 UTC
  • mto: This revision was merged to the branch mainline in revision 5128.
  • Revision ID: mbp@sourcefrog.net-20100401044118-shyctqc02ob08ngz
ignore .testrepository

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
    osutils,
41
41
    urlutils,
42
42
    )
43
 
from bzrlib.symbol_versioning import (
44
 
    DEPRECATED_PARAMETER,
45
 
    deprecated_in,
46
 
    deprecated_passed,
47
 
    warn,
48
 
    )
49
43
from bzrlib.trace import mutter, warning
50
44
from bzrlib.transport import (
51
45
    AppendBasedFileStream,
170
164
        connection, credentials = self._create_connection(credentials)
171
165
        self._set_connection(connection, credentials)
172
166
 
173
 
    def disconnect(self):
174
 
        connection = self._get_connection()
175
 
        if connection is not None:
176
 
            connection.close()
177
 
 
178
167
    def _translate_ftp_error(self, err, path, extra=None,
179
168
                              unknown_exc=FtpPathError):
180
169
        """Try to translate an ftplib exception to a bzrlib exception.
202
191
            or 'file/directory not found' in s # filezilla server
203
192
            # Microsoft FTP-Service RNFR reply if file not found
204
193
            or (s.startswith('550 ') and 'unable to rename to' in extra)
205
 
            # if containing directory doesn't exist, suggested by
206
 
            # <https://bugs.edge.launchpad.net/bzr/+bug/224373>
207
 
            or (s.startswith('550 ') and "can't find folder" in s)
208
194
            ):
209
195
            raise errors.NoSuchFile(path, extra=extra)
210
196
        elif ('file exists' in s):
246
232
            mutter("FTP has not: %s: %s", abspath, e)
247
233
            return False
248
234
 
249
 
    def get(self, relpath, decode=DEPRECATED_PARAMETER, retries=0):
 
235
    def get(self, relpath, decode=False, retries=0):
250
236
        """Get the file at the given relative path.
251
237
 
252
238
        :param relpath: The relative path to the file
256
242
        We're meant to return a file-like object which bzr will
257
243
        then read from. For now we do this via the magic of StringIO
258
244
        """
259
 
        if deprecated_passed(decode):
260
 
            warn(deprecated_in((2,3,0)) %
261
 
                 '"decode" parameter to FtpTransport.get()',
262
 
                 DeprecationWarning, stacklevel=2)
 
245
        # TODO: decode should be deprecated
263
246
        try:
264
247
            mutter("FTP get: %s", self._remote_path(relpath))
265
248
            f = self._get_FTP()
331
314
                    return len(bytes)
332
315
                else:
333
316
                    return fp.counted_bytes
334
 
            except (ftplib.error_temp, EOFError), e:
335
 
                warning("Failure during ftp PUT of %s: %s. Deleting temporary file."
336
 
                    % (tmp_abspath, e, ))
 
317
            except (ftplib.error_temp,EOFError), e:
 
318
                warning("Failure during ftp PUT. Deleting temporary file.")
337
319
                try:
338
320
                    f.delete(tmp_abspath)
339
321
                except:
346
328
                                       unknown_exc=errors.NoSuchFile)
347
329
        except ftplib.error_temp, e:
348
330
            if retries > _number_of_retries:
349
 
                raise errors.TransportError(
350
 
                    "FTP temporary error during PUT %s: %s. Aborting."
351
 
                    % (self.abspath(relpath), e), orig_error=e)
 
331
                raise errors.TransportError("FTP temporary error during PUT %s. Aborting."
 
332
                                     % self.abspath(relpath), orig_error=e)
352
333
            else:
353
334
                warning("FTP temporary error: %s. Retrying.", str(e))
354
335
                self._reconnect()
369
350
        try:
370
351
            mutter("FTP mkd: %s", abspath)
371
352
            f = self._get_FTP()
372
 
            try:
373
 
                f.mkd(abspath)
374
 
            except ftplib.error_reply, e:
375
 
                # <https://bugs.launchpad.net/bzr/+bug/224373> Microsoft FTP
376
 
                # server returns "250 Directory created." which is kind of
377
 
                # reasonable, 250 meaning "requested file action OK", but not what
378
 
                # Python's ftplib expects.
379
 
                if e[0][:3] == '250':
380
 
                    pass
381
 
                else:
382
 
                    raise
 
353
            f.mkd(abspath)
383
354
            self._setmode(relpath, mode)
384
355
        except ftplib.error_perm, e:
385
356
            self._translate_ftp_error(e, abspath,