Skip to content
This repository has been archived by the owner on Jan 31, 2021. It is now read-only.

Commit

Permalink
test/py: support TABs in log
Browse files Browse the repository at this point in the history
Wrap all logged stream content with <pre>. This allows TABs to work as
expected, so this commit stops converting TABs to "escape" sequences. It
also means that we don't have to:
- Convert spaces to &nbsp;.
- Convert newlines to<br/>.
- Manually check whether the last line of a stream ended with a newline
  or not in order to prevent the next "heading" from merging with the
  previous line.

The default CSS style for <pre> seems to include a top/bottom margin that
we don't want, so modify the CSS style sheet to remove this. This keeps
the spacing/layout of the HTML log file the same before/after this change.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
  • Loading branch information
nvswarren committed Dec 18, 2015
1 parent e5ff675 commit ee09f5d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
5 changes: 5 additions & 0 deletions test/py/multiplexed_log.css
Expand Up @@ -9,6 +9,11 @@ body {
color: #ffffff;
}

pre {
margin-top: 0px;
margin-bottom: 0px;
}

.implicit {
color: #808080;
}
Expand Down
13 changes: 4 additions & 9 deletions test/py/multiplexed_log.py
Expand Up @@ -73,7 +73,6 @@ class Logfile(object):
def __init__(self, fn):
self.f = open(fn, "wt")
self.last_stream = None
self.linebreak = True
self.blocks = []
self.cur_evt = 1
shutil.copy(mod_dir + "/multiplexed_log.css", os.path.dirname(fn))
Expand All @@ -99,17 +98,13 @@ def _escape(self, data):
data = "".join((c in self._nonprint) and ("%%%02x" % ord(c)) or
c for c in data)
data = cgi.escape(data)
data = data.replace(" ", "&nbsp;")
self.linebreak = data[-1:-1] == "\n"
data = data.replace(chr(10), "<br/>\n")
return data

def _terminate_stream(self):
self.cur_evt += 1
if not self.last_stream:
return
if not self.linebreak:
self.f.write("<br/>\n")
self.f.write("</pre>\n")
self.f.write("<div class=\"stream-trailer\" id=\"" +
self.last_stream.name + "\">End stream: " +
self.last_stream.name + "</div>\n")
Expand All @@ -120,9 +115,8 @@ def _note(self, note_type, msg):
self._terminate_stream()
self.f.write("<div class=\"" + note_type + "\">\n")
self.f.write(self._escape(msg))
self.f.write("<br/>\n")
self.f.write("\n")
self.f.write("</div>\n")
self.linebreak = True

def start_section(self, marker):
self._terminate_stream()
Expand Down Expand Up @@ -173,7 +167,7 @@ def get_stream(self, name, chained_file=None):
def get_runner(self, name, chained_file=None):
return RunAndLog(self, name, chained_file)

_nonprint = ("^%" + "".join(chr(c) for c in range(0, 32) if c != 10) +
_nonprint = ("^%" + "".join(chr(c) for c in range(0, 32) if c not in (9, 10)) +
"".join(chr(c) for c in range(127, 256)))

def write(self, stream, data, implicit=False):
Expand All @@ -182,6 +176,7 @@ def write(self, stream, data, implicit=False):
self.f.write("<div class=\"stream\" id=\"%s\">\n" % stream.name)
self.f.write("<div class=\"stream-header\" id=\"" + stream.name +
"\">Stream: " + stream.name + "</div>\n")
self.f.write("<pre>")
if implicit:
self.f.write("<span class=\"implicit\">")
self.f.write(self._escape(data))
Expand Down

0 comments on commit ee09f5d

Please sign in to comment.