All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] scripts/qmp/qom-set: Allow setting integer value
@ 2020-10-02 20:52 Jonatan Pålsson
  2020-10-03 17:33 ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 4+ messages in thread
From: Jonatan Pålsson @ 2020-10-02 20:52 UTC (permalink / raw)
  To: qemu-devel; +Cc: Jonatan Pålsson

If the value appears to be an integer, parse it as such.

This allows the following:

    qmp/qom-set -s ~/qmp.sock sensor.temperature 20000

.. where sensor is a tmp105 device, and temperature is an integer
property.

Signed-off-by: Jonatan Pålsson <jonatan.p@gmail.com>
---
 scripts/qmp/qom-set | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/scripts/qmp/qom-set b/scripts/qmp/qom-set
index 240a78187f..49eebe4924 100755
--- a/scripts/qmp/qom-set
+++ b/scripts/qmp/qom-set
@@ -56,7 +56,10 @@ if len(args) > 1:
         path, prop = args[0].rsplit('.', 1)
     except:
         usage_error("invalid format for path/property/value")
-    value = args[1]
+    try:
+        value = int(args[1])
+    except ValueError:
+        value = args[1]
 else:
     usage_error("not enough arguments")
 
-- 
2.26.1



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

* Re: [PATCH v2] scripts/qmp/qom-set: Allow setting integer value
  2020-10-02 20:52 [PATCH v2] scripts/qmp/qom-set: Allow setting integer value Jonatan Pålsson
@ 2020-10-03 17:33 ` Philippe Mathieu-Daudé
  2020-10-03 23:55   ` John Snow
  0 siblings, 1 reply; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-10-03 17:33 UTC (permalink / raw)
  To: Jonatan Pålsson; +Cc: John Snow, qemu-devel

Hi Jonatan,

On 10/2/20 10:52 PM, Jonatan Pålsson wrote:
> If the value appears to be an integer, parse it as such.
> 
> This allows the following:
> 
>     qmp/qom-set -s ~/qmp.sock sensor.temperature 20000

Maybe instead:

Fix the following error:

  $ scripts/qmp/qom-set -s ~/qmp.sock sensor.temperature 20000
  Traceback (most recent call last):
    File "scripts/qmp/qom-set", line 66, in <module>
      print(srv.command('qom-set', path=path, property=prop, value=value))
    File "scripts/qmp/../../python/qemu/qmp.py", line 274, in command
      raise QMPResponseError(ret)
  qemu.qmp.QMPResponseError: Invalid parameter type for 'temperature',
expected: integer

> 
> .. where sensor is a tmp105 device, and temperature is an integer
> property.
> 
> Signed-off-by: Jonatan Pålsson <jonatan.p@gmail.com>
> ---
>  scripts/qmp/qom-set | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/scripts/qmp/qom-set b/scripts/qmp/qom-set
> index 240a78187f..49eebe4924 100755
> --- a/scripts/qmp/qom-set
> +++ b/scripts/qmp/qom-set
> @@ -56,7 +56,10 @@ if len(args) > 1:
>          path, prop = args[0].rsplit('.', 1)
>      except:
>          usage_error("invalid format for path/property/value")
> -    value = args[1]
> +    try:
> +        value = int(args[1])

Maybe 'long' is safer?

> +    except ValueError:
> +        value = args[1]
>  else:
>      usage_error("not enough arguments")
>  
> 



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

* Re: [PATCH v2] scripts/qmp/qom-set: Allow setting integer value
  2020-10-03 17:33 ` Philippe Mathieu-Daudé
@ 2020-10-03 23:55   ` John Snow
  2020-10-04  9:46     ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 4+ messages in thread
From: John Snow @ 2020-10-03 23:55 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, Jonatan Pålsson; +Cc: qemu-devel

On 10/3/20 1:33 PM, Philippe Mathieu-Daudé wrote:
> Hi Jonatan,
> 
> On 10/2/20 10:52 PM, Jonatan Pålsson wrote:
>> If the value appears to be an integer, parse it as such.
>>
>> This allows the following:
>>
>>      qmp/qom-set -s ~/qmp.sock sensor.temperature 20000
> 
> Maybe instead:
> 
> Fix the following error:
> 
>    $ scripts/qmp/qom-set -s ~/qmp.sock sensor.temperature 20000
>    Traceback (most recent call last):
>      File "scripts/qmp/qom-set", line 66, in <module>
>        print(srv.command('qom-set', path=path, property=prop, value=value))
>      File "scripts/qmp/../../python/qemu/qmp.py", line 274, in command
>        raise QMPResponseError(ret)
>    qemu.qmp.QMPResponseError: Invalid parameter type for 'temperature',
> expected: integer
> 

