log_line.py
author Tero Marttila <terom@fixme.fi>
Wed, 11 Feb 2009 01:21:22 +0200
changeset 92 74f6a0b01ddf
parent 91 df2a6780cdf9
child 97 6165f1ba458d
permissions -rw-r--r--
change debug formatter to to use str(LogLine) for TSV, and fix handling of topic-unset
41
9585441a4bfb working basic logs stuff
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     1
"""
50
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
     2
    An IRC logfile consists of a series of lines/events
41
9585441a4bfb working basic logs stuff
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     3
"""
9585441a4bfb working basic logs stuff
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     4
50
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
     5
class LogTypes :
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
     6
    """
86
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
     7
        Definitions of the various LogLines types:
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
     8
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
     9
            LogTypes.RAW
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    10
            LogTypes.LOG_OPEN
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    11
            LogTypes.LOG_CLOSE
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    12
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    13
            LogTypes.MSG
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    14
            LogTypes.NOTICE
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    15
            LogTypes.ACTION
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    16
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    17
            LogTypes.JOIN
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    18
            LogTypes.PART
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    19
            LogTypes.KICK
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    20
            LogTypes.MODE
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    21
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    22
            LogTypes.NICK
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    23
            LogTypes.QUIT
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    24
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    25
            LogTypes.TOPIC
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    26
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    27
            LogTypes.SELF_NOTICE
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    28
            LogTypes.SELF_NICK
50
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
    29
    """
86
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    30
 
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    31
    # list of LogType values by name
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    32
    LIST = [
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    33
        ## special
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    34
        # unknown type, may or may not have a timestamp, no source, only data
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    35
        ('RAW',         0x01),
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    36
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    37
        # log opened
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    38
        ('LOG_OPEN',    0x02),
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    39
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    40
        # log closed
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    41
        ('LOG_CLOSE',   0x03),
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    42
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    43
        ## messages
92
74f6a0b01ddf change debug formatter to to use str(LogLine) for TSV, and fix handling of topic-unset
Tero Marttila <terom@fixme.fi>
parents: 91
diff changeset
    44
        # <source> sent message <data> to <channel>
86
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    45
        ('MSG',         0x10),
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    46
        
92
74f6a0b01ddf change debug formatter to to use str(LogLine) for TSV, and fix handling of topic-unset
Tero Marttila <terom@fixme.fi>
parents: 91
diff changeset
    47
        # <source> sent notice with message <data> to <channel>
86
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    48
        ('NOTICE',      0x11),
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    49
92
74f6a0b01ddf change debug formatter to to use str(LogLine) for TSV, and fix handling of topic-unset
Tero Marttila <terom@fixme.fi>
parents: 91
diff changeset
    50
        # <source> sent CTCP action with message <data> to <channel>
86
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    51
        ('ACTION',      0x12),
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    52
        
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    53
        ## user-channel stats
92
74f6a0b01ddf change debug formatter to to use str(LogLine) for TSV, and fix handling of topic-unset
Tero Marttila <terom@fixme.fi>
parents: 91
diff changeset
    54
        # <source> joined <channel>
86
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    55
        ('JOIN',        0x21),
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    56
92
74f6a0b01ddf change debug formatter to to use str(LogLine) for TSV, and fix handling of topic-unset
Tero Marttila <terom@fixme.fi>
parents: 91
diff changeset
    57
        # <source> left <channel> with message <data>
86
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    58
        ('PART',        0x22),
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    59
92
74f6a0b01ddf change debug formatter to to use str(LogLine) for TSV, and fix handling of topic-unset
Tero Marttila <terom@fixme.fi>
parents: 91
diff changeset
    60
        # <source> kicked <target> from <channel> with message <data>
86
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    61
        ('KICK',        0x25),
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    62
     
92
74f6a0b01ddf change debug formatter to to use str(LogLine) for TSV, and fix handling of topic-unset
Tero Marttila <terom@fixme.fi>
parents: 91
diff changeset
    63
        # <source> changed modes on <channel> with modestring <data>
86
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    64
        ('MODE',        0x26),
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    65
        
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    66
        ## user status
92
74f6a0b01ddf change debug formatter to to use str(LogLine) for TSV, and fix handling of topic-unset
Tero Marttila <terom@fixme.fi>
parents: 91
diff changeset
    67
        # <source> changed nickname to <target>
86
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    68
        ('NICK',        0x31),
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    69
92
74f6a0b01ddf change debug formatter to to use str(LogLine) for TSV, and fix handling of topic-unset
Tero Marttila <terom@fixme.fi>
parents: 91
diff changeset
    70
        # <source> quit the network with quit-message <data>
86
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    71
        ('QUIT',        0x32),
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    72
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    73
        ## general channel status
92
74f6a0b01ddf change debug formatter to to use str(LogLine) for TSV, and fix handling of topic-unset
Tero Marttila <terom@fixme.fi>
parents: 91
diff changeset
    74
        # <source> changed the topic of <channel> to <data>
74f6a0b01ddf change debug formatter to to use str(LogLine) for TSV, and fix handling of topic-unset
Tero Marttila <terom@fixme.fi>
parents: 91
diff changeset
    75
        # data may be None if the topic was unset
86
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    76
        ('TOPIC',       0x41),
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    77
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    78
        ## our own actions
92
74f6a0b01ddf change debug formatter to to use str(LogLine) for TSV, and fix handling of topic-unset
Tero Marttila <terom@fixme.fi>
parents: 91
diff changeset
    79
        # we (<source>) sent a notice with message <data> to <channel>
86
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    80
        ('SELF_NOTICE', 0x51),
92
74f6a0b01ddf change debug formatter to to use str(LogLine) for TSV, and fix handling of topic-unset
Tero Marttila <terom@fixme.fi>
parents: 91
diff changeset
    81
74f6a0b01ddf change debug formatter to to use str(LogLine) for TSV, and fix handling of topic-unset
Tero Marttila <terom@fixme.fi>
parents: 91
diff changeset
    82
        # we (<source>) changed nickname to <target>
86
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    83
        ('SELF_NICK',   0x52),
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    84
    ]
50
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
    85
    
86
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    86
    @classmethod
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    87
    def name_from_code (cls, code) :
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    88
        """
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    89
            Looks up a LogType name by code
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    90
        """
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    91
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    92
        return dict((type, name) for name, type in cls.LIST)[code]
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    93
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    94
# apply as attributes
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    95
for name, code in LogTypes.LIST :
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
    96
    setattr(LogTypes, name, code)
50
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
    97
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
    98
class LogLine (object) :
41
9585441a4bfb working basic logs stuff
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    99
    """
9585441a4bfb working basic logs stuff
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   100
        An event on some specific channel
9585441a4bfb working basic logs stuff
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   101
    """
9585441a4bfb working basic logs stuff
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   102
86
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
   103
    # the LogChannel
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
   104
    channel = None
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
   105
64
cdb6403c2498 beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents: 50
diff changeset
   106
    # the offset, only garunteed to be unique for a specific channel and date
cdb6403c2498 beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents: 50
diff changeset
   107
    offset = None
cdb6403c2498 beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents: 50
diff changeset
   108
50
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
   109
    # the event type, as defiend in LogTypes
41
9585441a4bfb working basic logs stuff
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   110
    type = None
9585441a4bfb working basic logs stuff
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   111
9585441a4bfb working basic logs stuff
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   112
    # the UTC timestamp of the event
9585441a4bfb working basic logs stuff
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   113
    timestamp = None
9585441a4bfb working basic logs stuff
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   114
92
74f6a0b01ddf change debug formatter to to use str(LogLine) for TSV, and fix handling of topic-unset
Tero Marttila <terom@fixme.fi>
parents: 91
diff changeset
   115
    # the source, this should be a (nickname, username, hostname, chanflags) tuple
41
9585441a4bfb working basic logs stuff
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   116
    source = None
