[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH] Add support for pretty-printing response in qmp
From: |
Peter Maydell |
Subject: |
Re: [Qemu-devel] [PATCH] Add support for pretty-printing response in qmp-shell |
Date: |
Wed, 15 Aug 2012 12:20:26 +0100 |
On 15 August 2012 11:33, Daniel P. Berrange <address@hidden> wrote:
> class QMPShell(qmp.QEMUMonitorProtocol):
> - def __init__(self, address):
> + def __init__(self, address, pp=None):
> qmp.QEMUMonitorProtocol.__init__(self, self.__get_address(address))
> self._greeting = None
> self._completer = None
> + self._pp = pp
>
> def __get_address(self, arg):
> """
> @@ -114,7 +116,11 @@ class QMPShell(qmp.QEMUMonitorProtocol):
> if resp is None:
> print 'Disconnected'
> return False
> - print resp
> +
> + if self._pp is not None:
> + self._pp.pprint(resp)
> + else:
> + print resp
If not pretty printing, you could initialise self._pp to a dummy object
with a pprint method that just does "print", which would let you avoid
the conditional here and just always do "self._pp.pprint(resp)".
Dunno whether that's worth the effort -- probably depends whether
there are likely to be other places in the code in future that want
to pretty-print an object.
-- PMM