Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parser stopped to read input after empty line #17

Merged
merged 2 commits into from
Dec 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? It should be:

while line:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because then line == "" will be false too and don't want to stop for empty lines.

# 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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You first check "if line". Then "if not line" and then you only continues with this iteration if line...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because we want to remove new line chars only when line is not None and we don't want to set line to an empty string to distinguish between empty line and EOF.

line = line.rstrip("\r\n")

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

# Write original log if needed
Expand Down