Skip to contentSkip to conversation

qmp-shell: Sort by key when pretty-printing

PATCH Applied David Edmondson 5 participants 6 messages Oct 13, 2020 – Dec 1, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qmp-shell: Sort by key when pretty-printing

If the user selects pretty-printing (-p) the contents of any dictionaries in the output are sorted by key.

---
 scripts/qmp/qmp-shell | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/qmp/qmp-shell +1 -1
index c5eef06f3f..b4d06096ab 100755
@@ -260,7 +260,7 @@ class QMPShell(qmp.QEMUMonitorProtocol):
         indent = None
         if self._pretty:
             indent = 4
-        jsobj = json.dumps(qmp, indent=indent)
+        jsobj = json.dumps(qmp, indent=indent, sort_keys=self._pretty)
         print(str(jsobj))
 
     def _execute_cmd(self, cmdline):
Signature · 1 line
2.28.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 14 lines · David Edmondson

If the user selects pretty-printing (-p) the contents of any dictionaries in the output are sorted by key.

---
  scripts/qmp/qmp-shell | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
scripts/qmp/qmp-shell +0 -0
index c5eef06f3f..b4d06096ab 100755

scripts/qmp/qmp-shell class QMPShell(qmp.QEMUMonitorProtocol): · line 266

Quoted 8 lines
scripts/qmp/qmp-shell +1 -1
@@ -260,7 +260,7 @@ class QMPShell(qmp.QEMUMonitorProtocol):
          indent = None
          if self._pretty:
              indent = 4
-        jsobj = json.dumps(qmp, indent=indent)
+        jsobj = json.dumps(qmp, indent=indent, sort_keys=self._pretty)
          print(str(jsobj))
 
      def _execute_cmd(self, cmdline):
#2 lore raw
In reply to David Edmondson
Quoted 13 lines · David Edmondson

If the user selects pretty-printing (-p) the contents of any dictionaries in the output are sorted by key.

---
 scripts/qmp/qmp-shell | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/qmp/qmp-shell +0 -0
index c5eef06f3f..b4d06096ab 100755

scripts/qmp/qmp-shell class QMPShell(qmp.QEMUMonitorProtocol): · line 266

Quoted 8 lines
scripts/qmp/qmp-shell +1 -1
@@ -260,7 +260,7 @@ class QMPShell(qmp.QEMUMonitorProtocol):
         indent = None
         if self._pretty:
             indent = 4
-        jsobj = json.dumps(qmp, indent=indent)
+        jsobj = json.dumps(qmp, indent=indent, sort_keys=self._pretty)
         print(str(jsobj))
 
     def _execute_cmd(self, cmdline):

Queued, thanks!

#3 lore raw
In reply to David Edmondson
Quoted 14 lines · David Edmondson

If the user selects pretty-printing (-p) the contents of any dictionaries in the output are sorted by key.

---
  scripts/qmp/qmp-shell | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
scripts/qmp/qmp-shell +0 -0
index c5eef06f3f..b4d06096ab 100755

scripts/qmp/qmp-shell class QMPShell(qmp.QEMUMonitorProtocol): · line 266

Quoted 8 lines
scripts/qmp/qmp-shell +1 -1
@@ -260,7 +260,7 @@ class QMPShell(qmp.QEMUMonitorProtocol):
          indent = None
          if self._pretty:
              indent = 4
-        jsobj = json.dumps(qmp, indent=indent)
+        jsobj = json.dumps(qmp, indent=indent, sort_keys=self._pretty)
          print(str(jsobj))
 
      def _execute_cmd(self, cmdline):

Hi, out of curiosity, what does this help you accomplish?

I've recently been overhauling a LOT of the Python utilities we have, so I'm interested in hearing about how people use these tools and what they'd like them to do.

--js

#4 lore raw
Quoted 21 lines · John Snow
Quoted 20 lines · David Edmondson

If the user selects pretty-printing (-p) the contents of any dictionaries in the output are sorted by key.

---
  scripts/qmp/qmp-shell | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
scripts/qmp/qmp-shell +1 -1
index c5eef06f3f..b4d06096ab 100755
@@ -260,7 +260,7 @@ class QMPShell(qmp.QEMUMonitorProtocol):
          indent = None
          if self._pretty:
              indent = 4
-        jsobj = json.dumps(qmp, indent=indent)
+        jsobj = json.dumps(qmp, indent=indent, sort_keys=self._pretty)
          print(str(jsobj))
 
Quoted 4 lines

scripts/qmp/qmp-shell class QMPShell(qmp.QEMUMonitorProtocol): · line 266

Quoted 2 lines
scripts/qmp/qmp-shell +0 -0
      def _execute_cmd(self, cmdline):

Hi, out of curiosity, what does this help you accomplish?

When dumping a dictionary with many values, visually finding a specific one that is of interest is much quicker if they are sorted. Nothing more than that.

Quoted 5 lines

I've recently been overhauling a LOT of the Python utilities we have, so I'm interested in hearing about how people use these tools and what they'd like them to do.

--js

dme.

Signature · 1 line
I can't explain, you would not understand. This is not how I am.
#5 lore raw
Quoted 23 lines · David Edmondson
Quoted 21 lines · John Snow
Quoted 20 lines · David Edmondson

If the user selects pretty-printing (-p) the contents of any dictionaries in the output are sorted by key.

---
   scripts/qmp/qmp-shell | 2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
scripts/qmp/qmp-shell +1 -1
index c5eef06f3f..b4d06096ab 100755
@@ -260,7 +260,7 @@ class QMPShell(qmp.QEMUMonitorProtocol):
           indent = None
           if self._pretty:
               indent = 4
-        jsobj = json.dumps(qmp, indent=indent)
+        jsobj = json.dumps(qmp, indent=indent, sort_keys=self._pretty)
           print(str(jsobj))
 
Quoted 9 lines
Quoted 4 lines

scripts/qmp/qmp-shell class QMPShell(qmp.QEMUMonitorProtocol): · line 266

Quoted 2 lines
scripts/qmp/qmp-shell +0 -0
       def _execute_cmd(self, cmdline):

Hi, out of curiosity, what does this help you accomplish?

When dumping a dictionary with many values, visually finding a specific one that is of interest is much quicker if they are sorted. Nothing more than that.

Okay, simple! thanks for the input.

If you ever have any other laundry list desires or feedback for qmp-shell, let me know, as I intend to overhaul it soon.

(I may turn it into a GSoC project, too.)

--js