virt.virt_test_utils: run_autotest - 'tar' needs relative paths to strip the leading '/'
[autotest-zwu.git] / tko / status_lib.py
blob1c35ac1e25242121725c311077680588667959be
1 import collections, re
2 import common
3 from autotest_lib.client.common_lib import log
6 statuses = log.job_statuses
9 def is_worse_than(lhs, rhs):
10 """ Compare two statuses and return a boolean indicating if the LHS status
11 is worse than the RHS status."""
12 return (statuses.index(lhs) < statuses.index(rhs))
15 def is_worse_than_or_equal_to(lhs, rhs):
16 """ Compare two statuses and return a boolean indicating if the LHS status
17 is worse than or equal to the RHS status."""
18 if lhs == rhs:
19 return True
20 return is_worse_than(lhs, rhs)
23 DEFAULT_BLACKLIST = ('\r\x00',)
24 def clean_raw_line(raw_line, blacklist=DEFAULT_BLACKLIST):
25 """Strip blacklisted characters from raw_line."""
26 return re.sub('|'.join(blacklist), '', raw_line)
29 class status_stack(object):
30 def __init__(self):
31 self.status_stack = [statuses[-1]]
34 def current_status(self):
35 return self.status_stack[-1]
38 def update(self, new_status):
39 if new_status not in statuses:
40 return
41 if is_worse_than(new_status, self.current_status()):
42 self.status_stack[-1] = new_status
45 def start(self):
46 self.status_stack.append(statuses[-1])
49 def end(self):
50 result = self.status_stack.pop()
51 if len(self.status_stack) == 0:
52 self.status_stack.append(statuses[-1])
53 return result
56 def size(self):
57 return len(self.status_stack) - 1
60 class line_buffer(object):
61 def __init__(self):
62 self.buffer = collections.deque()
65 def get(self):
66 return self.buffer.pop()
69 def put(self, line):
70 self.buffer.appendleft(line)
73 def put_multiple(self, lines):
74 self.buffer.extendleft(lines)
77 def put_back(self, line):
78 self.buffer.append(line)
81 def size(self):
82 return len(self.buffer)
85 def parser(version):
86 library = "autotest_lib.tko.parsers.version_%d" % version
87 module = __import__(library, globals(), locals(), ["parser"])
88 return module.parser()