changeset 1633:c62b1d1961da

merged main
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 22 Oct 2006 00:31:27 +0200
parents f89736ab2c8e (current diff) 1c28e0ea4fd0 (diff)
children 2161d292e1af
files docs/CHANGES
diffstat 2 files changed, 52 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/parser/text_irssi.py	Sun Oct 22 00:29:13 2006 +0200
+++ b/MoinMoin/parser/text_irssi.py	Sun Oct 22 00:31:27 2006 +0200
@@ -3,6 +3,7 @@
     MoinMoin - IRC Log Parser (irssi style logs)
 
     @copyright: 2004 by Thomas Waldmann
+    @copyright: 2006 by Georg Brandl (support for /actions)
     @license: GNU GPL, see COPYING for details.
 """
 
@@ -26,25 +27,63 @@
         self.out = kw.get('out', request)
 
     def format(self, formatter):
+        fmt = formatter
         lines = self.raw.split('\n')
         # TODO: Add support for displaying things like join and part messages.
-        pattern = re.compile(r"""
+        timestamp = r"""
             ((\[|\()?                      # Opening bracket or paren for the timestamp (if it exists)
-                (?P<time>([\d]?\d[:.]?)+)  # Timestamp as one or more :/.-separated groups of 1 or 2 digits (if it exists)
+                (?P<time>                  # Timestamp
+                    ((\d{1,4} [-/]?)+      # Date as one or more - or /-separated groups of digits (if it exists)
+                     [T ])?                # Date/time separator: T or space
+                    (\d?\d [:.]?)+         # Time as one or more :/.-separated groups of 1 or 2 digits (if it exists)
+                )  
             (\]|\))?\s+)?                  # Closing bracket or paren for the timestamp (if it exists) plus whitespace
+        """
+        std_pattern = re.compile(timestamp + r"""
             \s*<\s*?(?P<nick>.*?)\s*?>     # Nick, maybe preceeded by whitespace, which will apply only if no timestamp
             \s+                            # Space between the nick and message
             (?P<msg>.*)                    # Message
-        """, re.VERBOSE + re.UNICODE)
-        self.out.write(formatter.table(1))
+        """, re.VERBOSE | re.UNICODE)
+        act_pattern = re.compile(timestamp + r"""
+            \s*(?P<stars>[*]{1,3}|-!-)\s*  # Star(s)
+            (?P<nick>[^\s]+)               # Nick
+            \s+                            # Space
+            (?P<msg>.*)                    # Message
+        """, re.VERBOSE | re.UNICODE)
+
+        tbl_style = 'vertical-align:top;'
+        write = self.out.write
+
+        def write_tbl_cell(text, code=1, add_style=''):
+            write(fmt.table_cell(1, style=tbl_style+add_style))
+            if code: write(fmt.code(1))
+            write(text)
+            if code: write(fmt.code(0))
+            write(fmt.table_cell(0))
+          
+        write(fmt.table(1))
         for line in lines:
-            match = pattern.match(line)
+            # maybe it's a standard line
+            match = std_pattern.match(line)
             if match:
-                self.out.write(formatter.table_row(1))
-                for g in ('time', 'nick', 'msg'):
-                    self.out.write(formatter.table_cell(1))
-                    self.out.write(formatter.text(match.group(g) or ''))
-                    self.out.write(formatter.table_cell(0))
-                self.out.write(formatter.table_row(0))
-        self.out.write(formatter.table(0))
+                write(fmt.table_row(1))
+                write_tbl_cell(fmt.text(match.group('time') or ''))
+                write_tbl_cell(fmt.text(match.group('nick') or ''),
+                               add_style='text-align:right; font-weight:bold')
+                write_tbl_cell(fmt.text(match.group('msg') or ''), code=0)
+                write(fmt.table_row(0))
+            # maybe it's an ACTION
+            match = act_pattern.match(line)
+            if match:
+                write(fmt.table_row(1))
+                write_tbl_cell(fmt.text(match.group('time') or ''))
+                write_tbl_cell(fmt.text(match.group('stars') or ''),
+                               add_style='text-align:right')
+                write_tbl_cell(fmt.emphasis(1) + fmt.code(1) + fmt.strong(1) +
+                               fmt.text(match.group('nick') or '') +
+                               fmt.strong(0) + fmt.code(0) +
+                               fmt.text(' ' + match.group('msg')) +
+                               fmt.emphasis(0), code=0)
+                write(fmt.table_row(0))
+        write(fmt.table(0))
 
--- a/docs/CHANGES	Sun Oct 22 00:29:13 2006 +0200
+++ b/docs/CHANGES	Sun Oct 22 00:31:27 2006 +0200
@@ -243,6 +243,7 @@
       "this page has own (empty) ACLs, so do not use acl_rights_default here"
       Please note that this is COMPLETELY DIFFERENT from having no ACL line at
       all on the page (acl_rights_default is used in that case).
+    * Added support for actions in the irssi parser. Thanks to Georg Brandl.
 
 
   Bugfixes: