13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
17
"""Implementation of Transport that traces transport operations.
20
20
and then delegates it.
23
from __future__ import absolute_import
25
from bzrlib.transport import decorator
28
class TransportTraceDecorator(decorator.TransportDecorator):
23
from bzrlib.transport.decorator import TransportDecorator, DecoratorServer
26
class TransportTraceDecorator(TransportDecorator):
29
27
"""A tracing decorator for Transports.
31
29
Calls that potentially perform IO are logged to self._activity. The
35
33
Not all operations are logged at this point, if you need an unlogged
36
34
operation please add a test to the tests of this transport, for the logging
37
35
of the operation you want logged.
39
See also TransportLogDecorator, that records a machine-readable log in
40
memory for eg testing.
43
38
def __init__(self, url, _decorated=None, _from_transport=None):
44
39
"""Set the 'base' path where files will be stored.
46
41
_decorated is a private parameter for cloning.
48
super(TransportTraceDecorator, self).__init__(url, _decorated)
43
TransportDecorator.__init__(self, url, _decorated)
49
44
if _from_transport is None:
51
46
self._activity = []
103
98
def put_file(self, relpath, f, mode=None):
104
99
"""See Transport.put_file()."""
105
100
return self._decorated.put_file(relpath, f, mode)
107
102
def put_bytes(self, relpath, bytes, mode=None):
108
103
"""See Transport.put_bytes()."""
109
104
self._trace(('put_bytes', relpath, len(bytes), mode))
110
105
return self._decorated.put_bytes(relpath, bytes, mode)
112
def put_bytes_non_atomic(self, relpath, bytes, mode=None,
113
create_parent_dir=False, dir_mode=None):
114
"""See Transport.put_bytes_non_atomic."""
115
self._trace(('put_bytes_non_atomic', relpath, len(bytes), mode,
116
create_parent_dir, dir_mode))
117
return self._decorated.put_bytes_non_atomic(relpath, bytes, mode=mode,
118
create_parent_dir=create_parent_dir, dir_mode=dir_mode)
120
107
def listable(self):
121
108
"""See Transport.listable."""
122
109
return self._decorated.listable()
124
111
def iter_files_recursive(self):
125
112
"""See Transport.iter_files_recursive()."""
126
113
return self._decorated.iter_files_recursive()
128
115
def list_dir(self, relpath):
129
116
"""See Transport.list_dir()."""
130
117
return self._decorated.list_dir(relpath)
132
119
def readv(self, relpath, offsets, adjust_for_latency=False,
133
120
upper_limit=None):
134
# we override at the readv() level rather than _readv() so that any
135
# latency adjustments will be done by the underlying transport
121
"""See Transport.readv."""
136
122
self._trace(('readv', relpath, offsets, adjust_for_latency,
138
124
return self._decorated.readv(relpath, offsets, adjust_for_latency,
145
131
def rename(self, rel_from, rel_to):
146
132
self._activity.append(('rename', rel_from, rel_to))
147
133
return self._decorated.rename(rel_from, rel_to)
149
135
def rmdir(self, relpath):
150
136
"""See Transport.rmdir."""
151
self._trace(('rmdir', relpath))
152
137
return self._decorated.rmdir(relpath)
154
139
def stat(self, relpath):
171
156
self._activity.append(operation_tuple)
159
class TraceServer(DecoratorServer):
160
"""Server for the TransportTraceDecorator for testing with."""
162
def get_decorator_class(self):
163
return TransportTraceDecorator
174
166
def get_test_permutations():
175
167
"""Return the permutations to be used in testing."""
176
from bzrlib.tests import test_server
177
return [(TransportTraceDecorator, test_server.TraceServer)]
168
return [(TransportTraceDecorator, TraceServer)]