[PATCH 4/8] scripts: qemu-replies-tool: List also data from 'qom-list-properties'

Peter Krempa via Devel posted 8 patches 1 week, 2 days ago
[PATCH 4/8] scripts: qemu-replies-tool: List also data from 'qom-list-properties'
Posted by Peter Krempa via Devel 1 week, 2 days ago
From: Peter Krempa <pkrempa@redhat.com>

In addition to 'device-list-properties' libvirt probes also some
properties of qom types. Since the format is identical make the dumping
function for 'device-list-properties' universal and make it accept also
'qom-list-types'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 scripts/qemu-replies-tool.py | 50 +++++++++++++++++++++---------------
 1 file changed, 30 insertions(+), 20 deletions(-)

diff --git a/scripts/qemu-replies-tool.py b/scripts/qemu-replies-tool.py
index 211c448482..77d96f625d 100755
--- a/scripts/qemu-replies-tool.py
+++ b/scripts/qemu-replies-tool.py
@@ -409,30 +409,40 @@ def dump_qom_list_types(conv):
         print('(qom) ' + t)


-def dump_device_list_properties(conv):
-    devices = []
+def dump_device_and_object_properties(conv):
+    ent = []

     for c in conv:
+        prefix = None
+
         if c['cmd']['execute'] == 'device-list-properties':
-            if 'return' in c['rep']:
-                for arg in c['rep']['return']:
-                    for k in arg:
-                        if k not in ['name', 'type', 'description', 'default-value']:
-                            raise Exception("Unhandled 'device-list-properties' typename '%s' field '%s'" % (c['cmd']['arguments']['typename'], k))
-
-                    if 'default-value' in arg:
-                        defval = ' (%s)' % str(arg['default-value'])
-                    else:
-                        defval = ''
+            prefix = '(dev-prop)'
+
+        if c['cmd']['execute'] == 'qom-list-properties':
+            prefix = '(qom-prop)'
+
+        if prefix is None or 'return' not in c['rep']:
+            continue
+
+        for arg in c['rep']['return']:
+            for k in arg:
+                if k not in ['name', 'type', 'description', 'default-value']:
+                    raise Exception("Unhandled 'device-list-properties'/'qom-list-properties' typename '%s' field '%s'" % (c['cmd']['arguments']['typename'], k))
+
+                if 'default-value' in arg:
+                    defval = ' (%s)' % str(arg['default-value'])
+                else:
+                    defval = ''

-                    devices.append('%s %s %s%s' % (c['cmd']['arguments']['typename'],
-                                                   arg['name'],
-                                                   arg['type'],
-                                                   defval))
-    devices.sort()
+                    ent.append('%s %s %s %s%s' % (prefix,
+                                                  c['cmd']['arguments']['typename'],
+                                                  arg['name'],
+                                                  arg['type'],
+                                                  defval))
+    ent.sort()

-    for d in devices:
-        print('(dev) ' + d)
+    for e in ent:
+        print(e)


 # Sort helper for version string e.g. '11.0', '1.2' etc. Tolerates empty version.
@@ -507,7 +517,7 @@ def process_one(filename, args):

         if args.dump_all:
             dump_qom_list_types(conv)
-            dump_device_list_properties(conv)
+            dump_device_and_object_properties(conv)
             dump_machine_types(conv)
             dumped = True

-- 
2.51.0