No, this is just relaying the error that QMP returned. QMP is telling 
you it doesn't want string data for this parameter. His diagnosis of the 
problem is accurate.

>>
>> .. where sensor is a tmp105 device, and temperature is an integer
>> property.
>>
>> Signed-off-by: Jonatan Pålsson <jonatan.p@gmail.com>
>> ---
>>   scripts/qmp/qom-set | 5 ++++-
>>   1 file changed, 4 insertions(+), 1 deletion(-)
>>
>> diff --git a/scripts/qmp/qom-set b/scripts/qmp/qom-set
>> index 240a78187f..49eebe4924 100755
>> --- a/scripts/qmp/qom-set
>> +++ b/scripts/qmp/qom-set
>> @@ -56,7 +56,10 @@ if len(args) > 1:
>>           path, prop = args[0].rsplit('.', 1)
>>       except:
>>           usage_error("invalid format for path/property/value")
>> -    value = args[1]
>> +    try:
>> +        value = int(args[1])
> 
> Maybe 'long' is safer?
> 

This is a Python patch, what's a "long"?

>> +    except ValueError:
>> +        value = args[1]
>>   else:
>>       usage_error("not enough arguments")
>>   
>>
> 



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

* Re: [PATCH v2] scripts/qmp/qom-set: Allow setting integer value
  2020-10-03 23:55   ` John Snow
@ 2020-10-04  9:46     ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-10-04  9:46 UTC (permalink / raw)
  To: John Snow, Jonatan Pålsson; +Cc: qemu-devel

On 10/4/20 1:55 AM, John Snow wrote:
> On 10/3/20 1:33 PM, Philippe Mathieu-Daudé wrote:
>> Hi Jonatan,
>>
>> On 10/2/20 10:52 PM, Jonatan Pålsson wrote:
>>> If the value appears to be an integer, parse it as such.
>>>
>>> This allows the following:
>>>
>>>      qmp/qom-set -s ~/qmp.sock sensor.temperature 20000
>>
>> Maybe instead:
>>
>> Fix the following error:
>>
>>    $ scripts/qmp/qom-set -s ~/qmp.sock sensor.temperature 20000
>>    Traceback (most recent call last):
>>      File "scripts/qmp/qom-set", line 66, in <module>
>>        print(srv.command('qom-set', path=path, property=prop,
>> value=value))
>>      File "scripts/qmp/../../python/qemu/qmp.py", line 274, in command
>>        raise QMPResponseError(ret)
>>    qemu.qmp.QMPResponseError: Invalid parameter type for 'temperature',
>> expected: integer
>>
> 
> No, this is just relaying the error that QMP returned. QMP is telling
> you it doesn't want string data for this parameter. His diagnosis of the
> problem is accurate.

OK.

> 
>>>
>>> .. where sensor is a tmp105 device, and temperature is an integer
>>> property.
>>>
>>> Signed-off-by: Jonatan Pålsson <jonatan.p@gmail.com>
>>> ---
>>>   scripts/qmp/qom-set | 5 ++++-
>>>   1 file changed, 4 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/scripts/qmp/qom-set b/scripts/qmp/qom-set
>>> index 240a78187f..49eebe4924 100755
>>> --- a/scripts/qmp/qom-set
>>> +++ b/scripts/qmp/qom-set
>>> @@ -56,7 +56,10 @@ if len(args) > 1:
>>>           path, prop = args[0].rsplit('.', 1)
>>>       except:
>>>           usage_error("invalid format for path/property/value")
>>> -    value = args[1]
>>> +    try:
>>> +        value = int(args[1])
>>
>> Maybe 'long' is safer?
>>
> 
> This is a Python patch, what's a "long"?

I haven't finished the mental 2 -> 3 switch yet :/

> 
>>> +    except ValueError:
>>> +        value = args[1]
>>>   else:
>>>       usage_error("not enough arguments")
>>>  
>>
> 



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

end of thread, other threads:[~2020-10-04  9:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-02 20:52 [PATCH v2] scripts/qmp/qom-set: Allow setting integer value Jonatan Pålsson
2020-10-03 17:33 ` Philippe Mathieu-Daudé
2020-10-03 23:55   ` John Snow
2020-10-04  9:46     ` Philippe Mathieu-Daudé

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.