~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/trace.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-07-17 09:40:51 UTC
  • mfrom: (3518.1.2 virtualvf)
  • Revision ID: pqm@pqm.ubuntu.com-20080717094051-cgyo1zagozwcd4mm
(Jelmer) Add VirtualVersionedFiles class.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
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
16
16
 
17
17
"""Implementation of Transport that traces transport operations.
18
18
 
20
20
and then delegates it.
21
21
"""
22
22
 
23
 
from bzrlib.transport import decorator
24
 
 
25
 
 
26
 
class TransportTraceDecorator(decorator.TransportDecorator):
 
23
from bzrlib.transport.decorator import TransportDecorator, DecoratorServer
 
24
 
 
25
 
 
26
class TransportTraceDecorator(TransportDecorator):
27
27
    """A tracing decorator for Transports.
28
28
 
29
29
    Calls that potentially perform IO are logged to self._activity. The
34
34
    operation please add a test to the tests of this transport, for the logging
35
35
    of the operation you want logged.
36
36
 
37
 
    See also TransportLogDecorator, that records a machine-readable log in 
38
 
    memory for eg testing.
 
37
    Another future enhancement would be to log to bzrlib.trace.mutter when
 
38
    trace+ is used from the command line (or perhaps as well/instead use
 
39
    -Dtransport), to make tracing operations of the entire program easily.
39
40
    """
40
41
 
41
42
    def __init__(self, url, _decorated=None, _from_transport=None):
42
43
        """Set the 'base' path where files will be stored.
43
 
 
 
44
        
44
45
        _decorated is a private parameter for cloning.
45
46
        """
46
 
        super(TransportTraceDecorator, self).__init__(url, _decorated)
 
47
        TransportDecorator.__init__(self, url, _decorated)
47
48
        if _from_transport is None:
48
49
            # newly created
49
50
            self._activity = []
75
76
 
76
77
    def get(self, relpath):
77
78
        """See Transport.get()."""
78
 
        self._trace(('get', relpath))
 
79
        self._activity.append(('get', relpath))
79
80
        return self._decorated.get(relpath)
80
81
 
81
82
    def get_smart_client(self):
91
92
 
92
93
    def mkdir(self, relpath, mode=None):
93
94
        """See Transport.mkdir()."""
94
 
        self._trace(('mkdir', relpath, mode))
95
95
        return self._decorated.mkdir(relpath, mode)
96
96
 
97
97
    def open_write_stream(self, relpath, mode=None):
101
101
    def put_file(self, relpath, f, mode=None):
102
102
        """See Transport.put_file()."""
103
103
        return self._decorated.put_file(relpath, f, mode)
104
 
 
 
104
    
105
105
    def put_bytes(self, relpath, bytes, mode=None):
106
106
        """See Transport.put_bytes()."""
107
 
        self._trace(('put_bytes', relpath, len(bytes), mode))
 
107
        self._activity.append(('put_bytes', relpath, len(bytes), mode))
108
108
        return self._decorated.put_bytes(relpath, bytes, mode)
109
109
 
110
 
    def put_bytes_non_atomic(self, relpath, bytes, mode=None,
111
 
        create_parent_dir=False, dir_mode=None):
112
 
        """See Transport.put_bytes_non_atomic."""
113
 
        self._trace(('put_bytes_non_atomic', relpath, len(bytes), mode,
114
 
            create_parent_dir, dir_mode))
115
 
        return self._decorated.put_bytes_non_atomic(relpath, bytes, mode=mode,
116
 
            create_parent_dir=create_parent_dir, dir_mode=dir_mode)
117
 
 
118
110
    def listable(self):
119
111
        """See Transport.listable."""
120
112
        return self._decorated.listable()
122
114
    def iter_files_recursive(self):
123
115
        """See Transport.iter_files_recursive()."""
124
116
        return self._decorated.iter_files_recursive()
125
 
 
 
117
    
126
118
    def list_dir(self, relpath):
127
119
        """See Transport.list_dir()."""
128
120
        return self._decorated.list_dir(relpath)
129
121
 
130
122
    def readv(self, relpath, offsets, adjust_for_latency=False,
131
123
        upper_limit=None):
132
 
        # we override at the readv() level rather than _readv() so that any
133
 
        # latency adjustments will be done by the underlying transport
134
 
        self._trace(('readv', relpath, offsets, adjust_for_latency,
 
124
        """See Transport.readv."""
 
125
        self._activity.append(('readv', relpath, offsets, adjust_for_latency,
135
126
            upper_limit))
136
127
        return self._decorated.readv(relpath, offsets, adjust_for_latency,
137
128
            upper_limit)
143
134
    def rename(self, rel_from, rel_to):
144
135
        self._activity.append(('rename', rel_from, rel_to))
145
136
        return self._decorated.rename(rel_from, rel_to)
146
 
 
 
137
    
147
138
    def rmdir(self, relpath):
148
139
        """See Transport.rmdir."""
149
 
        self._trace(('rmdir', relpath))
150
140
        return self._decorated.rmdir(relpath)
151
141
 
152
142
    def stat(self, relpath):
161
151
        """See Transport.lock_write."""
162
152
        return self._decorated.lock_write(relpath)
163
153
 
164
 
    def _trace(self, operation_tuple):
165
 
        """Record that a transport operation occured.
166
 
 
167
 
        :param operation: Tuple of transport call name and arguments.
168
 
        """
169
 
        self._activity.append(operation_tuple)
 
154
 
 
155
class TraceServer(DecoratorServer):
 
156
    """Server for the TransportTraceDecorator for testing with."""
 
157
 
 
158
    def get_decorator_class(self):
 
159
        return TransportTraceDecorator
170
160
 
171
161
 
172
162
def get_test_permutations():
173
163
    """Return the permutations to be used in testing."""
174
 
    from bzrlib.tests import test_server
175
 
    return [(TransportTraceDecorator, test_server.TraceServer)]
 
164
    return [(TransportTraceDecorator, TraceServer)]