/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 breezy/transport/log.py

  • Committer: Breezy landing bot
  • Author(s): Colin Watson
  • Date: 2020-11-16 21:47:08 UTC
  • mfrom: (7521.1.1 remove-lp-workaround)
  • Revision ID: breezy.the.bot@gmail.com-20201116214708-jos209mgxi41oy15
Remove breezy.git workaround for bazaar.launchpad.net.

Merged from https://code.launchpad.net/~cjwatson/brz/remove-lp-workaround/+merge/393710

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
"""Transport decorator that logs transport operations to .bzr.log."""
18
 
 
19
 
from __future__ import absolute_import
 
17
"""Transport decorator that logs transport operations to brz.log."""
20
18
 
21
19
# see also the transportstats plugin, which gives you some summary information
22
20
# in a machine-readable dump
23
21
 
24
 
import StringIO
25
 
import cStringIO
26
22
import time
27
23
import types
28
24
 
29
 
from bzrlib.trace import mutter
30
 
from bzrlib.transport import decorator
 
25
from ..trace import mutter
 
26
from ..transport import decorator
31
27
 
32
28
 
33
29
class TransportLogDecorator(decorator.TransportDecorator):
34
 
    """Decorator for Transports that logs interesting operations to .bzr.log.
 
30
    """Decorator for Transports that logs interesting operations to brz.log.
35
31
 
36
32
    In general we want to log things that usually take a network round trip
37
33
    and may be slow.
38
34
 
39
35
    Not all operations are logged yet.
40
36
 
41
 
    See also TransportTraceDecorator, that records a machine-readable log in 
 
37
    See also TransportTraceDecorator, that records a machine-readable log in
42
38
    memory for eg testing.
43
39
    """
44
40
 
45
41
    def __init__(self, *args, **kw):
46
42
        super(TransportLogDecorator, self).__init__(*args, **kw)
 
43
 
47
44
        def _make_hook(hookname):
48
45
            def _hook(relpath, *args, **kw):
49
46
                return self._log_and_call(hookname, relpath, *args, **kw)
50
47
            return _hook
 
48
        # GZ 2017-05-21: Not all methods take relpath as first argument, for
 
49
        # instance copy_to takes list of relpaths. Also, unclear on url vs
 
50
        # filesystem path split. Needs tidying up.
51
51
        for methodname in (
52
 
            'append_bytes',
53
 
            'append_file',
54
 
            'copy_to',
55
 
            'delete',
56
 
            'get',
57
 
            'has',
58
 
            'open_write_stream',
59
 
            'mkdir',
60
 
            'move',
61
 
            'put_bytes', 'put_bytes_non_atomic', 'put_file put_file_non_atomic',
62
 
            'list_dir', 'lock_read', 'lock_write',
63
 
            'readv', 'rename', 'rmdir',
64
 
            'stat',
65
 
            'ulock',
66
 
            ):
 
52
                'append_bytes',
 
53
                'append_file',
 
54
                'copy_to',
 
55
                'delete',
 
56
                'get',
 
57
                'has',
 
58
                'open_write_stream',
 
59
                'mkdir',
 
60
                'move',
 
61
                'put_bytes', 'put_bytes_non_atomic', 'put_file put_file_non_atomic',
 
62
                'list_dir', 'lock_read', 'lock_write',
 
63
                'readv', 'rename', 'rmdir',
 
64
                'stat',
 
65
                'ulock',
 
66
                ):
67
67
            setattr(self, methodname, _make_hook(methodname))
68
68
 
69
69
    @classmethod
73
73
    def iter_files_recursive(self):
74
74
        # needs special handling because it does not have a relpath parameter
75
75
        mutter("%s %s"
76
 
            % ('iter_files_recursive', self._decorated.base))
 
76
               % ('iter_files_recursive', self._decorated.base))
77
77
        return self._call_and_log_result('iter_files_recursive', (), {})
78
78
 
79
79
    def _log_and_call(self, methodname, relpath, *args, **kwargs):
82
82
        else:
83
83
            kwargs_str = ''
84
84
        mutter("%s %s %s %s"
85
 
               % (methodname, self._decorated.abspath(relpath),
 
85
               % (methodname, relpath,
86
86
                  self._shorten(self._strip_tuple_parens(args)),
87
87
                  kwargs_str))
88
88
        return self._call_and_log_result(methodname, (relpath,) + args, kwargs)
91
91
        before = time.time()
92
92
        try:
93
93
            result = getattr(self._decorated, methodname)(*args, **kwargs)
94
 
        except Exception, e:
 
94
        except Exception as e:
95
95
            mutter("  --> %s" % e)
96
96
            mutter("      %.03fs" % (time.time() - before))
97
97
            raise
109
109
            return_result = iter(result)
110
110
        else:
111
111
            return_result = result
112
 
        if isinstance(result, (cStringIO.OutputType, StringIO.StringIO)):
113
 
            val = repr(result.getvalue())
 
112
        # Is this an io object with a getvalue() method?
 
113
        getvalue = getattr(result, 'getvalue', None)
 
114
        if getvalue is not None:
 
115
            val = repr(getvalue())
114
116
            result_len = len(val)
115
117
            shown_result = "%s(%s) (%d bytes)" % (result.__class__.__name__,
116
 
                self._shorten(val), result_len)
 
118
                                                  self._shorten(val), result_len)
117
119
        elif methodname == 'readv':
118
120
            num_hunks = len(result)
119
 
            total_bytes = sum((len(d) for o,d in result))
 
121
            total_bytes = sum((len(d) for o, d in result))
120
122
            shown_result = "readv response, %d hunks, %d total bytes" % (
121
123
                num_hunks, total_bytes)
122
124
            result_len = total_bytes
132
134
                # this is the rate of higher-level data, not the raw network
133
135
                # speed using base-10 units (see HACKING.txt).
134
136
                mutter("      %9.03fs %8dkB/s"
135
 
                       % (elapsed, result_len/elapsed/1000))
 
137
                       % (elapsed, result_len / elapsed / 1000))
136
138
            else:
137
139
                mutter("      %9.03fs" % (elapsed))
138
140
        return return_result
151
153
 
152
154
def get_test_permutations():
153
155
    """Return the permutations to be used in testing."""
154
 
    from bzrlib.tests import test_server
 
156
    from ..tests import test_server
155
157
    return [(TransportLogDecorator, test_server.LogDecoratorServer)]