/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/transport/trace.py

  • Committer: Martin Pool
  • Date: 2005-06-28 03:02:31 UTC
  • Revision ID: mbp@sourcefrog.net-20050628030231-d311e4ebcd467ef4
Merge John's import-speedup branch:

                                                                                         
  777 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 22:20:32 -0500
      revision-id: john@arbash-meinel.com-20050627032031-e82a50db3863b18e
      bzr selftest was not using the correct bzr

  776 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 22:20:22 -0500
      revision-id: john@arbash-meinel.com-20050627032021-c9f21fde989ddaee
      Add was using an old mutter

  775 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 22:02:33 -0500
      revision-id: john@arbash-meinel.com-20050627030233-9165cfe98fc63298
      Cleaned up to be less different

  774 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 21:54:53 -0500
      revision-id: john@arbash-meinel.com-20050627025452-4260d0e744edef43
      Allow BZR_PLUGIN_PATH='' to negate plugin loading.

  773 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 21:49:34 -0500
      revision-id: john@arbash-meinel.com-20050627024933-b7158f67b7b9eae5
      Finished the previous cleanup (allowing load_plugins to be called twice)

  772 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 21:45:08 -0500
      revision-id: john@arbash-meinel.com-20050627024508-723b1df510d196fc
      Work on making the tests pass. versioning.py is calling run_cmd directly, but plugins have been loaded.

  771 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 21:32:29 -0500
      revision-id: john@arbash-meinel.com-20050627023228-79972744d7c53e15
      Got it down a little bit more by removing import of tree and inventory.

  770 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 21:26:05 -0500
      revision-id: john@arbash-meinel.com-20050627022604-350b9773ef622f95
      Reducing the number of import from bzrlib/__init__.py and bzrlib/branch.py

  769 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 20:32:25 -0500
      revision-id: john@arbash-meinel.com-20050627013225-32dd044f10d23948
      Updated revision.py and xml.py to include SubElement.

  768 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 20:03:56 -0500
      revision-id: john@arbash-meinel.com-20050627010356-ee66919e1c377faf
      Minor typo

  767 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 20:03:13 -0500
      revision-id: john@arbash-meinel.com-20050627010312-40d024007eb85051
      Caching the import

  766 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 19:51:47 -0500
      revision-id: john@arbash-meinel.com-20050627005147-5281c99e48ed1834
      Created wrapper functions for lazy import of ElementTree

  765 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 19:46:37 -0500
      revision-id: john@arbash-meinel.com-20050627004636-bf432902004a94c5
      Removed all of the test imports of cElementTree

  764 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 19:43:59 -0500
      revision-id: john@arbash-meinel.com-20050627004358-d137fbe9570dd71b
      Trying to make bzr startup faster.

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 bzrlib.transport import decorator
24
 
 
25
 
 
26
 
class TransportTraceDecorator(decorator.TransportDecorator):
27
 
    """A tracing decorator for Transports.
28
 
 
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.
32
 
 
33
 
    Not all operations are logged at this point, if you need an unlogged
34
 
    operation please add a test to the tests of this transport, for the logging
35
 
    of the operation you want logged.
36
 
 
37
 
    See also TransportLogDecorator, that records a machine-readable log in 
38
 
    memory for eg testing.
39
 
    """
40
 
 
41
 
    def __init__(self, url, _decorated=None, _from_transport=None):
42
 
        """Set the 'base' path where files will be stored.
43
 
 
44
 
        _decorated is a private parameter for cloning.
45
 
        """
46
 
        super(TransportTraceDecorator, self).__init__(url, _decorated)
47
 
        if _from_transport is None:
48
 
            # newly created
49
 
            self._activity = []
50
 
        else:
51
 
            # cloned
52
 
            self._activity = _from_transport._activity
53
 
 
54
 
    def append_file(self, relpath, f, mode=None):
55
 
        """See Transport.append_file()."""
56
 
        return self._decorated.append_file(relpath, f, mode=mode)
57
 
 
58
 
    def append_bytes(self, relpath, bytes, mode=None):
59
 
        """See Transport.append_bytes()."""
