2 An IRC logfile consists of a series of lines/events |
2 An IRC logfile consists of a series of lines/events |
3 """ |
3 """ |
4 |
4 |
5 class LogTypes : |
5 class LogTypes : |
6 """ |
6 """ |
7 Definitions of the various LogLines types |
7 Definitions of the various LogLines types: |
|
8 |
|
9 LogTypes.RAW |
|
10 LogTypes.LOG_OPEN |
|
11 LogTypes.LOG_CLOSE |
|
12 |
|
13 LogTypes.MSG |
|
14 LogTypes.NOTICE |
|
15 LogTypes.ACTION |
|
16 |
|
17 LogTypes.JOIN |
|
18 LogTypes.PART |
|
19 LogTypes.KICK |
|
20 LogTypes.MODE |
|
21 |
|
22 LogTypes.NICK |
|
23 LogTypes.QUIT |
|
24 |
|
25 LogTypes.TOPIC |
|
26 |
|
27 LogTypes.SELF_NOTICE |
|
28 LogTypes.SELF_NICK |
8 """ |
29 """ |
|
30 |
|
31 # list of LogType values by name |
|
32 LIST = [ |
|
33 ## special |
|
34 # unknown type, may or may not have a timestamp, no source, only data |
|
35 ('RAW', 0x01), |
|
36 |
|
37 # log opened |
|
38 ('LOG_OPEN', 0x02), |
|
39 |
|
40 # log closed |
|
41 ('LOG_CLOSE', 0x03), |
|
42 |
|
43 ## messages |
|
44 # normal message |
|
45 ('MSG', 0x10), |
|
46 |
|
47 # notice |
|
48 ('NOTICE', 0x11), |
|
49 |
|
50 # CTCP action |
|
51 ('ACTION', 0x12), |
|
52 |
|
53 ## user-channel stats |
|
54 # join |
|
55 ('JOIN', 0x21), |
|
56 |
|
57 # part |
|
58 ('PART', 0x22), |
|
59 |
|
60 # kick |
|
61 ('KICK', 0x25), |
|
62 |
|
63 # channel modes |
|
64 ('MODE', 0x26), |
|
65 |
|
66 ## user status |
|
67 # nick-change |
|
68 ('NICK', 0x31), |
|
69 |
|
70 # quit |
|
71 ('QUIT', 0x32), |
|
72 |
|
73 ## general channel status |
|
74 # topic changed |
|
75 ('TOPIC', 0x41), |
|
76 |
|
77 ## our own actions |
|
78 ('SELF_NOTICE', 0x51), |
|
79 ('SELF_NICK', 0x52), |
|
80 ] |
9 |
81 |
10 # unknown type, may or may not have a timestamp, no source, only data |
82 @classmethod |
11 RAW = 0x01 |
83 def name_from_code (cls, code) : |
|
84 """ |
|
85 Looks up a LogType name by code |
|
86 """ |
|
87 |
|
88 return dict((type, name) for name, type in cls.LIST)[code] |
|
89 |
|
90 # apply as attributes |
|
91 for name, code in LogTypes.LIST : |
|
92 setattr(LogTypes, name, code) |
12 |
93 |
13 class LogLine (object) : |
94 class LogLine (object) : |
14 """ |
95 """ |
15 An event on some specific channel |
96 An event on some specific channel |
16 """ |
97 """ |
|
98 |
|
99 # the LogChannel |
|
100 channel = None |
17 |
101 |
18 # the offset, only garunteed to be unique for a specific channel and date |
102 # the offset, only garunteed to be unique for a specific channel and date |
19 offset = None |
103 offset = None |
20 |
104 |
21 # the event type, as defiend in LogTypes |
105 # the event type, as defiend in LogTypes |
22 type = None |
106 type = None |
23 |
107 |
24 # the UTC timestamp of the event |
108 # the UTC timestamp of the event |
25 timestamp = None |
109 timestamp = None |
26 |
110 |
27 # the event source |
111 # the event source, this should be a |
28 source = None |
112 source = None |
|
113 |
|
114 # possible event target, for certain types (kick, nick) |
|
115 target = None |
29 |
116 |
30 # associated data (message, etc) |
117 # associated data (message, etc) |
31 data = None |
118 data = None |
32 |
119 |
33 def __init__ (self, offset, type, timestamp, source, data) : |
120 def __init__ (self, channel, offset, type, timestamp, source, target, data) : |
34 """ |
121 """ |
35 Initialize with given values |
122 Initialize with given values |
36 """ |
123 """ |
37 |
124 |
|
125 self.channel = channel |
38 self.offset = offset |
126 self.offset = offset |
39 self.type = type |
127 self.type = type |
40 self.timestamp = timestamp |
128 self.timestamp = timestamp |
41 self.source = source |
129 self.source = source |
|
130 self.target = target |
42 self.data = data |
131 self.data = data |
|
132 |
|
133 def __repr__ (self) : |
|
134 return "channel=%s, offset=%s, type=%s, timestamp=%s, source=%s, target=%s, data=%s" % ( |
|
135 self.channel, self.offset, LogTypes.name_from_code(self.type), self.timestamp, self.source, self.target, self.data |
|
136 ) |
43 |
137 |