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

  • Committer: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

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 .brz.log."""
 
17
"""Transport decorator that logs transport operations to .bzr.log."""
18
18
 
19
19
from __future__ import absolute_import
20
20
 
21
21
# see also the transportstats plugin, which gives you some summary information
22
22
# in a machine-readable dump
23
23
 
 
24
import StringIO
 
25
import cStringIO
24
26
import time
25
27
import types
26
28
 
27
 
from ..trace import mutter
28
 
from ..transport import decorator
 
29
from bzrlib.trace import mutter
 
30
from bzrlib.transport import decorator
29
31
 
30
32
 
31
33
class TransportLogDecorator(decorator.TransportDecorator):
32
 
    """Decorator for Transports that logs interesting operations to .brz.log.
 
34
    """Decorator for Transports that logs interesting operations to .bzr.log.
33
35
 
34
36
    In general we want to log things that usually take a network round trip
35
37
    and may be slow.
46
48
            def _hook(relpath, *args, **kw):
47
49
                return self._log_and_call(hookname, relpath, *args, **kw)
48
50
            return _hook
49
 
        # GZ 2017-05-21: Not all methods take relpath as first argument, for
50
 
        # instance copy_to takes list of relpaths. Also, unclear on url vs
51
 
        # filesystem path split. Needs tidying up.
52
51
        for methodname in (
53
52
            'append_bytes',
54
53
            'append_file',
83
82
        else:
84
83
            kwargs_str = ''
85
84
        mutter("%s %s %s %s"
86
 
               % (methodname, relpath,
 
85
               % (methodname, self._decorated.abspath(relpath),
87
86
                  self._shorten(self._strip_tuple_parens(args)),
88
87
                  kwargs_str))
89
88
        return self._call_and_log_result(methodname, (relpath,) + args, kwargs)
92
91
        before = time.time()
93
92
        try:
94
93
            result = getattr(self._decorated, methodname)(*args, **kwargs)
95
 
        except Exception as e:
 
94
        except Exception, e:
96
95
            mutter("  --> %s" % e)
97
96
            mutter("      %.03fs" % (time.time() - before))
98
97
            raise
110
109
            return_result = iter(result)
111
110
        else:
112
111
            return_result = result
113
 
        # Is this an io object with a getvalue() method?
114
 
        getvalue = getattr(result, 'getvalue', None)
115
 
        if getvalue is not None:
116
 
            val = repr(getvalue())
 
112
        if isinstance(result, (cStringIO.OutputType, StringIO.StringIO)):
 
113
            val = repr(result.getvalue())
117
114
            result_len = len(val)
118
115
            shown_result = "%s(%s) (%d bytes)" % (result.__class__.__name__,
119
116
                self._shorten(val), result_len)
120
117
        elif methodname == 'readv':
121
118
            num_hunks = len(result)
122
 
            total_bytes = sum((len(d) for o, d in result))
 
119
            total_bytes = sum((len(d) for o,d in result))
123
120
            shown_result = "readv response, %d hunks, %d total bytes" % (
124
121
                num_hunks, total_bytes)
125
122
            result_len = total_bytes
154
151
 
155
152
def get_test_permutations():
156
153
    """Return the permutations to be used in testing."""
157
 
    from ..tests import test_server
 
154
    from bzrlib.tests import test_server
158
155
    return [(TransportLogDecorator, test_server.LogDecoratorServer)]