diff mbox

[KVM-AUTOTEST,13/17] KVM test: fix a parsing problem in kvm_config.py

Message ID e9c95b309190c10502e17917db915cb55cb61a81.1248102188.git.mgoldish@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Michael Goldish July 20, 2009, 3:07 p.m. UTC
Allow kvm_config to parse weird lines that seem to contain several operators,
such as:
time_filter_re = "(?<=TIME: ...)"

The '?<=' is recognized as the operator instead of the '='.
To fix this, select the operator closest to the beginning of the line.

Signed-off-by: Michael Goldish <mgoldish@redhat.com>
---
 client/tests/kvm/kvm_config.py |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

Comments

Lucas Meneghel Rodrigues July 27, 2009, 1:31 p.m. UTC | #1
On Mon, Jul 20, 2009 at 12:07 PM, Michael Goldish<mgoldish@redhat.com> wrote:
> Allow kvm_config to parse weird lines that seem to contain several operators,
> such as:
> time_filter_re = "(?<=TIME: ...)"
>
> The '?<=' is recognized as the operator instead of the '='.
> To fix this, select the operator closest to the beginning of the line.

Applied.

> Signed-off-by: Michael Goldish <mgoldish@redhat.com>
> ---
>  client/tests/kvm/kvm_config.py |    6 ++++--
>  1 files changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/client/tests/kvm/kvm_config.py b/client/tests/kvm/kvm_config.py
> index 95eefcb..99ccb2a 100755
> --- a/client/tests/kvm/kvm_config.py
> +++ b/client/tests/kvm/kvm_config.py
> @@ -294,10 +294,12 @@ class config:
>             # Look for a known operator in the line
>             operators = ["?+=", "?<=", "?=", "+=", "<=", "="]
>             op_found = None
> +            op_pos = len(line)
>             for op in operators:
> -                if op in line:
> +                pos = line.find(op)
> +                if pos >= 0 and pos < op_pos:
>                     op_found = op
> -                    break
> +                    op_pos = pos
>
>             # Found an operator?
>             if op_found:
> --
> 1.5.4.1
>
> _______________________________________________
> Autotest mailing list
> Autotest@test.kernel.org
> http://test.kernel.org/cgi-bin/mailman/listinfo/autotest
>
diff mbox

Patch

diff --git a/client/tests/kvm/kvm_config.py b/client/tests/kvm/kvm_config.py
index 95eefcb..99ccb2a 100755
--- a/client/tests/kvm/kvm_config.py
+++ b/client/tests/kvm/kvm_config.py
@@ -294,10 +294,12 @@  class config:
             # Look for a known operator in the line
             operators = ["?+=", "?<=", "?=", "+=", "<=", "="]
             op_found = None
+            op_pos = len(line)
             for op in operators:
-                if op in line:
+                pos = line.find(op)
+                if pos >= 0 and pos < op_pos:
                     op_found = op
-                    break
+                    op_pos = pos
 
             # Found an operator?
             if op_found: