summaryrefslogtreecommitdiff
path: root/tko/status_lib.py
blob: 4ddfa5aacb7f1040d864f3c268d70aec00866be2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import collections
import common
from autotest_lib.client.common_lib import logging


class status_stack(object):
	statuses = logging.job_statuses


	def __init__(self):
		self.status_stack = [self.statuses[-1]]


	def current_status(self):
		return self.status_stack[-1]


	def update(self, new_status):
		if new_status not in self.statuses:
			return
		old = self.statuses.index(self.current_status())
		new = self.statuses.index(new_status)
		if new < old:
			self.status_stack[-1] = new_status


	def start(self):
		self.status_stack.append(self.statuses[-1])


	def end(self):
		result = self.status_stack.pop()
		if len(self.status_stack) == 0:
			self.status_stack.append(self.statuses[-1])
		return result


	def size(self):
		return len(self.status_stack) - 1


class line_buffer(object):
	def __init__(self):
		self.buffer = collections.deque()


	def get(self):
		return self.buffer.pop()


	def put(self, line):
		self.buffer.appendleft(line)


	def put_multiple(self, lines):
		self.buffer.extendleft(lines)


	def put_back(self, line):
		self.buffer.append(line)


	def size(self):
		return len(self.buffer)


def parser(version):
	library = "autotest_lib.tko.parsers.version_%d" % version
	module = __import__(library, globals(), locals(), ["parser"])
	return module.parser()