From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47224) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WJ7mi-0005HI-9h for qemu-devel@nongnu.org; Thu, 27 Feb 2014 15:42:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WJ7mc-00067h-5y for qemu-devel@nongnu.org; Thu, 27 Feb 2014 15:42:24 -0500 Received: from mx1.redhat.com ([209.132.183.28]:10720) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WJ7mb-00067Y-So for qemu-devel@nongnu.org; Thu, 27 Feb 2014 15:42:18 -0500 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s1RKgGZO015151 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 27 Feb 2014 15:42:16 -0500 Date: Thu, 27 Feb 2014 10:35:01 -0500 From: Luiz Capitulino Message-ID: <20140227103501.36e255b3@redhat.com> In-Reply-To: <1392174313-25921-1-git-send-email-famz@redhat.com> References: <1392174313-25921-1-git-send-email-famz@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v3] QMP: Allow dot separated dict path arguments in qmp-shell List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fam Zheng Cc: Igor Mammedov , qemu-devel@nongnu.org, Stefan Hajnoczi On Wed, 12 Feb 2014 11:05:13 +0800 Fam Zheng wrote: > As another convinience to allow using commands that expect a dict as > argument, this patch adds support for foo.bar=value syntax, similar to > command line argument style: > > (QEMU) blockdev-add options.driver=file options.id=drive1 options.filename=... > > Signed-off-by: Fam Zheng Applied to the qmp branch, thanks. > > --- > v3: Fix error message wording. (Eric) > v2: Fix variable usage and improved error check and report. > > Applies on top of Stefan's patch > > [PATCH] QMP: allow JSON dict arguments in qmp-shell > > Signed-off-by: Fam Zheng > --- > scripts/qmp/qmp-shell | 20 ++++++++++++++++++-- > 1 file changed, 18 insertions(+), 2 deletions(-) > > diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell > index d374b35..e0e848b 100755 > --- a/scripts/qmp/qmp-shell > +++ b/scripts/qmp/qmp-shell > @@ -112,13 +112,29 @@ class QMPShell(qmp.QEMUMonitorProtocol): > value = json.loads(opt[1]) > else: > value = opt[1] > - qmpcmd['arguments'][opt[0]] = value > + optpath = opt[0].split('.') > + parent = qmpcmd['arguments'] > + curpath = [] > + for p in optpath[:-1]: > + curpath.append(p) > + d = parent.get(p, {}) > + if type(d) is not dict: > + raise QMPShellError('Cannot use "%s" as both leaf and non-leaf key' % '.'.join(curpath)) > + parent[p] = d > + parent = d > + if optpath[-1] in parent: > + if type(parent[optpath[-1]]) is dict: > + raise QMPShellError('Cannot use "%s" as both leaf and non-leaf key' % '.'.join(curpath)) > + else: > + raise QMPShellError('Cannot set "%s" multiple times' % opt[0]) > + parent[optpath[-1]] = value > return qmpcmd > > def _execute_cmd(self, cmdline): > try: > qmpcmd = self.__build_cmd(cmdline) > - except: > + except Exception, e: > + print 'Error while parsing command line: %s' % e > print 'command format: ', > print '[arg-name1=arg1] ... [arg-nameN=argN]' > return True