diff options
author | Richard Darst <rkd@zgib.net> | 2009-09-02 15:40:53 (GMT) |
---|---|---|
committer | Richard Darst <rkd@zgib.net> | 2009-09-02 15:40:53 (GMT) |
commit | 27ce4735fbcf66a7db9735019f64634f122c3cb9 (patch) | |
tree | 36e59e13fd9ed4f4c2a9bc9a33d4febba8072c6a /writers.py | |
parent | ca03606ac10fb800fe93e84780682da36d261583 (diff) |
Add a self-done HTMLlog writer
- This writer does the exact same thing as the current one, but has
a custom parsing and writing. This means that it can be more easily
customized eventually
darcs-hash:20090902154053-82ea9-0aff7cbc7df35234846cc5abc5a968ebd2ba6ee9.gz
Diffstat (limited to 'writers.py')
-rw-r--r-- | writers.py | 102 |
1 files changed, 102 insertions, 0 deletions
@@ -184,6 +184,108 @@ class HTMLlog(_BaseWriter): out, count=1) return out +class HTMLlog2(_BaseWriter): + def format(self, extension=None): + """Write pretty HTML logs.""" + M = self.M + lines = [ ] + line_re = re.compile(r"""\s* + (?P<time> \[?[0-9:\s]*\]?)\s* + (?P<nick>\s+<[@+\s]?[^>]+>)\s* + (?P<line>.*) + """, re.VERBOSE) + action_re = re.compile(r"""\s* + (?P<time> \[?[0-9:\s]*\]?)\s* + (?P<nick>\*\s+[@+\s]?[^\s]+)\s* + (?P<line>.*) + """,re.VERBOSE) + command_re = re.compile(r"(#[^\s]+[ \t\f\v]*)(.*)") + command_topic_re = re.compile(r"(#topic[ \t\f\v]*)(.*)") + hilight_re = re.compile(r"([^\s]+:)( .*)") + lineNumber = 0 + for l in M.lines: + lineNumber += 1 # starts from 1 + # is it a regular line? + m = line_re.match(l) + if m is not None: + line = m.group('line') + # Match #topic + m2 = command_topic_re.match(line) + if m2 is not None: + outline = ('<span class="topic">%s</span>' + '<span class="topicline">%s</span>'% + (html(m2.group(1)),html(m2.group(2)))) + # Match other #commands + if m2 is None: + m2 = command_re.match(line) + if m2 is not None: + outline = ('<span class="cmd">%s</span>' + '<span class="cmdline">%s</span>'% + (html(m2.group(1)),html(m2.group(2)))) + # match hilights + if m2 is None: + m2 = hilight_re.match(line) + if m2 is not None: + outline = ('<span class="hi">%s</span>' + '%s'% + (html(m2.group(1)),html(m2.group(2)))) + if m2 is None: + outline = html(line) + lines.append('<a name="l-%(lineno)s"></a>' + '<span class="tm">%(time)s</span>' + '<span class="nk">%(nick)s</span> ' + '%(line)s'%{'lineno':lineNumber, + 'time':html(m.group('time')), + 'nick':html(m.group('nick')), + 'line':outline,}) + continue + m = action_re.match(l) + # is it a action line? + if m is not None: + lines.append('<a name="l-%(lineno)s"></a>' + '<span class="tm">%(time)s</span>' + '<span class="nka">%(nick)s</span> ' + '<span class="ac">%(line)s</span>'% + {'lineno':lineNumber, + 'time':html(m.group('time')), + 'nick':html(m.group('nick')), + 'line':html(m.group('line')),}) + continue + print l + print m.groups() + print "**error**", l + + css = textwrap.dedent('''\ + pre { /*line-height: 125%;*/ + white-space: pre-wrap; } + body { background: #f0f0f0; } + + body .tm { color: #007020 } /* time */ + body .nk { color: #062873; font-weight: bold } /* nick, regular */ + body .nka { color: #007020; font-weight: bold } /* action nick */ + body .ac { color: #00A000 } /* action line */ + body .hi { color: #4070a0 } /* hilights */ + + /* Things to make particular MeetBot commands stick out */ + body .topic { color: #007020; font-weight: bold } + body .topicline { color: #000080; font-weight: bold } + body .cmd { color: #007020; font-weight: bold } + body .cmdline { font-weight: bold } + ''') + css_head = textwrap.dedent('''\ + <style type="text/css"> + %s + </style> + ''') + return html_template%{'pageTitle':"%s log"%html(M.channel), + #'body':"<br>\n".join(lines), + 'body':"<pre>"+("\n".join(lines))+"</pre>", + 'headExtra':css_head%css, + } +HTMLlog = HTMLlog2 + + + html_template = textwrap.dedent('''\ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> |