60
 
        return self._decorated.append_bytes(relpath, bytes, mode=mode)
61
 
 
62
 
    def delete(self, relpath):
63
 
        """See Transport.delete()."""
64
 
        self._activity.append(('delete', relpath))
65
 
        return self._decorated.delete(relpath)
66
 
 
67
 
    def delete_tree(self, relpath):
68
 
        """See Transport.delete_tree()."""
69
 
        return self._decorated.delete_tree(relpath)
70
 
 
71
 
    @classmethod
72
 
    def _get_url_prefix(self):
73
 
        """Tracing transports are identified by 'trace+'"""
74
 
        return 'trace+'
75
 
 
76
 
    def get(self, relpath):
77
 
        """See Transport.get()."""
78
 
        self._trace(('get', relpath))
79
 
        return self._decorated.get(relpath)
80
 
 
81
 
    def get_smart_client(self):
82
 
        return self._decorated.get_smart_client()
83
 
 
84
 
    def has(self, relpath):
85
 
        """See Transport.has()."""
86
 
        return self._decorated.has(relpath)
87
 
 
88
 
    def is_readonly(self):
89
 
        """See Transport.is_readonly."""
90
 
        return self._decorated.is_readonly()
91
 
 
92
 
    def mkdir(self, relpath, mode=None):
93
 
        """See Transport.mkdir()."""
94
 
        self._trace(('mkdir', relpath, mode))
95
 
        return self._decorated.mkdir(relpath, mode)
96
 
 
97
 
    def open_write_stream(self, relpath, mode=None):
98
 
        """See Transport.open_write_stream."""
99
 
        return self._decorated.open_write_stream(relpath, mode=mode)
100
 
 
101
 
    def put_file(self, relpath, f, mode=None):
102
 
        """See Transport.put_file()."""
103
 
        return self._decorated.put_file(relpath, f, mode)
104
 
 
105
 
    def put_bytes(self, relpath, bytes, mode=None):
106
 
        """See Transport.put_bytes()."""
107
 
        self._trace(('put_bytes', relpath, len(bytes), mode))
108
 
        return self._decorated.put_bytes(relpath, bytes, mode)
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
 
    def listable(self):
119
 
        """See Transport.listable."""
120
 
        return self._decorated.listable()
121
 
 
122
 
    def iter_files_recursive(self):
123
 
        """See Transport.iter_files_recursive()."""
124
 
        return self._decorated.iter_files_recursive()
125
 
 
126
 
    def list_dir(self, relpath):
127
 
        """See Transport.list_dir()."""
128
 
        return self._decorated.list_dir(relpath)
129
 
 
130
 
    def readv(self, relpath, offsets, adjust_for_latency=False,
131
 
        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,
135
 
            upper_limit))
136
 
        return self._decorated.readv(relpath, offsets, adjust_for_latency,
137
 
            upper_limit)
138
 
 
139
 
    def recommended_page_size(self):
140
 
        """See Transport.recommended_page_size()."""
141
 
        return self._decorated.recommended_page_size()
142
 
 
143
 
    def rename(self, rel_from, rel_to):
144
 
        self._activity.append(('rename', rel_from, rel_to))
145
 
        return self._decorated.rename(rel_from, rel_to)
146
 
 
147
 
    def rmdir(self, relpath):
148
 
        """See Transport.rmdir."""
149
 
        self._trace(('rmdir', relpath))
150
 
        return self._decorated.rmdir(relpath)
151
 
 
152
 
    def stat(self, relpath):
153
 
        """See Transport.stat()."""
154
 
        return self._decorated.stat(relpath)
155
 
 
156
 
    def lock_read(self, relpath):
157
 
        """See Transport.lock_read."""
158
 
        return self._decorated.lock_read(relpath)
159
 
 
160
 
    def lock_write(self, relpath):
161
 
        """See Transport.lock_write."""
162
 
        return self._decorated.lock_write(relpath)
163
 
 
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)
170
 
 
171
 
 
172
 
def get_test_permutations():
173
 
    """Return the permutations to be used in testing."""
174
 
    from bzrlib.tests import test_server
175
 
    return [(TransportTraceDecorator, test_server.TraceServer)]