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."""
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):
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
:
41 if is_worse_than(new_status
, self
.current_status()):
42 self
.status_stack
[-1] = new_status
46 self
.status_stack
.append(statuses
[-1])
50 result
= self
.status_stack
.pop()
51 if len(self
.status_stack
) == 0:
52 self
.status_stack
.append(statuses
[-1])
57 return len(self
.status_stack
) - 1
60 class line_buffer(object):
62 self
.buffer = collections
.deque()
66 return self
.buffer.pop()
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
)
82 return len(self
.buffer)
86 library
= "autotest_lib.tko.parsers.version_%d" % version
87 module
= __import__(library
, globals(), locals(), ["parser"])
88 return module
.parser()