mbligh | 2895ce5 | 2008-04-17 15:40:51 +0000 | [diff] [blame] | 1 | import collections |
mbligh | 302482e | 2008-05-01 20:06:16 +0000 | [diff] [blame] | 2 | import common |
3 | from autotest_lib.client.common_lib import logging | ||||
mbligh | 2895ce5 | 2008-04-17 15:40:51 +0000 | [diff] [blame] | 4 | |
5 | |||||
6 | class status_stack(object): | ||||
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame^] | 7 | statuses = logging.job_statuses |
mbligh | 2895ce5 | 2008-04-17 15:40:51 +0000 | [diff] [blame] | 8 | |
9 | |||||
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame^] | 10 | def __init__(self): |
11 | self.status_stack = [self.statuses[-1]] | ||||
mbligh | 2895ce5 | 2008-04-17 15:40:51 +0000 | [diff] [blame] | 12 | |
13 | |||||
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame^] | 14 | def current_status(self): |
15 | return self.status_stack[-1] | ||||
mbligh | 2895ce5 | 2008-04-17 15:40:51 +0000 | [diff] [blame] | 16 | |
17 | |||||
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame^] | 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 | ||||
mbligh | 2895ce5 | 2008-04-17 15:40:51 +0000 | [diff] [blame] | 25 | |
26 | |||||
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame^] | 27 | def start(self): |
28 | self.status_stack.append(self.statuses[-1]) | ||||
mbligh | 2895ce5 | 2008-04-17 15:40:51 +0000 | [diff] [blame] | 29 | |
30 | |||||
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame^] | 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 | ||||
mbligh | 2895ce5 | 2008-04-17 15:40:51 +0000 | [diff] [blame] | 36 | |
37 | |||||
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame^] | 38 | def size(self): |
39 | return len(self.status_stack) - 1 | ||||
mbligh | 2895ce5 | 2008-04-17 15:40:51 +0000 | [diff] [blame] | 40 | |
41 | |||||
42 | class line_buffer(object): | ||||
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame^] | 43 | def __init__(self): |
44 | self.buffer = collections.deque() | ||||
mbligh | 2895ce5 | 2008-04-17 15:40:51 +0000 | [diff] [blame] | 45 | |
46 | |||||
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame^] | 47 | def get(self): |
48 | return self.buffer.pop() | ||||
mbligh | 2895ce5 | 2008-04-17 15:40:51 +0000 | [diff] [blame] | 49 | |
50 | |||||
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame^] | 51 | def put(self, line): |
52 | self.buffer.appendleft(line) | ||||
mbligh | 2895ce5 | 2008-04-17 15:40:51 +0000 | [diff] [blame] | 53 | |
54 | |||||
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame^] | 55 | def put_multiple(self, lines): |
56 | self.buffer.extendleft(lines) | ||||
jadmanski | 6e8bf75 | 2008-05-14 00:17:48 +0000 | [diff] [blame] | 57 | |
58 | |||||
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame^] | 59 | def put_back(self, line): |
60 | self.buffer.append(line) | ||||
mbligh | 2895ce5 | 2008-04-17 15:40:51 +0000 | [diff] [blame] | 61 | |
62 | |||||
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame^] | 63 | def size(self): |
64 | return len(self.buffer) | ||||
mbligh | 2895ce5 | 2008-04-17 15:40:51 +0000 | [diff] [blame] | 65 | |
66 | |||||
67 | def parser(version): | ||||
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame^] | 68 | library = "autotest_lib.tko.parsers.version_%d" % version |
69 | module = __import__(library, globals(), locals(), ["parser"]) | ||||
70 | return module.parser() |