9585441a4bfb working basic logs stuff
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   117
92
74f6a0b01ddf change debug formatter to to use str(LogLine) for TSV, and fix handling of topic-unset
Tero Marttila <terom@fixme.fi>
parents: 91
diff changeset
   118
    # possible target nickname for certain types (kick, nick)
86
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
   119
    target = None
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
   120
41
9585441a4bfb working basic logs stuff
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   121
    # associated data (message, etc)
9585441a4bfb working basic logs stuff
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   122
    data = None
50
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
   123
    
86
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
   124
    def __init__ (self, channel, offset, type, timestamp, source, target, data) :
50
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
   125
        """
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
   126
            Initialize with given values
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
   127
        """
64
cdb6403c2498 beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents: 50
diff changeset
   128
        
86
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
   129
        self.channel = channel
64
cdb6403c2498 beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents: 50
diff changeset
   130
        self.offset = offset
50
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
   131
        self.type = type
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
   132
        self.timestamp = timestamp
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
   133
        self.source = source
86
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
   134
        self.target = target
50
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
   135
        self.data = data
86
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
   136
    
90
275a675712f1 clean up repr(LogLine) output
Tero Marttila <terom@fixme.fi>
parents: 86
diff changeset
   137
    def format_type (self) :
275a675712f1 clean up repr(LogLine) output
Tero Marttila <terom@fixme.fi>
parents: 86
diff changeset
   138
        """
275a675712f1 clean up repr(LogLine) output
Tero Marttila <terom@fixme.fi>
parents: 86
diff changeset
   139
            Formats type as a string code
275a675712f1 clean up repr(LogLine) output
Tero Marttila <terom@fixme.fi>
parents: 86
diff changeset
   140
        """
275a675712f1 clean up repr(LogLine) output
Tero Marttila <terom@fixme.fi>
parents: 86
diff changeset
   141
275a675712f1 clean up repr(LogLine) output
Tero Marttila <terom@fixme.fi>
parents: 86
diff changeset
   142
        return LogTypes.name_from_code(self.type)
275a675712f1 clean up repr(LogLine) output
Tero Marttila <terom@fixme.fi>
parents: 86
diff changeset
   143
275a675712f1 clean up repr(LogLine) output
Tero Marttila <terom@fixme.fi>
parents: 86
diff changeset
   144
    def format_source (self) :
275a675712f1 clean up repr(LogLine) output
Tero Marttila <terom@fixme.fi>
parents: 86
diff changeset
   145
        """
92
74f6a0b01ddf change debug formatter to to use str(LogLine) for TSV, and fix handling of topic-unset
Tero Marttila <terom@fixme.fi>
parents: 91
diff changeset
   146
            Formats source as [<chanflags>][<nickname>][!<username>][@<hostname>], omitting those parts that are missing.
74f6a0b01ddf change debug formatter to to use str(LogLine) for TSV, and fix handling of topic-unset
Tero Marttila <terom@fixme.fi>
parents: 91
diff changeset
   147
74f6a0b01ddf change debug formatter to to use str(LogLine) for TSV, and fix handling of topic-unset
Tero Marttila <terom@fixme.fi>
parents: 91
diff changeset
   148
            If all parts are None, this returns the empty string
90
275a675712f1 clean up repr(LogLine) output
Tero Marttila <terom@fixme.fi>
parents: 86
diff changeset
   149
        """
275a675712f1 clean up repr(LogLine) output
Tero Marttila <terom@fixme.fi>
parents: 86
diff changeset
   150
275a675712f1 clean up repr(LogLine) output
Tero Marttila <terom@fixme.fi>
parents: 86
diff changeset
   151
        nick, user, host, flags = self.source
275a675712f1 clean up repr(LogLine) output
Tero Marttila <terom@fixme.fi>
parents: 86
diff changeset
   152
