1
# -*- coding: iso-8859-1 -*-
3
MoinMoin - IRC Log Parser (irssi style logs)
5
@copyright: 2004 Thomas Waldmann,
6
2006 Georg Brandl (support for /actions)
7
@license: GNU GPL, see COPYING for details.
16
Send IRC logs in a table
21
def __init__(self, raw, request, **kw):
23
self.request = request
24
self.form = request.form
25
self._ = request.getText
26
self.out = kw.get('out', request)
28
def format(self, formatter):
30
lines = self.raw.split('\n')
31
# TODO: Add support for displaying things like join and part messages.
33
((\[|\()? # Opening bracket or paren for the timestamp (if it exists)
35
((\d{1,4} [-/]?)+ # Date as one or more - or /-separated groups of digits (if it exists)
36
[T ])? # Date/time separator: T or space
37
(\d?\d [:.]?)+ # Time as one or more :/.-separated groups of 1 or 2 digits (if it exists)
39
(\]|\))?\s+)? # Closing bracket or paren for the timestamp (if it exists) plus whitespace
41
std_pattern = re.compile(timestamp + r"""
42
\s*<\s*?(?P<nick>.*?)\s*?> # Nick, maybe preceeded by whitespace, which will apply only if no timestamp
43
\s+ # Space between the nick and message
45
""", re.VERBOSE | re.UNICODE)
46
act_pattern = re.compile(timestamp + r"""
47
\s*(?P<stars>[*]{1,3}|-!-)\s* # Star(s)
48
(?P<nick>[^\s]+) # Nick
51
""", re.VERBOSE | re.UNICODE)
53
tbl_style = 'vertical-align:top;'
54
write = self.out.write
56
def write_tbl_cell(text, code=1, add_style=''):
57
write(fmt.table_cell(1, style=tbl_style+add_style))
63
write(fmt.table_cell(0))
67
# maybe it's a standard line
68
match = std_pattern.match(line)
70
write(fmt.table_row(1))
71
write_tbl_cell(fmt.text(match.group('time') or ''))
72
write_tbl_cell(fmt.text(match.group('nick') or ''),
73
add_style='text-align:right; font-weight:bold')
74
write_tbl_cell(fmt.text(match.group('msg') or ''), code=0)
75
write(fmt.table_row(0))
76
# maybe it's an ACTION
77
match = act_pattern.match(line)
79
write(fmt.table_row(1))
80
write_tbl_cell(fmt.text(match.group('time') or ''))
81
write_tbl_cell(fmt.text(match.group('stars') or ''),
82
add_style='text-align:right')
83
write_tbl_cell(fmt.emphasis(1) + fmt.code(1) + fmt.strong(1) +
84
fmt.text(match.group('nick') or '') +
85
fmt.strong(0) + fmt.code(0) +
86
fmt.text(' ' + match.group('msg')) +
87
fmt.emphasis(0), code=0)
88
write(fmt.table_row(0))