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): |
mbligh | 302482e | 2008-05-01 20:06:16 +0000 | [diff] [blame^] | 7 | statuses = logging.job_statuses |
mbligh | 2895ce5 | 2008-04-17 15:40:51 +0000 | [diff] [blame] | 8 | |
| 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 | |
| 42 | class 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 | |
| 63 | def parser(version): |
| 64 | library = "autotest_lib.tko.parsers.version_%d" % version |
| 65 | module = __import__(library, globals(), locals(), ["parser"]) |
| 66 | return module.parser() |