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
If we need to add a new loop argument, I don't know how to do that, append the argument to end_loop? it seems the above method hasn't a good expansibility. In addition, it will be very hard to understand a value's meaning, IMO, here should be a key/value pair, meanwhile, that will be very clear if start_loop and end_loop are aindependent line, for example: domain:start guestname vm1 start_loop times 10 ${new key} ${new value} ... domain:save guestname vm1 domain:restore guestname vm1 end_loop domain:destroy guestname vm1 Anyway, that's my personal opinion. Alex
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]
-- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list