From patchwork Mon Feb 22 17:02:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= X-Patchwork-Id: 8380351 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id D0EF4C0553 for ; Mon, 22 Feb 2016 17:04:04 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E6562204AE for ; Mon, 22 Feb 2016 17:04:00 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2B7EC203A9 for ; Mon, 22 Feb 2016 17:04:00 +0000 (UTC) Received: from localhost ([::1]:50556 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aXttv-0004kJ-If for patchwork-qemu-devel@patchwork.kernel.org; Mon, 22 Feb 2016 12:03:59 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42607) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aXtsz-0003Wn-CH for qemu-devel@nongnu.org; Mon, 22 Feb 2016 12:03:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aXtsv-0005Yf-By for qemu-devel@nongnu.org; Mon, 22 Feb 2016 12:03:01 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56246) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aXtsv-0005YT-4u for qemu-devel@nongnu.org; Mon, 22 Feb 2016 12:02:57 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 971FDC00F1C7 for ; Mon, 22 Feb 2016 17:02:56 +0000 (UTC) Received: from t530wlan.home.berrange.com.com (vpn1-6-4.ams2.redhat.com [10.36.6.4]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u1MH2sx3001784; Mon, 22 Feb 2016 12:02:55 -0500 From: "Daniel P. Berrange" To: qemu-devel@nongnu.org Date: Mon, 22 Feb 2016 17:02:47 +0000 Message-Id: <1456160567-18072-1-git-send-email-berrange@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Markus Armbruster , Luiz Capitulino Subject: [Qemu-devel] [PATCH] qmp-shell: fix pretty printing of JSON responses X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 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 Reviewed-by: Eric Blake --- 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):