~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/sftp.py

  • Committer: Martin Pool
  • Date: 2008-12-14 18:37:16 UTC
  • mto: (3882.7.11 progress)
  • mto: This revision was merged to the branch mainline in revision 3940.
  • Revision ID: mbp@sourcefrog.net-20081214183716-rdtk0w8yvxubdd3k
Start reporting activity from sftp read access

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Copyright (C) 2005 Robey Pointer <robey@lag.net>
2
 
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
 
2
# Copyright (C) 2005, 2006, 2007, 2008 Canonical Ltd
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify
5
5
# it under the terms of the GNU General Public License as published by
140
140
    # See _get_requests for an explanation.
141
141
    _max_request_size = 32768
142
142
 
143
 
    def __init__(self, original_offsets, relpath):
 
143
    def __init__(self, original_offsets, relpath, _report_activity):
144
144
        """Create a new readv helper.
145
145
 
146
146
        :param original_offsets: The original requests given by the caller of
147
147
            readv()
148
148
        :param relpath: The name of the file (if known)
 
149
        :param _report_activity: A Transport._report_activity bound method,
 
150
            to be called as data arrives.
149
151
        """
150
152
        self.original_offsets = list(original_offsets)
151
153
        self.relpath = relpath
 
154
        self._report_activity = _report_activity
152
155
 
153
156
    def _get_requests(self):
154
157
        """Break up the offsets into individual requests over sftp.
266
269
                    # Move the start-of-buffer pointer
267
270
                    input_start += cur_size
268
271
                    # Yield the requested data
 
272
                    self._report_activity(len(cur_data), 'read')
269
273
                    yield cur_offset, cur_data
270
274
                    cur_offset, cur_size = offset_iter.next()
271
275
                # at this point, we've consumed as much of buffered as we can,
312
316
                    raise AssertionError('We must have miscalulated.'
313
317
                        ' We expected %d bytes, but only found %d'
314
318
                        % (cur_size, len(data)))
 
319
                self._report_activity(len(data), 'read')
315
320
                yield cur_offset, data
316
321
                cur_offset, cur_size = offset_iter.next()
317
322
 
405
410
            return False
406
411
 
407
412
    def get(self, relpath):
408
 
        """
409
 
        Get the file at the given relative path.
 
413
        """Get the file at the given relative path.
410
414
 
411
415
        :param relpath: The relative path to the file
412
416
        """
415
419
            f = self._get_sftp().file(path, mode='rb')
416
420
            if self._do_prefetch and (getattr(f, 'prefetch', None) is not None):
417
421
                f.prefetch()
 
422
            import pdb;pdb.set_trace()
418
423
            return f
419
424
        except (IOError, paramiko.SSHException), e:
420
425
            self._translate_io_exception(e, path, ': error retrieving',
454
459
        does not support ranges > 64K, so it caps the request size, and
455
460
        just reads until it gets all the stuff it wants
456
461
        """
457
 
        helper = _SFTPReadvHelper(offsets, relpath)
 
462
        helper = _SFTPReadvHelper(offsets, relpath, self._report_activity)
458
463
        return helper.request_and_yield_offsets(fp)
459
464
 
460
465
    def put_file(self, relpath, f, mode=None):