blob: 6e430a3e8fdeb389626854ecb2517ddaa2617cfa [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):
mbligh302482e2008-05-01 20:06:16 +00007 statuses = logging.job_statuses
mbligh2895ce52008-04-17 15:40:51 +00008
9
10 def __init__(self):
11 self.status_stack = [self.statuses[-1]]
12
13
14 def current_status(self):
15 return self.status_stack[-1]
16
17
18 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
25
26
27 def start(self):
28 self.status_stack.append(self.statuses[-1])
29
30
31 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
36
37
38 def size(self):
39 return len(self.status_stack) - 1
40
41
42class line_buffer(object):
43 def __init__(self):
44 self.buffer = collections.deque()
45
46
47 def get(self):
48 return self.buffer.pop()
49
50
51 def put(self, line):
52 self.buffer.appendleft(line)
53
54
55 def put_back(self, line):
56 self.buffer.append(line)
57
58
59 def size(self):
60 return len(self.buffer)
61
62
63def parser(version):
64 library = "autotest_lib.tko.parsers.version_%d" % version
65 module = __import__(library, globals(), locals(), ["parser"])
66 return module.parser()