~ubuntu-branches/ubuntu/natty/moin/natty-updates

« back to all changes in this revision

Viewing changes to MoinMoin/parser/text_irssi.py

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-06-22 21:17:13 UTC
  • mfrom: (0.9.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080622211713-fpo2zrq3s5dfecxg
Tags: 1.7.0-3
Simplify /etc/moin/wikilist format: "USER URL" (drop unneeded middle
CONFIG_DIR that was wrongly advertised as DATA_DIR).  Make
moin-mass-migrate handle both formats and warn about deprecation of
the old one.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: iso-8859-1 -*-
 
2
"""
 
3
    MoinMoin - IRC Log Parser (irssi style logs)
 
4
 
 
5
    @copyright: 2004 Thomas Waldmann,
 
6
                2006 Georg Brandl (support for /actions)
 
7
    @license: GNU GPL, see COPYING for details.
 
8
"""
 
9
 
 
10
import re
 
11
 
 
12
Dependencies = []
 
13
 
 
14
class Parser:
 
15
    """
 
16
        Send IRC logs in a table
 
17
    """
 
18
    extensions = ['.irc']
 
19
    Dependencies = []
 
20
 
 
21
    def __init__(self, raw, request, **kw):
 
22
        self.raw = raw
 
23
        self.request = request
 
24
        self.form = request.form
 
25
        self._ = request.getText
 
26
        self.out = kw.get('out', request)
 
27
 
 
28
    def format(self, formatter):
 
29
        fmt = formatter
 
30
        lines = self.raw.split('\n')
 
31
        # TODO: Add support for displaying things like join and part messages.
 
32
        timestamp = r"""
 
33
            ((\[|\()?                      # Opening bracket or paren for the timestamp (if it exists)
 
34
                (?P<time>                  # Timestamp
 
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)
 
38
                )
 
39
            (\]|\))?\s+)?                  # Closing bracket or paren for the timestamp (if it exists) plus whitespace
 
40
        """
 
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
 
44
            (?P<msg>.*)                    # 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
 
49
            \s+                            # Space
 
50
            (?P<msg>.*)                    # Message
 
51
        """, re.VERBOSE | re.UNICODE)
 
52
 
 
53
        tbl_style = 'vertical-align:top;'
 
54
        write = self.out.write
 
55
 
 
56
        def write_tbl_cell(text, code=1, add_style=''):
 
57
            write(fmt.table_cell(1, style=tbl_style+add_style))
 
58
            if code:
 
59
                write(fmt.code(1))
 
60
            write(text)
 
61
            if code:
 
62
                write(fmt.code(0))
 
63
            write(fmt.table_cell(0))
 
64
 
 
65
        write(fmt.table(1))
 
66
        for line in lines:
 
67
            # maybe it's a standard line
 
68
            match = std_pattern.match(line)
 
69
            if match:
 
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)
 
78
            if match:
 
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))
 
89
        write(fmt.table(0))
 
90