Skip to content

Commit

Permalink
Merge pull request #17 from rticommunity/fix_emptylines
Browse files Browse the repository at this point in the history
Fix parser stopped to read input after empty line
  • Loading branch information
iblancasa authored Dec 27, 2016
2 parents 08adf15 + 4ed5444 commit baa3fae
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
10 changes: 8 additions & 2 deletions logparser/devices/inputdevices.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,12 @@ def read_line(self):
line = None
try:
line = stdin.readline()
except Exception: # pylint: disable=W0703
if line == "": # On EOF it'll be empty, for empty line it's \n
line = None
except Exception as ex: # pylint: disable=W0703
# On error don't return None because we want to continue reading.
line = ""
print("[InputError] %s" % ex)

if self.show_progress:
self.print_time(0.2)
Expand Down Expand Up @@ -147,9 +150,12 @@ def read_line(self):
line = None
try:
line = self.stream.readline()
except Exception: # pylint: disable=W0703
if line == "": # On EOF it'll be empty, for empty line it's \n
line = None
except Exception as ex: # pylint: disable=W0703
# On error don't return None because we want to continue reading.
line = ""
print("[InputError] %s" % ex)

if self.show_progress:
self.print_progress(0.01, 2, 51)
Expand Down
14 changes: 9 additions & 5 deletions logparser/logparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,18 @@ def _parse_log(self):
True)

# While there is a new line, parse it.
line = True # For the first condition.
while line:
line = ""
while line is not None:
# If the line contains non-UTF8 chars it could raise an exception.
self.state['input_line'] += 1
line = device.read_line().rstrip("\r\n")
line = device.read_line()

# If EOF or the line is empty, continue.
if not line or line == "":
# Remove end of lines
if line:
line = line.rstrip("\r\n")

# Skip if EOF or empty line
if not line:
continue

# Write original log if needed
Expand Down

0 comments on commit baa3fae

Please sign in to comment.