All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luiz Capitulino <lcapitulino@redhat.com>
To: Fam Zheng <famz@redhat.com>
Cc: Igor Mammedov <imammedo@redhat.com>,
	qemu-devel@nongnu.org, Stefan Hajnoczi <stefanha@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v3] QMP: Allow dot separated dict path arguments in qmp-shell
Date: Thu, 27 Feb 2014 10:35:01 -0500	[thread overview]
Message-ID: <20140227103501.36e255b3@redhat.com> (raw)
In-Reply-To: <1392174313-25921-1-git-send-email-famz@redhat.com>

On Wed, 12 Feb 2014 11:05:13 +0800
Fam Zheng <famz@redhat.com> 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 <famz@redhat.com>

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 <famz@redhat.com>
> ---
>  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: <command-name> ',
>              print '[arg-name1=arg1] ... [arg-nameN=argN]'
>              return True

      parent reply	other threads:[~2014-02-27 20:42 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-12  3:05 [Qemu-devel] [PATCH v3] QMP: Allow dot separated dict path arguments in qmp-shell Fam Zheng
2014-02-12 18:14 ` Eric Blake
2014-02-13  1:44   ` Fam Zheng
2014-02-14  9:47 ` Stefan Hajnoczi
2014-02-27 15:35 ` Luiz Capitulino [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140227103501.36e255b3@redhat.com \
    --to=lcapitulino@redhat.com \
    --cc=famz@redhat.com \
    --cc=imammedo@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.