diff -r 0521cf830eb9 -r 645cf9c4441e log_source.py --- a/log_source.py Tue Feb 10 22:59:52 2009 +0200 +++ b/log_source.py Tue Feb 10 23:00:11 2009 +0200 @@ -46,13 +46,26 @@ A collection of IRC logs for a specific target in some format. Provides the possibility to read specific events """ - def __init__ (self, decoder) : + def __init__ (self, decoder, channel=None) : """ - Use the given LogSourceDecoder + The appropriate LogChannel must be given, as we need to be able to construct the LogLines. If it is not yet + known, then it can be given as None, and set later with bind_channel. + + Uses the given LogSourceDecoder to decode the lines. + """ + + self.channel = channel + self.decoder = decoder + + def bind_channel (self, channel) : + """ + Set this source's channel, where None was set before """ - self.decoder = decoder - + assert not self.channel + + self.channel = channel + def get_latest (self, count) : """ Yield the latest events, up to `count` of them. @@ -156,7 +169,7 @@ XXX: modify to implement LogSource? """ - def __init__ (self, path, parser, decoder, start_date=None, sep='\n') : + def __init__ (self, path, parser, decoder, channel=None, start_date=None, sep='\n') : """ Open the file at the given path, which contains lines as separated by the given separator. Lines are decoded using the given LogSourceDecoder, and then parsed using the given parser, using the given date @@ -166,6 +179,7 @@ """ # store + self.channel = channel self.path = path self.parser = parser self.start_date = start_date @@ -192,7 +206,7 @@ """ # just use our __iter__ - return self.parser.parse_lines(self, self.start_date, starting_offset=1) + return self.parser.parse_lines(self.channel, self, self.start_date, starting_offset=1) def read_from (self, dt) : """ @@ -316,22 +330,23 @@ # decode in reverse order, using our starting date.... # XXX: use lines[::-1] or reversed? # XXX: it may make more sense to parse in reverse order, using 'self.end_date' or something like that - return self.parser.parse_lines(reversed(lines), self.start_date) + return self.parser.parse_lines(self.channel, reversed(lines), self.start_date) class LogDirectory (LogSource) : """ A directory containing a series of timestamped LogFiles """ - def __init__ (self, path, tz, parser, decoder, filename_fmt) : + def __init__ (self, path, tz, parser, decoder, filename_fmt, channel=None) : """ - Load the logfiles at the given path. + Load the logfiles at the given path, which are for the given LogChannel Decode the file lines using the given decoder, the files are named according the the date in the given timezone and date format, and will be parsed using the given parser. """ # store + self.channel = channel self.path = path self.tz = tz self.parser = parser @@ -366,7 +381,7 @@ try : if load : # open+return the LogFile - return LogFile(path, self.parser, self.decoder, d) + return LogFile(path, self.parser, self.decoder, start_date=d, channel=self.channel) else : # test