blob: ab5c6440c11adefb7a5dcbc10e25d339e2f56ae0 [file] [log] [blame]
mbligh2895ce52008-04-17 15:40:51 +00001import collections
mbligh302482e2008-05-01 20:06:16 +00002import common
3from autotest_lib.client.common_lib import logging
mbligh2895ce52008-04-17 15:40:51 +00004
5
6class status_stack(object):
jadmanski0afbb632008-06-06 21:10:57 +00007 statuses = logging.job_statuses
mbligh2895ce52008-04-17 15:40:51 +00008
9
jadmanski0afbb632008-06-06 21:10:57 +000010 def __init__(self):
11 self.status_stack = [self.statuses[-1]]
mbligh2895ce52008-04-17 15:40:51 +000012
13
jadmanski0afbb632008-06-06 21:10:57 +000014 def current_status(self):
15 return self.status_stack[-1]
mbligh2895ce52008-04-17 15:40:51 +000016
17
jadmanski0afbb632008-06-06 21:10:57 +000018 def update(self, new_status):
19 if new_status not in self.statuses:
20 return
21 old = self.statuses.index(self.current_status())
22 new = self.statuses.index(new_status)
23 if new < old:
24 self.status_stack[-1] = new_status
mbligh2895ce52008-04-17 15:40:51 +000025
26
jadmanski0afbb632008-06-06 21:10:57 +000027 def start(self):
28 self.status_stack.append(self.statuses[-1])
mbligh2895ce52008-04-17 15:40:51 +000029
30
jadmanski0afbb632008-06-06 21:10:57 +000031 def end(self):
32 result = self.status_stack.pop()
33 if len(self.status_stack) == 0:
34 self.status_stack.append(self.statuses[-1])
35 return result
mbligh2895ce52008-04-17 15:40:51 +000036
37
jadmanski0afbb632008-06-06 21:10:57 +000038 def size(self):
39 return len(self.status_stack) - 1
mbligh2895ce52008-04-17 15:40:51 +000040
41
42class line_buffer(object):
jadmanski0afbb632008-06-06 21:10:57 +000043 def __init__(self):
44 self.buffer = collections.deque()
mbligh2895ce52008-04-17 15:40:51 +000045
46
jadmanski0afbb632008-06-06 21:10:57 +000047 def get(self):
48 return self.buffer.pop()
mbligh2895ce52008-04-17 15:40:51 +000049
50
jadmanski0afbb632008-06-06 21:10:57 +000051 def put(self, line):
52 self.buffer.appendleft(line)
mbligh2895ce52008-04-17 15:40:51 +000053
54
jadmanski0afbb632008-06-06 21:10:57 +000055 def put_multiple(self, lines):
56 self.buffer.extendleft(lines)
jadmanski6e8bf752008-05-14 00:17:48 +000057
58
jadmanski0afbb632008-06-06 21:10:57 +000059 def put_back(self, line):
60 self.buffer.append(line)
mbligh2895ce52008-04-17 15:40:51 +000061
62
jadmanski0afbb632008-06-06 21:10:57 +000063 def size(self):
64 return len(self.buffer)
mbligh2895ce52008-04-17 15:40:51 +000065
66
67def parser(version):
jadmanski0afbb632008-06-06 21:10:57 +000068 library = "autotest_lib.tko.parsers.version_%d" % version
69 module = __import__(library, globals(), locals(), ["parser"])
70 return module.parser()