# HG changeset patch # User Tero Marttila # Date 1234308082 -7200 # Node ID 74f6a0b01ddfd323dad9ce244485bf09c98b4df6 # Parent df2a6780cdf993cf8757b3747f5e9d3884674559 change debug formatter to to use str(LogLine) for TSV, and fix handling of topic-unset diff -r df2a6780cdf9 -r 74f6a0b01ddf log_formatter.py --- a/log_formatter.py Wed Feb 11 01:00:18 2009 +0200 +++ b/log_formatter.py Wed Feb 11 01:21:22 2009 +0200 @@ -35,13 +35,19 @@ self.img_ttf_path = img_ttf_path self.img_font_size = img_font_size - def _format_line_text (self, line, template_dict, full_timestamp=False) : + def _format_line_text (self, line, template_dict, type=None, full_timestamp=False) : """ - Format the given line as text, using the given { type: string template } dict + Format the given line as text, using the given { type: string template } dict. + + If type is given, then it overrides line.type """ + + # default type? + if type is None : + type = line.type # look up the template - template = template_dict[line.type] + template = template_dict[type] # convert timestamp into display timezone dtz = line.timestamp.astimezone(self.tz) @@ -173,6 +179,7 @@ LogTypes.QUIT : "%(timestamp)s -!- %(source_nickname)s [%(source_username)s@%(source_hostname)s] has quit [%(message)s]", LogTypes.TOPIC : "%(timestamp)s -!- %(source_nickname)s changed the topic of %(channel_name)s to: %(message)s", + 'TOPIC_UNSET' : "%(timestamp)s -!- Topic unset by %(source_nickname)s on %(channel_name)s", LogTypes.SELF_NOTICE: "%(timestamp)s -%(source_nickname)s- %(message)s", LogTypes.SELF_NICK : "%(timestamp)s -!- %(source_nickname)s is now known as %(target_nickname)s", @@ -181,8 +188,15 @@ def format_txt (self, lines, full_timestamps=False) : # ...handle each line for line in lines : + # specialcases + if line.type == LogTypes.TOPIC and line.data is None : + type = 'TOPIC_UNSET' + + else : + type = line.type + # using __TYPES - yield line, self._format_line_text(line, self.__FMT, full_timestamps) + yield line, self._format_line_text(line, self.__FMT, type, full_timestamps) class IrssiFormatter (BaseHTMLFormatter, IrssiTextFormatter) : """ @@ -206,7 +220,7 @@ # iterate for line in lines : # just dump - yield line, repr(line) + yield line, str(line) def by_name (name) : """ diff -r df2a6780cdf9 -r 74f6a0b01ddf log_line.py --- a/log_line.py Wed Feb 11 01:00:18 2009 +0200 +++ b/log_line.py Wed Feb 11 01:21:22 2009 +0200 @@ -41,41 +41,45 @@ ('LOG_CLOSE', 0x03), ## messages - # normal message + # sent message to ('MSG', 0x10), - # notice + # sent notice with message to ('NOTICE', 0x11), - # CTCP action + # sent CTCP action with message to ('ACTION', 0x12), ## user-channel stats - # join + # joined ('JOIN', 0x21), - # part + # left with message ('PART', 0x22), - # kick + # kicked from with message ('KICK', 0x25), - # channel modes + # changed modes on with modestring ('MODE', 0x26), ## user status - # nick-change + # changed nickname to ('NICK', 0x31), - # quit + # quit the network with quit-message ('QUIT', 0x32), ## general channel status - # topic changed + # changed the topic of to + # data may be None if the topic was unset ('TOPIC', 0x41), ## our own actions + # we () sent a notice with message to ('SELF_NOTICE', 0x51), + + # we () changed nickname to ('SELF_NICK', 0x52), ] @@ -108,10 +112,10 @@ # the UTC timestamp of the event timestamp = None - # the event source, this should be a + # the source, this should be a (nickname, username, hostname, chanflags) tuple source = None - # possible event target, for certain types (kick, nick) + # possible target nickname for certain types (kick, nick) target = None # associated data (message, etc) @@ -139,7 +143,9 @@ def format_source (self) : """ - Formats source as [][][!][@], omitting those parts that are missing + Formats source as [][][!][@], omitting those parts that are missing. + + If all parts are None, this returns the empty string """ nick, user, host, flags = self.source @@ -150,6 +156,17 @@ '!' + user if user else '', '@' + host if host else '' ) + + def __str__ (self) : + return '\t'.join(( + self.channel.name, + str(self.offset), + self.format_type(), + str(self.timestamp), + self.format_source(), + str(self.target), + str(self.data) + )) def __repr__ (self) : return "LogLine(%r, %s, %-12s, %s, %-35s, %-10s, %r)" % ( diff -r df2a6780cdf9 -r 74f6a0b01ddf log_parser.py --- a/log_parser.py Wed Feb 11 01:00:18 2009 +0200 +++ b/log_parser.py Wed Feb 11 01:21:22 2009 +0200 @@ -51,7 +51,9 @@ _TS = r'(?P\S+)' _NICK = r'(?P.+?)' _NICK2 = r'(?P.+?)' + _TARGET = r'(?P.+?)' _CHAN = r'(?P.+?)' + _CHAN2 = r'(?P.+?)' _USERHOST = r'(?P.*?)@(?P.*?)' _MSG = r'(?P.*)' @@ -64,14 +66,14 @@ ( LogTypes.ACTION, _TS + r' \* ' + _NICK + ' ' + _MSG ), ( LogTypes.JOIN, _TS + r' -!- ' + _NICK + ' \[' + _USERHOST + '\] has joined ' + _CHAN ), ( LogTypes.PART, _TS + r' -!- ' + _NICK + ' \[' + _USERHOST + '\] has left ' + _CHAN + ' \[(?P.*?)\]' ), - ( LogTypes.KICK, _TS + r' -!- ' + _NICK2 + ' was kicked from ' + _CHAN + ' by ' + _NICK + ' \[(?P.*?)\]' ), + ( LogTypes.KICK, _TS + r' -!- ' + _TARGET + ' was kicked from ' + _CHAN + ' by ' + _NICK + ' \[(?P.*?)\]' ), ( LogTypes.MODE, _TS + r' -!- mode/' + _CHAN + ' \[(?P.+?)\] by (?P\S+)' ), - ( LogTypes.NICK, _TS + r' -!- ' + _NICK + ' is now known as (?P\S+)' ), + ( LogTypes.NICK, _TS + r' -!- ' + _NICK + ' is now known as (?P\S+)' ), ( LogTypes.QUIT, _TS + r' -!- ' + _NICK + ' \[' + _USERHOST + '\] has quit \[(?P.*?)\]' ), - ( LogTypes.TOPIC, _TS + r' -!- ' + _NICK + ' changed the topic of ' + _CHAN + ' to: (?P.*)' ), + ( LogTypes.TOPIC, _TS + r' -!- (' + _NICK + ' changed the topic of ' + _CHAN + ' to: (?P.*)|Topic unset by ' + _NICK2 + ' on ' + _CHAN2 + ')' ), ( LogTypes.SELF_NOTICE, _TS + r' \[notice\(' + _CHAN + '\)\] ' + _MSG ), - ( LogTypes.SELF_NICK, _TS + r' -!- You\'re now known as (?P\S+)' ), + ( LogTypes.SELF_NICK, _TS + r' -!- You\'re now known as (?P\S+)' ), ) # precompile @@ -127,11 +129,14 @@ # now localize with timezone dtz = self.tz.localize(dt) + # channel, currently unused + channel_name = (groups.get('channel') or groups.get('channel2')) + # source - source = (groups.get('nickname'), groups.get('username'), groups.get('hostname'), groups.get('flags')) + source = (groups.get('nickname') or groups.get('nickname2'), groups.get('username'), groups.get('hostname'), groups.get('flags')) # target - target = groups.get('nickname2') + target = groups.get('target') # data if 'message' in groups : diff -r df2a6780cdf9 -r 74f6a0b01ddf templates/preferences.tmpl --- a/templates/preferences.tmpl Wed Feb 11 01:00:18 2009 +0200 +++ b/templates/preferences.tmpl Wed Feb 11 01:21:22 2009 +0200 @@ -34,7 +34,7 @@