1
# Copyright (C) 2007 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""Implementation of Transport that traces transport operations.
19
This does not change the transport behaviour at allmerely records every call
20
and then delegates it.
23
from bzrlib.transport.decorator import TransportDecorator, DecoratorServer
26
class TransportTraceDecorator(TransportDecorator):
27
"""A tracing decorator for Transports.
29
Calls that potentially perform IO are logged to self._activity. The
30
_activity attribute is shared as the transport is cloned, but not if a new
31
transport is created without cloning.
34
def __init__(self, url, _decorated=None, _from_transport=None):
35
"""Set the 'base' path where files will be stored.
37
_decorated is a private parameter for cloning.
39
TransportDecorator.__init__(self, url, _decorated)
40
if _from_transport is None:
45
self._activity = _from_transport._activity
47
def append_file(self, relpath, f, mode=None):
48
"""See Transport.append_file()."""
49
return self._decorated.append_file(relpath, f, mode=mode)
51
def append_bytes(self, relpath, bytes, mode=None):
52
"""See Transport.append_bytes()."""
53
return self._decorated.append_bytes(relpath, bytes, mode=mode)
55
def delete(self, relpath):
56
"""See Transport.delete()."""
57
return self._decorated.delete(relpath)
59
def delete_tree(self, relpath):
60
"""See Transport.delete_tree()."""
61
return self._decorated.delete_tree(relpath)
64
def _get_url_prefix(self):
65
"""Tracing transports are identified by 'trace+'"""
68
def get(self, relpath):
69
"""See Transport.get()."""
70
self._activity.append(('get', relpath))
71
return self._decorated.get(relpath)
73
def get_smart_client(self):
74
return self._decorated.get_smart_client()
76
def has(self, relpath):
77
"""See Transport.has()."""
78
return self._decorated.has(relpath)
80
def is_readonly(self):
81
"""See Transport.is_readonly."""
82
return self._decorated.is_readonly()
84
def mkdir(self, relpath, mode=None):
85
"""See Transport.mkdir()."""
86
return self._decorated.mkdir(relpath, mode)
88
def open_write_stream(self, relpath, mode=None):
89
"""See Transport.open_write_stream."""
90
return self._decorated.open_write_stream(relpath, mode=mode)
92
def put_file(self, relpath, f, mode=None):
93
"""See Transport.put_file()."""
94
return self._decorated.put_file(relpath, f, mode)
96
def put_bytes(self, relpath, bytes, mode=None):
97
"""See Transport.put_bytes()."""
98
self._activity.append(('put_bytes', relpath, len(bytes), mode))
99
return self._decorated.put_bytes(relpath, bytes, mode)
102
"""See Transport.listable."""
103
return self._decorated.listable()
105
def iter_files_recursive(self):
106
"""See Transport.iter_files_recursive()."""
107
return self._decorated.iter_files_recursive()
109
def list_dir(self, relpath):
110
"""See Transport.list_dir()."""
111
return self._decorated.list_dir(relpath)
113
def readv(self, relpath, offsets, adjust_for_latency=False,
115
"""See Transport.readv."""
116
self._activity.append(('readv', relpath, offsets, adjust_for_latency,
118
return self._decorated.readv(relpath, offsets, adjust_for_latency,
121
def recommended_page_size(self):
122
"""See Transport.recommended_page_size()."""
123
return self._decorated.recommended_page_size()
125
def rename(self, rel_from, rel_to):
126
return self._decorated.rename(rel_from, rel_to)
128
def rmdir(self, relpath):
129
"""See Transport.rmdir."""
130
return self._decorated.rmdir(relpath)
132
def stat(self, relpath):
133
"""See Transport.stat()."""
134
return self._decorated.stat(relpath)
136
def lock_read(self, relpath):
137
"""See Transport.lock_read."""
138
return self._decorated.lock_read(relpath)
140
def lock_write(self, relpath):
141
"""See Transport.lock_write."""
142
return self._decorated.lock_write(relpath)
145
class TraceServer(DecoratorServer):
146
"""Server for the TransportTraceDecorator for testing with."""
148
def get_decorator_class(self):
149
return TransportTraceDecorator
152
def get_test_permutations():
153
"""Return the permutations to be used in testing.
155
The Decorator class is not directly usable, and testing it would not have
156
any benefit - its the concrete classes which need to be tested.
158
return [(TransportTraceDecorator, TraceServer)]