[PATCH] qmp-shell: Sort by key when pretty-printing

David Edmondson posted 1 patch 3 years, 6 months ago
Test checkpatch passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20201013141414.18398-1-david.edmondson@oracle.com
Maintainers: Markus Armbruster <armbru@redhat.com>
scripts/qmp/qmp-shell | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] qmp-shell: Sort by key when pretty-printing
Posted by David Edmondson 3 years, 6 months ago
If the user selects pretty-printing (-p) the contents of any
dictionaries in the output are sorted by key.

Signed-off-by: David Edmondson <david.edmondson@oracle.com>
---
 scripts/qmp/qmp-shell | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell
index c5eef06f3f..b4d06096ab 100755
--- a/scripts/qmp/qmp-shell
+++ b/scripts/qmp/qmp-shell
@@ -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.28.0


Re: [PATCH] qmp-shell: Sort by key when pretty-printing
Posted by Philippe Mathieu-Daudé 3 years, 6 months ago
On 10/13/20 4:14 PM, David Edmondson wrote:
> If the user selects pretty-printing (-p) the contents of any
> dictionaries in the output are sorted by key.
> 
> Signed-off-by: David Edmondson <david.edmondson@oracle.com>
> ---
>   scripts/qmp/qmp-shell | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell
> index c5eef06f3f..b4d06096ab 100755
> --- a/scripts/qmp/qmp-shell
> +++ b/scripts/qmp/qmp-shell
> @@ -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):
> 

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>


Re: [PATCH] qmp-shell: Sort by key when pretty-printing
Posted by Markus Armbruster 3 years, 6 months ago
David Edmondson <david.edmondson@oracle.com> writes:

> If the user selects pretty-printing (-p) the contents of any
> dictionaries in the output are sorted by key.
>
> Signed-off-by: David Edmondson <david.edmondson@oracle.com>
> ---
>  scripts/qmp/qmp-shell | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell
> index c5eef06f3f..b4d06096ab 100755
> --- a/scripts/qmp/qmp-shell
> +++ b/scripts/qmp/qmp-shell
> @@ -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!


Re: [PATCH] qmp-shell: Sort by key when pretty-printing
Posted by John Snow 3 years, 4 months ago
On 10/13/20 10:14 AM, David Edmondson wrote:
> If the user selects pretty-printing (-p) the contents of any
> dictionaries in the output are sorted by key.
> 
> Signed-off-by: David Edmondson <david.edmondson@oracle.com>
> ---
>   scripts/qmp/qmp-shell | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell
> index c5eef06f3f..b4d06096ab 100755
> --- a/scripts/qmp/qmp-shell
> +++ b/scripts/qmp/qmp-shell
> @@ -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


Re: [PATCH] qmp-shell: Sort by key when pretty-printing
Posted by David Edmondson 3 years, 4 months ago
On Monday, 2020-11-30 at 15:56:51 -05, John Snow wrote:

> On 10/13/20 10:14 AM, David Edmondson wrote:
>> If the user selects pretty-printing (-p) the contents of any
>> dictionaries in the output are sorted by key.
>> 
>> Signed-off-by: David Edmondson <david.edmondson@oracle.com>
>> ---
>>   scripts/qmp/qmp-shell | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>> 
>> diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell
>> index c5eef06f3f..b4d06096ab 100755
>> --- a/scripts/qmp/qmp-shell
>> +++ b/scripts/qmp/qmp-shell
>> @@ -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?

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.

> 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.
-- 
I can't explain, you would not understand. This is not how I am.

Re: [PATCH] qmp-shell: Sort by key when pretty-printing
Posted by John Snow 3 years, 4 months ago
On 11/30/20 4:57 PM, David Edmondson wrote:
> On Monday, 2020-11-30 at 15:56:51 -05, John Snow wrote:
> 
>> On 10/13/20 10:14 AM, David Edmondson wrote:
>>> If the user selects pretty-printing (-p) the contents of any
>>> dictionaries in the output are sorted by key.
>>>
>>> Signed-off-by: David Edmondson <david.edmondson@oracle.com>
>>> ---
>>>    scripts/qmp/qmp-shell | 2 +-
>>>    1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell
>>> index c5eef06f3f..b4d06096ab 100755
>>> --- a/scripts/qmp/qmp-shell
>>> +++ b/scripts/qmp/qmp-shell
>>> @@ -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?
> 
> 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