~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/trace.py

- properties are retrieved when revisions are loaded

- test for this

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007 Canonical Ltd
2
 
#
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.
7
 
#
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.
12
 
#
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
 
 
17
 
"""Implementation of Transport that traces transport operations.
18
 
 
19
 
This does not change the transport behaviour at all, merely records every call
20
 
and then delegates it.
21
 
"""
22
 
 
23
 
from __future__ import absolute_import
24
 
 
25
 
from bzrlib.transport import decorator
26
 
 
27
 
 
28
 
class TransportTraceDecorator(decorator.TransportDecorator):
29
 
    """A tracing decorator for Transports.
30
 
 
31
 
    Calls that potentially perform IO are logged to self._activity. The
32
 
    _activity attribute is shared as the transport is cloned, but not if a new
33
 
    transport is created without cloning.
34
 
 
35
 
    Not all operations are logged at this point, if you need an unlogged
36
 
    operation please add a test to the tests of this transport, for the logging
37
 
    of the operation you want logged.
38
 
 
39
 
    See also TransportLogDecorator, that records a machine-readable log in 
40
 
    memory for eg testing.
41
 
    """
42
 
 
43
 
    def __init__(self, url, _decorated=None, _from_transport=None):
44
 
        """Set the 'base' path where files will be stored.
45
 
 
46
 
        _decorated is a private parameter for cloning.
47
 
        """
48
 
        super(TransportTraceDecorator, self).__init__(url, _decorated)
49
 
        if _from_transport is None:
50
 
            # newly created
51
 
            self._activity = []
52
 
        else:
53
 
            # cloned
54
 
            self._activity = _from_transport._activity
55
 
 
56
 
    def append_file(self, relpath, f, mode=None):
57
 
        """See Transport.append_file()."""
58
 
        return self._decorated.append_file(relpath, f, mode=mode)
59
 
 
60
 
    def append_bytes(self, relpath, bytes, mode=None):
61
 
        """See Transport.append_bytes()."""
62
 
        return self._decorated.append_bytes(relpath, bytes, mode=mode)
63
 
 
64
 
    def delete(self, relpath):
65
 
        """See Transport.delete()."""
66
 
        self._activity.append(('delete', relpath))
67
 
        return self._decorated.delete(relpath)
68
 
 
69
 
    def delete_tree(self, relpath):
70
 
        """See Transport.delete_tree()."""
71
 
        return self._decorated.delete_tree(relpath)
72
 
 
73
 
    @classmethod
74
 
    def _get_url_prefix(self):
75
 
        """Tracing transports are identified by 'trace+'"""
76
 
        return 'trace+'
77
 
 
78
 
    def get(self, relpath):
79
 
        """See Transport.get()."""
80
 
        self._trace(('get', relpath))
81
 
        return self._decorated.get(relpath)
82
 
 
83
 
    def get_smart_client(self):
84
 
        return self._decorated.get_smart_client()
85
 
 
86
 
    def has(self, relpath):
87
 
        """See Transport.has()."""
88
 
        return self._decorated.has(relpath)
89
 
 
90
 
    def is_readonly(self):
91
 
        """See Transport.is_readonly."""
92
 
        return self._decorated.is_readonly()
93
 
 
94
 
    def mkdir(self, relpath, mode=None):
95
 
        """See Transport.mkdir()."""
96
 
        self._trace(('mkdir', relpath, mode))
97
 
        return self._decorated.mkdir(relpath, mode)
98
 
 
99
 
    def open_write_stream(self, relpath, mode=None):
100
 
        """See Transport.open_write_stream."""
101
 
        return self._decorated.open_write_stream(relpath, mode=mode)
102
 
 
103
 
    def put_file(self, relpath, f, mode=None):
104
 
        """See Transport.put_file()."""
105
 
        return self._decorated.put_file(relpath, f, mode)
106
 
 
107
 
    def put_bytes(self, relpath, bytes, mode=None):
108
 
        """See Transport.put_bytes()."""
109
 
        self._trace(('put_bytes', relpath, len(bytes), mode))
110
 
        return self._decorated.put_bytes(relpath, bytes, mode)
111
 
 
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)
119
 
 
120
 
    def listable(self):
121
 
        """See Transport.listable."""
122
 
        return self._decorated.listable()
123
 
 
124
 
    def iter_files_recursive(self):
125
 
        """See Transport.iter_files_recursive()."""
126
 
        return self._decorated.iter_files_recursive()
127
 
 
128
 
    def list_dir(self, relpath):
129
 
        """See Transport.list_dir()."""
130
 
        return self._decorated.list_dir(relpath)
131
 
 
132
 
    def readv(self, relpath, offsets, adjust_for_latency=False,
133
 
        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
136
 
        self._trace(('readv', relpath, offsets, adjust_for_latency,
137
 
            upper_limit))
138
 
        return self._decorated.readv(relpath, offsets, adjust_for_latency,
139
 
            upper_limit)
140
 
 
141
 
    def recommended_page_size(self):
142
 
        """See Transport.recommended_page_size()."""
143
 
        return self._decorated.recommended_page_size()
144
 
 
145
 
    def rename(self, rel_from, rel_to):
146
 
        self._activity.append(('rename', rel_from, rel_to))
147
 
        return self._decorated.rename(rel_from, rel_to)
148
 
 
149
 
    def rmdir(self, relpath):
150
 
        """See Transport.rmdir."""
151
 
        self._trace(('rmdir', relpath))
152
 
        return self._decorated.rmdir(relpath)
153
 
 
154
 
    def stat(self, relpath):
155
 
        """See Transport.stat()."""
156
 
        return self._decorated.stat(relpath)
157
 
 
158
 
    def lock_read(self, relpath):
159
 
        """See Transport.lock_read."""
160
 
        return self._decorated.lock_read(relpath)
161
 
 
162
 
    def lock_write(self, relpath):
163
 
        """See Transport.lock_write."""
164
 
        return self._decorated.lock_write(relpath)
165
 
 
166
 
    def _trace(self, operation_tuple):
167
 
        """Record that a transport operation occured.
168
 
 
169
 
        :param operation: Tuple of transport call name and arguments.
170
 
        """
171
 
        self._activity.append(operation_tuple)
172
 
 
173
 
 
174
 
def get_test_permutations():
175
 
    """Return the permutations to be used in testing."""
176
 
    from bzrlib.tests import test_server
177
 
    return [(TransportTraceDecorator, test_server.TraceServer)]