On 06/16/2011 01:14 PM, Nan Zhang wrote:
For example:
-----------------
domain:start
guestname
vm1
domain:save start_loop
guestname
vm1
domain:restore end_loop 10
guestname
vm1
domain:destroy
guestname
vm1
-----------------
---
parser.py | 46 +++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 45 insertions(+), 1 deletions(-)
diff --git a/parser.py b/parser.py
index 5b3ce58..e9cce58 100644
--- a/parser.py
+++ b/parser.py
@@ -31,13 +31,18 @@ class CaseFileParser(object):
""" Parser the case configuration file to generate a data list.
"""
def __init__(self, casefile=None, debug=False):
- """ Initialize the list and optionally parse case file.
"""
self.list = [[]]
self.variables = {}
self.missing_variables = []
self.debug = debug
self.casefile = casefile
self.env = env_parser.Envparser("env.cfg")
+ self.loop_finish = False
+ self.loop_start = 0
+ self.loop_end = 0
+ self.loop_times = 0
+ self.loop_list = []
+
if casefile:
self.parse_file(casefile)
@@ -306,6 +311,7 @@ class CaseFileParser(object):
def parse(self, fh, list):
""" For the testcase name parsing. """
+
while True:
if self.debug:
self.debug_print("the list is", list)
@@ -330,6 +336,44 @@ class CaseFileParser(object):
self.debug_print("we begin to handle the case",
tripped_casename)
+ if self.loop_finish:
+ for i in range(len(list)):
+ self.loop_list.append([])
+
+ i = 0
+ for caselist in list:
+ for j in range(self.loop_start, self.loop_end):
+ self.loop_list[i].append(caselist.pop())
+
+ self.loop_list[i].reverse()
+ self.debug_print("loop_list is", self.loop_list)
+ caselist.extend(self.loop_list[i] * self.loop_times)
+ i += 1
+
+ self.loop_finish = False
+
+ if len(tripped_caselist) == 2 and \
+ tripped_caselist[1] == "start_loop":
+ for caselist in list:
+ newdict = {}
+ newdict[tripped_casename] = {}
+ caselist.append(newdict)
+ self.loop_start = len(caselist) - 1
+ continue
+
+ if len(tripped_caselist) == 3 and \
+ tripped_caselist[1] == "end_loop":
+ looptimes = tripped_caselist[2]
+ self.debug_print("looptimes is", looptimes)
+ self.loop_times = int(looptimes)
+ self.loop_finish = True
+ for caselist in list:
+ newdict = {}
+ newdict[tripped_casename] = {}
+ caselist.append(newdict)
+ self.loop_end = len(caselist)
+ continue
+
if len(tripped_caselist) == 3 and \
tripped_caselist[1] == "times":
times = tripped_caselist[2]
The patch uses the
global variable to mark the start point of
loop , so before we meet
a second loop ,we need to ensure the variable to be initialized to
the original.