/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/bzr/smart/ping.py

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2020-01-30 17:30:52 UTC
  • mfrom: (7464.3.2 drop-roundtripping)
  • Revision ID: breezy.the.bot@gmail.com-20200130173052-fedd479i21ci93dr
Drop more roundtripping support in Git.

Merged from https://code.launchpad.net/~jelmer/brz/drop-roundtripping/+merge/378336

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2008-2012 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
"""Ping plugin for brz."""
 
18
 
 
19
from __future__ import absolute_import
 
20
 
 
21
from ...commands import Command
 
22
from ...lazy_import import lazy_import
 
23
from ...sixish import viewitems
 
24
 
 
25
lazy_import(globals(), """
 
26
from breezy.bzr.smart.client import _SmartClient
 
27
from breezy.transport import get_transport
 
28
""")
 
29
 
 
30
from breezy import errors
 
31
 
 
32
 
 
33
class cmd_ping(Command):
 
34
    """Pings a Bazaar smart server.
 
35
 
 
36
    This command sends a 'hello' request to the given location using the brz
 
37
    smart protocol, and reports the response.
 
38
    """
 
39
 
 
40
    takes_args = ['location']
 
41
 
 
42
    def run(self, location):
 
43
        transport = get_transport(location)
 
44
        try:
 
45
            medium = transport.get_smart_medium()
 
46
        except errors.NoSmartMedium as e:
 
47
            raise errors.BzrCommandError(str(e))
 
48
        client = _SmartClient(medium)
 
49
        # Use call_expecting_body (even though we don't expect a body) so that
 
50
        # we can see the response headers (if any) via the handler object.
 
51
        response, handler = client.call_expecting_body(b'hello')
 
52
        handler.cancel_read_body()
 
53
        self.outf.write('Response: %r\n' % (response,))
 
54
        if getattr(handler, 'headers', None) is not None:
 
55
            headers = {
 
56
                k.decode('utf-8'): v.decode('utf-8')
 
57
                for (k, v) in viewitems(handler.headers)}
 
58
            self.outf.write('Headers: %r\n' % (headers,))