All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v3] QMP: Allow dot separated dict path arguments in qmp-shell
@ 2014-02-12  3:05 Fam Zheng
  2014-02-12 18:14 ` Eric Blake
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Fam Zheng @ 2014-02-12  3:05 UTC (permalink / raw)
  To: qemu-devel; +Cc: Igor Mammedov, Stefan Hajnoczi, Luiz Capitulino

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>

---
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
-- 
1.8.5.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH v3] QMP: Allow dot separated dict path arguments in qmp-shell
  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
  2 siblings, 1 reply; 5+ messages in thread
From: Eric Blake @ 2014-02-12 18:14 UTC (permalink / raw)
  To: Fam Zheng, qemu-devel; +Cc: Igor Mammedov, Stefan Hajnoczi, Luiz Capitulino

[-- Attachment #1: Type: text/plain, Size: 670 bytes --]

On 02/11/2014 08:05 PM, Fam Zheng wrote:
> As another convinience to allow using commands that expect a dict as

You missed this, even though I pointed it out in v2:

s/convinience/convenience/

> 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>
> 
> ---

My python is weak, so take this with a grain of salt:
Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
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] 5+ messages in thread

* Re: [Qemu-devel] [PATCH v3] QMP: Allow dot separated dict path arguments in qmp-shell
  2014-02-12 18:14 ` Eric Blake
@ 2014-02-13  1:44   ` Fam Zheng
  0 siblings, 0 replies; 5+ messages in thread
From: Fam Zheng @ 2014-02-13  1:44 UTC (permalink / raw)
  To: Eric Blake, Luiz Capitulino; +Cc: Igor Mammedov, qemu-devel, Stefan Hajnoczi

On Wed, 02/12 11:14, Eric Blake wrote:
> On 02/11/2014 08:05 PM, Fam Zheng wrote:
> > As another convinience to allow using commands that expect a dict as
> 
> You missed this, even though I pointed it out in v2:
> 
> s/convinience/convenience/

Oops, I'm sorry for that. Luiz, would you fix this when applying?

Thanks,
Fam

> 
> > 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>
> > 
> > ---
> 
> My python is weak, so take this with a grain of salt:
> Reviewed-by: Eric Blake <eblake@redhat.com>
> 
> -- 
> Eric Blake   eblake redhat com    +1-919-301-3266
> Libvirt virtualization library http://libvirt.org
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH v3] QMP: Allow dot separated dict path arguments in qmp-shell
  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-14  9:47 ` Stefan Hajnoczi
  2014-02-27 15:35 ` Luiz Capitulino
  2 siblings, 0 replies; 5+ messages in thread
From: Stefan Hajnoczi @ 2014-02-14  9:47 UTC (permalink / raw)
  To: Fam Zheng; +Cc: Igor Mammedov, qemu-devel, Luiz Capitulino

On Wed, Feb 12, 2014 at 11:05:13AM +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 <famz@redhat.com>
> 
> ---
> 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(-)

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH v3] QMP: Allow dot separated dict path arguments in qmp-shell
  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-14  9:47 ` Stefan Hajnoczi
@ 2014-02-27 15:35 ` Luiz Capitulino
  2 siblings, 0 replies; 5+ messages in thread
From: Luiz Capitulino @ 2014-02-27 15:35 UTC (permalink / raw)
  To: Fam Zheng; +Cc: Igor Mammedov, qemu-devel, Stefan Hajnoczi

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-02-27 20:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 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.