|
|
9ae3a8 |
From 4bd5352922b192e3442671b2015633720253a3e4 Mon Sep 17 00:00:00 2001
|
|
|
9ae3a8 |
From: Kevin Wolf <kwolf@redhat.com>
|
|
|
9ae3a8 |
Date: Mon, 9 Sep 2013 14:28:04 +0200
|
|
|
9ae3a8 |
Subject: [PATCH 13/38] qapi.py: Avoid code duplication
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
RH-Author: Kevin Wolf <kwolf@redhat.com>
|
|
|
9ae3a8 |
Message-id: <1378736903-18489-14-git-send-email-kwolf@redhat.com>
|
|
|
9ae3a8 |
Patchwork-id: 54200
|
|
|
9ae3a8 |
O-Subject: [RHEL-7.0 qemu-kvm PATCH 13/32] qapi.py: Avoid code duplication
|
|
|
9ae3a8 |
Bugzilla: 1005818
|
|
|
9ae3a8 |
RH-Acked-by: Fam Zheng <famz@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Max Reitz <mreitz@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Bugzilla: 1005818
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
The code that interprets the read JSON expression and appends types to
|
|
|
9ae3a8 |
the respective global variables was duplicated. We can avoid that by
|
|
|
9ae3a8 |
splitting off the part that reads from the file.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
9ae3a8 |
Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com>
|
|
|
9ae3a8 |
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
|
|
|
9ae3a8 |
(cherry picked from commit bd9927fee4e63b451b4ef67a4c49729070d8b05d)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
scripts/qapi.py | 18 +++++++++---------
|
|
|
9ae3a8 |
1 file changed, 9 insertions(+), 9 deletions(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
scripts/qapi.py | 18 +++++++++---------
|
|
|
9ae3a8 |
1 files changed, 9 insertions(+), 9 deletions(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/scripts/qapi.py b/scripts/qapi.py
|
|
|
9ae3a8 |
index afc5f32..daedaea 100644
|
|
|
9ae3a8 |
--- a/scripts/qapi.py
|
|
|
9ae3a8 |
+++ b/scripts/qapi.py
|
|
|
9ae3a8 |
@@ -72,10 +72,8 @@ def parse(tokens):
|
|
|
9ae3a8 |
def evaluate(string):
|
|
|
9ae3a8 |
return parse(map(lambda x: x, tokenize(string)))[0]
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
-def parse_schema(fp):
|
|
|
9ae3a8 |
- exprs = []
|
|
|
9ae3a8 |
+def get_expr(fp):
|
|
|
9ae3a8 |
expr = ''
|
|
|
9ae3a8 |
- expr_eval = None
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
for line in fp:
|
|
|
9ae3a8 |
if line.startswith('#') or line == '\n':
|
|
|
9ae3a8 |
@@ -84,18 +82,20 @@ def parse_schema(fp):
|
|
|
9ae3a8 |
if line.startswith(' '):
|
|
|
9ae3a8 |
expr += line
|
|
|
9ae3a8 |
elif expr:
|
|
|
9ae3a8 |
- expr_eval = evaluate(expr)
|
|
|
9ae3a8 |
- if expr_eval.has_key('enum'):
|
|
|
9ae3a8 |
- add_enum(expr_eval['enum'])
|
|
|
9ae3a8 |
- elif expr_eval.has_key('union'):
|
|
|
9ae3a8 |
- add_enum('%sKind' % expr_eval['union'])
|
|
|
9ae3a8 |
- exprs.append(expr_eval)
|
|
|
9ae3a8 |
+ yield expr
|
|
|
9ae3a8 |
expr = line
|
|
|
9ae3a8 |
else:
|
|
|
9ae3a8 |
expr += line
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
if expr:
|
|
|
9ae3a8 |
+ yield expr
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+def parse_schema(fp):
|
|
|
9ae3a8 |
+ exprs = []
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ for expr in get_expr(fp):
|
|
|
9ae3a8 |
expr_eval = evaluate(expr)
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
if expr_eval.has_key('enum'):
|
|
|
9ae3a8 |
add_enum(expr_eval['enum'])
|
|
|
9ae3a8 |
elif expr_eval.has_key('union'):
|
|
|
9ae3a8 |
--
|
|
|
9ae3a8 |
1.7.1
|
|
|
9ae3a8 |
|