275a675712f1 clean up repr(LogLine) output
Tero Marttila <terom@fixme.fi>
parents: 86
diff changeset
   153
        return "%s%s%s%s" % (
91
df2a6780cdf9 make LogLine.format_source slightly less misleading
Tero Marttila <terom@fixme.fi>
parents: 90
diff changeset
   154
            flags if flags and flags != ' ' else '',
90
275a675712f1 clean up repr(LogLine) output
Tero Marttila <terom@fixme.fi>
parents: 86
diff changeset
   155
            nick if nick else '',
275a675712f1 clean up repr(LogLine) output
Tero Marttila <terom@fixme.fi>
parents: 86
diff changeset
   156
            '!' + user if user else '',
275a675712f1 clean up repr(LogLine) output
Tero Marttila <terom@fixme.fi>
parents: 86
diff changeset
   157
            '@' + host if host else ''
86
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 64
diff changeset
   158
        )
92
74f6a0b01ddf change debug formatter to to use str(LogLine) for TSV, and fix handling of topic-unset
Tero Marttila <terom@fixme.fi>
parents: 91
diff changeset
   159
   
74f6a0b01ddf change debug formatter to to use str(LogLine) for TSV, and fix handling of topic-unset
Tero Marttila <terom@fixme.fi>
parents: 91
diff changeset
   160
    def __str__ (self) :
74f6a0b01ddf change debug formatter to to use str(LogLine) for TSV, and fix handling of topic-unset
Tero Marttila <terom@fixme.fi>
parents: 91
diff changeset
   161
        return '\t'.join((
74f6a0b01ddf change debug formatter to to use str(LogLine) for TSV, and fix handling of topic-unset
Tero Marttila <terom@fixme.fi>
parents: 91
diff changeset
   162
            self.channel.name,
74f6a0b01ddf change debug formatter to to use str(LogLine) for TSV, and fix handling of topic-unset
Tero Marttila <terom@fixme.fi>
parents: 91
diff changeset
   163
            str(self.offset),
74f6a0b01ddf change debug formatter to to use str(LogLine) for TSV, and fix handling of topic-unset
Tero Marttila <terom@fixme.fi>
parents: 91
diff changeset
   164
            self.format_type(),
74f6a0b01ddf change debug formatter to to use str(LogLine) for TSV, and fix handling of topic-unset
Tero Marttila <terom@fixme.fi>
parents: 91
diff changeset
   165
            str(self.timestamp),
74f6a0b01ddf change debug formatter to to use str(LogLine) for TSV, and fix handling of topic-unset
Tero Marttila <terom@fixme.fi>
parents: 91
diff changeset
   166
            self.format_source(),
74f6a0b01ddf change debug formatter to to use str(LogLine) for TSV, and fix handling of topic-unset
Tero Marttila <terom@fixme.fi>
parents: 91
diff changeset
   167
            str(self.target),
74f6a0b01ddf change debug formatter to to use str(LogLine) for TSV, and fix handling of topic-unset
Tero Marttila <terom@fixme.fi>
parents: 91
diff changeset
   168
            str(self.data)
74f6a0b01ddf change debug formatter to to use str(LogLine) for TSV, and fix handling of topic-unset
Tero Marttila <terom@fixme.fi>
parents: 91
diff changeset
   169
        ))
50
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
   170
90
275a675712f1 clean up repr(LogLine) output
Tero Marttila <terom@fixme.fi>
parents: 86
diff changeset
   171
    def __repr__ (self) :
275a675712f1 clean up repr(LogLine) output
Tero Marttila <terom@fixme.fi>
parents: 86
diff changeset
   172
        return "LogLine(%r, %s, %-12s, %s, %-35s, %-10s, %r)" % (
275a675712f1 clean up repr(LogLine) output
Tero Marttila <terom@fixme.fi>
parents: 86
diff changeset
   173
            self.channel, self.offset, self.format_type(), self.timestamp, self.format_source(), self.target, self.data
275a675712f1 clean up repr(LogLine) output
Tero Marttila <terom@fixme.fi>
parents: 86
diff changeset
   174
        )
275a675712f1 clean up repr(LogLine) output
Tero Marttila <terom@fixme.fi>
parents: 86
diff changeset
   175