44 |
44 |
45 class IrssiParser (LogParser) : |
45 class IrssiParser (LogParser) : |
46 """ |
46 """ |
47 A parser for irssi logfiles |
47 A parser for irssi logfiles |
48 """ |
48 """ |
|
49 |
|
50 # timestamp prefix, with trailing space |
|
51 _TS = r'(?P<timestamp>[a-zA-Z0-9: ]+[a-zA-Z0-9])\s*' |
49 |
52 |
50 # subexpression parts |
53 # subexpression parts |
51 _TS = r'(?P<timestamp>\S+)' |
|
52 _NICK = r'(?P<nickname>.+?)' |
54 _NICK = r'(?P<nickname>.+?)' |
53 _NICK2 = r'(?P<nickname2>.+?)' |
55 _NICK2 = r'(?P<nickname2>.+?)' |
54 _TARGET = r'(?P<target>.+?)' |
56 _TARGET = r'(?P<target>.+?)' |
55 _CHAN = r'(?P<channel>.+?)' |
57 _CHAN = r'(?P<channel>.+?)' |
56 _CHAN2 = r'(?P<channel2>.+?)' |
58 _CHAN2 = r'(?P<channel2>.+?)' |
61 |
63 |
62 # regular expressions for matching lines, by type |
64 # regular expressions for matching lines, by type |
63 TYPE_EXPRS = ( |
65 TYPE_EXPRS = ( |
64 ( LogTypes.LOG_OPEN, r'--- Log opened (?P<datetime>.+)' ), |
66 ( LogTypes.LOG_OPEN, r'--- Log opened (?P<datetime>.+)' ), |
65 ( LogTypes.LOG_CLOSE, r'--- Log closed (?P<datetime>.+)' ), |
67 ( LogTypes.LOG_CLOSE, r'--- Log closed (?P<datetime>.+)' ), |
66 ( LogTypes.MSG, _TS + r' <(?P<flags>.)' + _NICK + '> ' + _MSG ), |
68 ( LogTypes.MSG, _TS + r'<(?P<flags>.)' + _NICK + '> ' + _MSG ), |
67 ( LogTypes.NOTICE, _TS + r' -' + _NICK + ':' + _CHAN + '- ' + _MSG ), |
69 ( LogTypes.NOTICE, _TS + r'-' + _NICK + ':' + _CHAN + '- ' + _MSG ), |
68 ( LogTypes.ACTION, _TS + r' \* ' + _NICK + ' ' + _MSG ), |
70 ( LogTypes.ACTION, _TS + r'\* ' + _NICK + ' ' + _MSG ), |
69 ( LogTypes.JOIN, _TS + r' -!- ' + _NICK + ' \[' + _USERHOST + '\] has joined ' + _CHAN ), |
71 ( LogTypes.JOIN, _TS + r'-!- ' + _NICK + ' \[' + _USERHOST + '\] has joined ' + _CHAN ), |
70 ( LogTypes.PART, _TS + r' -!- ' + _NICK + ' \[' + _USERHOST + '\] has left ' + _CHAN + ' \[(?P<message>.*?)\]' ), |
72 ( LogTypes.PART, _TS + r'-!- ' + _NICK + ' \[' + _USERHOST + '\] has left ' + _CHAN + ' \[(?P<message>.*?)\]' ), |
71 ( LogTypes.KICK, _TS + r' -!- ' + _TARGET + ' was kicked from ' + _CHAN + ' by ' + _NICK + ' \[(?P<message>.*?)\]' ), |
73 ( LogTypes.KICK, _TS + r'-!- ' + _TARGET + ' was kicked from ' + _CHAN + ' by ' + _NICK + ' \[(?P<message>.*?)\]' ), |
72 # XXX: use hostname instead of nickname for ServerMode |
74 # XXX: use hostname instead of nickname for ServerMode |
73 ( LogTypes.MODE, _TS + r' -!- (mode|ServerMode)/' + _CHAN + ' \[(?P<mode>.+?)\] by (?P<nickname>\S+)' ), |
75 ( LogTypes.MODE, _TS + r'-!- (mode|ServerMode)/' + _CHAN + ' \[(?P<mode>.+?)\] by (?P<nickname>\S+)' ), |
74 ( LogTypes.NICK, _TS + r' -!- ' + _NICK + ' is now known as (?P<target>\S+)' ), |
76 ( LogTypes.NICK, _TS + r'-!- ' + _NICK + ' is now known as (?P<target>\S+)' ), |
75 ( LogTypes.QUIT, _TS + r' -!- ' + _NICK + ' \[' + _USERHOST + '\] has quit \[(?P<message>.*?)\]' ), |
77 ( LogTypes.QUIT, _TS + r'-!- ' + _NICK + ' \[' + _USERHOST + '\] has quit \[(?P<message>.*?)\]' ), |
76 ( LogTypes.TOPIC, _TS + r' -!- (' + _NICK + ' changed the topic of ' + _CHAN + ' to: (?P<topic>.*)|Topic unset by ' + _NICK2 + ' on ' + _CHAN2 + ')' ), |
78 ( LogTypes.TOPIC, _TS + r'-!- (' + _NICK + ' changed the topic of ' + _CHAN + ' to: (?P<topic>.*)|Topic unset by ' + _NICK2 + ' on ' + _CHAN2 + ')' ), |
77 |
79 |
78 ( LogTypes.SELF_NOTICE, _TS + r' \[notice\(' + _CHAN + '\)\] ' + _MSG ), |
80 ( LogTypes.SELF_NOTICE, _TS + r'\[notice\(' + _CHAN + '\)\] ' + _MSG ), |
79 ( LogTypes.SELF_NICK, _TS + r' -!- You\'re now known as (?P<target>\S+)' ), |
81 ( LogTypes.SELF_NICK, _TS + r'-!- You\'re now known as (?P<target>\S+)' ), |
80 |
82 |
81 ( LogTypes.NETSPLIT_START, _TS + r' -!- Netsplit ' + _SRV1 + ' <-> ' + _SRV2 + ' quits: (?P<nick_list>[^(]+)( \(\+(?P<count>\d+) more,\S+\))?'), |
83 ( LogTypes.NETSPLIT_START, _TS + r'-!- Netsplit ' + _SRV1 + ' <-> ' + _SRV2 + ' quits: (?P<nick_list>[^(]+)( \(\+(?P<count>\d+) more,\S+\))?'), |
82 ( LogTypes.NETSPLIT_END, _TS + r' -!- Netsplit over, joins: (?P<nick_list>[^(]+)( \(\+(?P<count>\d+) more\))?' ), |
84 ( LogTypes.NETSPLIT_END, _TS + r'-!- Netsplit over, joins: (?P<nick_list>[^(]+)( \(\+(?P<count>\d+) more\))?' ), |
83 |
85 |
84 ( 'DAY_CHANGED', r'--- Day changed (?P<date>.+)' ), |
86 ( 'DAY_CHANGED', r'--- Day changed (?P<date>.+)' ), |
85 ) |
87 ) |
86 |
88 |
87 # precompile |
89 # precompile |