qapi.py: Avoid code duplication

The code that interprets the read JSON expression and appends types to
the respective global variables was duplicated. We can avoid that by
splitting off the part that reads from the file.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
This commit is contained in:
Kevin Wolf 2013-07-01 16:31:50 +02:00 committed by Luiz Capitulino
parent 0f95305117
commit bd9927fee4
1 changed files with 9 additions and 9 deletions

View File

@ -78,10 +78,8 @@ def parse(tokens):
def evaluate(string): def evaluate(string):
return parse(map(lambda x: x, tokenize(string)))[0] return parse(map(lambda x: x, tokenize(string)))[0]
def parse_schema(fp): def get_expr(fp):
exprs = []
expr = '' expr = ''
expr_eval = None
for line in fp: for line in fp:
if line.startswith('#') or line == '\n': if line.startswith('#') or line == '\n':
@ -90,18 +88,20 @@ def parse_schema(fp):
if line.startswith(' '): if line.startswith(' '):
expr += line expr += line
elif expr: elif expr:
expr_eval = evaluate(expr) yield expr
if expr_eval.has_key('enum'):
add_enum(expr_eval['enum'])
elif expr_eval.has_key('union'):
add_enum('%sKind' % expr_eval['union'])
exprs.append(expr_eval)
expr = line expr = line
else: else:
expr += line expr += line
if expr: if expr:
yield expr
def parse_schema(fp):
exprs = []
for expr in get_expr(fp):
expr_eval = evaluate(expr) expr_eval = evaluate(expr)
if expr_eval.has_key('enum'): if expr_eval.has_key('enum'):
add_enum(expr_eval['enum']) add_enum(expr_eval['enum'])
elif expr_eval.has_key('union'): elif expr_eval.has_key('union'):