On 11/03/2010 05:21 PM, Michael Goldish wrote:
> On 11/03/2010 10:55 AM, Jinxin Zheng wrote:
>
>> On 11/03/2010 04:31 PM, Michael Goldish wrote:
>>
>>> On 11/03/2010 09:23 AM, Jinxin Zheng wrote:
>>>
>>>
>>>> On 11/03/2010 03:07 PM, Jason Wang wrote:
>>>>
>>>>
>>>>> Jinxin Zheng writes:
>>>>> > Hi,
>>>>> >
>>>>> > Is there any way to delete an existing option in the kvm test
>>>>> config file?
>>>>> >
>>>>> > I mean, something like this:
>>>>> >
>>>>> > --
>>>>> > key1 = value1
>>>>> > key2 = value2
>>>>> > key3 = value3
>>>>> >
>>>>> > variants:
>>>>> > - one:
>>>>> > key1 = Hello World
>>>>> > unset key2<--- delete the option only in this dict.
>>>>> > - two:
>>>>> >
>>>>>
>>>>> I'm not sure but does
>>>>>
>>>>> key2 =
>>>>>
>>>>> works?
>>>>>
>>>>>
>>>>>
>>>> Thank you. This sets the option empty but does not delete the option.
>>>>
>>>>
>>> If that isn't good enough, you should probably modify the test you're
>>> using to use the parameter only if it evaluates as true, e.g.
>>>
>>> if params.get("key2"):
>>> do_something(params.get("key2"))
>>>
>>> This way empty values will be considered as though they are unset.
>>>
>>>
>> Could be, though this would require more modification in the tests.
>>
> Yes, but I think that's OK because most tests already do that (in
> kvm-autotest anyway).
>
> The required changes are very small. Instead of using:
> if 'key2' in params:
> Use:
> if params.get('key2'):
>
> And instead of:
> value = params.get("key2", "default value")
> Use:
> value = params.get("key2") or "default value"
>
> This way if the value of key2 is "", "default value" will be used.
>
>
>>> If this is impossible (perhaps "" is a valid value for the parameter),
>>> then we can easily add an 'unset' command to the config parser.
>>> Mind if I ask which test you're running?
>>>
>>>
>> Actually I'm running xen-autotest, which uses an earlier version of the
>> kvm config file parser.
>>
>> Yufang implemented a new operator '?-' which works perfect for us.
>> However this patch does not apply to the upstream code.
>>
> We can use that upstream too. What's the syntax of the '?-' operator?
> What do you think about using 'del key2' like in Python?
>
The operator is used as:
key2 ?-
In Yufang's implementation, this operator treats key2 as a regex and
deletes all the options that matches, which is the behavior the '?' implies.
I think a 'del' command would also be ideal, but I guess it would match
the key exactly.
This is the main part of Yufang's '?-' code:
--
...
elif op_found == "?-":
for dict in filtered_list:
for key in dict.keys():
if exp.match(key):
dict.pop(key)
--
Regards.
Jinxin
_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest