* [Qemu-devel] [PATCH] qmp-shell: fix pretty printing of JSON responses
@ 2016-02-22 17:02 Daniel P. Berrange
2016-02-22 22:02 ` Eric Blake
0 siblings, 1 reply; 3+ messages in thread
From: Daniel P. Berrange @ 2016-02-22 17:02 UTC (permalink / raw)
To: qemu-devel; +Cc: Markus Armbruster, Luiz Capitulino
Pretty printing of JSON responses is important to be able
to understand large responses from query commands in
particular, eg
(QEMU) query-chardev
{ u'return': [ { u'filename': u'vc',
u'frontend-open': False,
u'label': u'parallel0'},
{ u'filename': u'vc',
u'frontend-open': True,
u'label': u'serial0'},
{ u'filename': u'unix:/tmp/qemp,server',
u'frontend-open': True,
u'label': u'compat_monitor0'}]}
Unfortunately this was broken during the addition of
the verbose flag in
commit 1ceca07e48ead0dd2e41576c81d40e6a91cafefd
Author: John Snow <jsnow@redhat.com>
Date: Wed Apr 29 15:14:04 2015 -0400
scripts: qmp-shell: Add verbose flag
This is because that change turned the python data
structure into a formatted JSON string before the
pretty print was given it. So we're just pretty
printing a string, which is a no-op.
This fixes pretty printing of the command responses
and as an added benefit it will also pretty print
command arguments in verbose mode
(QEMU) object-add qom-type=secret id=sec0 props={"data":"123456"}
{ 'arguments': { 'id': 'sec0',
'props': { u'data': u'123456'},
'qom-type': 'secret'},
'execute': 'object-add'}
{ u'return': { }}
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
---
scripts/qmp/qmp-shell | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell
index 7a402ed..15bbc5e 100755
--- a/scripts/qmp/qmp-shell
+++ b/scripts/qmp/qmp-shell
@@ -231,10 +231,10 @@ class QMPShell(qmp.QEMUMonitorProtocol):
return qmpcmd
def _print(self, qmp):
- jsobj = json.dumps(qmp)
if self._pp is not None:
- self._pp.pprint(jsobj)
+ self._pp.pprint(qmp)
else:
+ jsobj = json.dumps(qmp)
print str(jsobj)
def _execute_cmd(self, cmdline):
--
2.5.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] qmp-shell: fix pretty printing of JSON responses
2016-02-22 17:02 [Qemu-devel] [PATCH] qmp-shell: fix pretty printing of JSON responses Daniel P. Berrange
@ 2016-02-22 22:02 ` Eric Blake
2016-02-23 10:53 ` Daniel P. Berrange
0 siblings, 1 reply; 3+ messages in thread
From: Eric Blake @ 2016-02-22 22:02 UTC (permalink / raw)
To: Daniel P. Berrange, qemu-devel; +Cc: Markus Armbruster, Luiz Capitulino
[-- Attachment #1: Type: text/plain, Size: 2596 bytes --]
On 02/22/2016 10:02 AM, Daniel P. Berrange wrote:
> Pretty printing of JSON responses is important to be able
> to understand large responses from query commands in
> particular, eg
>
> (QEMU) query-chardev
> { u'return': [ { u'filename': u'vc',
> u'frontend-open': False,
> u'label': u'parallel0'},
> { u'filename': u'vc',
> u'frontend-open': True,
> u'label': u'serial0'},
> { u'filename': u'unix:/tmp/qemp,server',
> u'frontend-open': True,
> u'label': u'compat_monitor0'}]}
>
> Unfortunately this was broken during the addition of
> the verbose flag in
>
> commit 1ceca07e48ead0dd2e41576c81d40e6a91cafefd
> Author: John Snow <jsnow@redhat.com>
> Date: Wed Apr 29 15:14:04 2015 -0400
>
> scripts: qmp-shell: Add verbose flag
>
> This is because that change turned the python data
> structure into a formatted JSON string before the
> pretty print was given it. So we're just pretty
> printing a string, which is a no-op.
>
> This fixes pretty printing of the command responses
> and as an added benefit it will also pretty print
> command arguments in verbose mode
>
> (QEMU) object-add qom-type=secret id=sec0 props={"data":"123456"}
> { 'arguments': { 'id': 'sec0',
> 'props': { u'data': u'123456'},
> 'qom-type': 'secret'},
> 'execute': 'object-add'}
> { u'return': { }}
That's an odd mix of regular and Unicode strings. Any ideas why it is
happening? But the patch is a strict improvement, so:
Reviewed-by: Eric Blake <eblake@redhat.com>
>
> Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
> ---
> scripts/qmp/qmp-shell | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell
> index 7a402ed..15bbc5e 100755
> --- a/scripts/qmp/qmp-shell
> +++ b/scripts/qmp/qmp-shell
> @@ -231,10 +231,10 @@ class QMPShell(qmp.QEMUMonitorProtocol):
> return qmpcmd
>
> def _print(self, qmp):
> - jsobj = json.dumps(qmp)
> if self._pp is not None:
> - self._pp.pprint(jsobj)
> + self._pp.pprint(qmp)
> else:
> + jsobj = json.dumps(qmp)
> print str(jsobj)
>
> def _execute_cmd(self, cmdline):
>
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] qmp-shell: fix pretty printing of JSON responses
2016-02-22 22:02 ` Eric Blake
@ 2016-02-23 10:53 ` Daniel P. Berrange
0 siblings, 0 replies; 3+ messages in thread
From: Daniel P. Berrange @ 2016-02-23 10:53 UTC (permalink / raw)
To: Eric Blake; +Cc: Luiz Capitulino, qemu-devel, Markus Armbruster
On Mon, Feb 22, 2016 at 03:02:03PM -0700, Eric Blake wrote:
> On 02/22/2016 10:02 AM, Daniel P. Berrange wrote:
> > Pretty printing of JSON responses is important to be able
> > to understand large responses from query commands in
> > particular, eg
> >
> > (QEMU) query-chardev
> > { u'return': [ { u'filename': u'vc',
> > u'frontend-open': False,
> > u'label': u'parallel0'},
> > { u'filename': u'vc',
> > u'frontend-open': True,
> > u'label': u'serial0'},
> > { u'filename': u'unix:/tmp/qemp,server',
> > u'frontend-open': True,
> > u'label': u'compat_monitor0'}]}
> >
> > Unfortunately this was broken during the addition of
> > the verbose flag in
> >
> > commit 1ceca07e48ead0dd2e41576c81d40e6a91cafefd
> > Author: John Snow <jsnow@redhat.com>
> > Date: Wed Apr 29 15:14:04 2015 -0400
> >
> > scripts: qmp-shell: Add verbose flag
> >
> > This is because that change turned the python data
> > structure into a formatted JSON string before the
> > pretty print was given it. So we're just pretty
> > printing a string, which is a no-op.
> >
> > This fixes pretty printing of the command responses
> > and as an added benefit it will also pretty print
> > command arguments in verbose mode
> >
> > (QEMU) object-add qom-type=secret id=sec0 props={"data":"123456"}
> > { 'arguments': { 'id': 'sec0',
> > 'props': { u'data': u'123456'},
> > 'qom-type': 'secret'},
> > 'execute': 'object-add'}
> > { u'return': { }}
>
> That's an odd mix of regular and Unicode strings. Any ideas why it is
> happening? But the patch is a strict improvement, so:
It is todo with the way qmp-shell parses the command line. The qom-type
and id arguments it just parses directly, but the last props argument
it gets by using json.loads() which returns unicode strings.
I realized we can avoid this issue and improve output style by not
pretty printing a python data struture, and instead telling the json
formatter to pretty print its output. So I've sent a v2 that does that
Regards,
Daniel
--
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org -o- http://virt-manager.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-02-23 10:53 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-22 17:02 [Qemu-devel] [PATCH] qmp-shell: fix pretty printing of JSON responses Daniel P. Berrange
2016-02-22 22:02 ` Eric Blake
2016-02-23 10:53 ` Daniel P. Berrange
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).