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

  • Committer: Jelmer Vernooij
  • Date: 2012-08-31 11:22:09 UTC
  • mfrom: (0.53.3 trunk)
  • mto: (6556.2.1 bzr.dev)
  • mto: This revision was merged to the branch mainline in revision 6559.
  • Revision ID: jelmer@samba.org-20120831112209-7p53u3ek55mjn3ry
Merge in bzr-ping plugin.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2008 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
 
17
"""Ping plugin for bzr."""
 
18
 
 
19
from bzrlib.commands import Command, register_command
 
20
from bzrlib.lazy_import import lazy_import
 
21
 
 
22
lazy_import(globals(), """
 
23
from bzrlib import errors
 
24
from bzrlib.smart.client import _SmartClient
 
25
from bzrlib.transport import get_transport
 
26
""")
 
27
 
 
28
 
 
29
class cmd_ping(Command):
 
30
    """Pings a Bazaar smart server.
 
31
    
 
32
    This command sends a 'hello' request to the given location using the bzr
 
33
    smart protocol, and reports the response.
 
34
    """
 
35
 
 
36
    takes_args = ['location']
 
37
 
 
38
    def run(self, location):
 
39
        transport = get_transport(location)
 
40
        try:
 
41
            medium = transport.get_smart_medium()
 
42
        except errors.NoSmartMedium, e:
 
43
            raise errors.BzrCommandError(str(e))
 
44
        client = _SmartClient(medium)
 
45
        # Use call_expecting_body (even though we don't expect a body) so that
 
46
        # we can see the response headers (if any) via the handler object.
 
47
        response, handler = client.call_expecting_body('hello')
 
48
        handler.cancel_read_body()
 
49
        self.outf.write('Response: %r\n' % (response,))
 
50
        if getattr(handler, 'headers', None) is not None:
 
51
            self.outf.write('Headers: %r\n' % (handler.headers,))
 
52
 
 
53
register_command(cmd_ping)