Commit cb9ea8c3 authored by Frédéric Escudié's avatar Frédéric Escudié
Browse files

Increase speed for MakefloLog parsing.

parent 0a2f630c
......@@ -46,43 +46,21 @@ class LogParserMixin(object):
'# COMPLETED' : lambda s, l: s._parse_completed(l),
}
def parse(self, offset=None):
""" Parse the log stream based on `offset`.
If `offset` is specified, we seek to that location in the file before
reading, otherwise, we seek to the offset stored in the internal
:class:`Log` object. This allows for resuming parsing of active
Makeflow logs (i.e. for monitoring applications).
def parse(self):
""" Parse the log stream.
If a parsing error occurs, a :class:`LogParserError` is thrown.
"""
stream = open(self.path, 'r')
offset = offset or self.offset
try:
stream.seek(offset)
except IOError:
return
while self.parse_stream(stream):
pass
self.offset = stream.tell()
def parse_stream(self, stream):
line = stream.readline()
if not line:
return False
line = line.strip()
key = line.split('\t')[0]
try:
LogParserMixin._PARSERS[key](self, line)
except KeyError:
if not line.startswith('#'):
self._parse_event(line)
return True
for line in stream:
line = line.strip()
key = line.split('\t')[0]
try:
LogParserMixin._PARSERS[key](self, line)
except KeyError:
if not line.startswith('#'):
self._parse_event(line)
stream.close()
@raise_parser_error(ValueError, 'node', LogParserError)
def _parse_node(self, line):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment