# HG changeset patch # User Tero Marttila # Date 1234230531 -7200 # Node ID 745032a5780367f257a86a01bc1426ca7d74b1f1 # Parent a0662cff1d9dcddf5fe74f4def784249b5654d7c add #test logfile, improve handling of low-logfile situations diff -r a0662cff1d9d -r 745032a57803 config.py --- a/config.py Tue Feb 10 03:22:43 2009 +0200 +++ b/config.py Tue Feb 10 03:48:51 2009 +0200 @@ -31,6 +31,7 @@ # the log parser that we use LOG_PARSER = IrssiParser(LOG_TIMEZONE, LOG_TIMESTAMP_FMT) +LOG_PARSER_FULLTS = IrssiParser(LOG_TIMEZONE, '%Y%m%d%H%M%S') # the statically defined channel list LOG_CHANNELS = ChannelList([ @@ -41,6 +42,10 @@ LogChannel('openttd', "OFTC", "#openttd", LogDirectory(relpath('logs/openttd'), LOG_TIMEZONE, LOG_PARSER, LOG_CHARSET, LOG_FILENAME_FMT) ), + + LogChannel('test', "TEST", "#test", + LogDirectory(relpath('/home/terom/irclogs/test'), LOG_TIMEZONE, LOG_PARSER_FULLTS, LOG_CHARSET, LOG_FILENAME_FMT) + ) ]) # date format for URLs diff -r a0662cff1d9d -r 745032a57803 log_source.py --- a/log_source.py Tue Feb 10 03:22:43 2009 +0200 +++ b/log_source.py Tue Feb 10 03:48:51 2009 +0200 @@ -130,7 +130,7 @@ # open self.file = open(path, 'rb') - + def __iter__ (self) : """ Yields a series of unicode lines, as read from the top of the file @@ -345,10 +345,11 @@ # default to now if not dt : - dt = datetime.datetime.now(pytz.utc) - - # convert to target timezone - dtz = dt.astimezone(self.tz) + dtz = self.tz.localize(datetime.datetime.now()) + + else : + # convert to target timezone + dtz = dt.astimezone(self.tz) # our timedelta ONE_DAY = datetime.timedelta(1) @@ -372,6 +373,9 @@ # start counting at zero... file_count = 0 + # have we found any files at all so far? + have_found = False + # iterate backwards over days for day in self._iter_date_reverse(dt) : # stop if we've handled enough files by now @@ -386,14 +390,23 @@ # no logfile there? if not logfile : - # if we didn't find any logfiles at all, terminate rudely + # hit our limit? if file_count > max_files : - raise Exception("No recent logfiles found") - + # if we didn't find any logfiles at all, terminate rudely + if not have_found : + raise Exception("No recent logfiles found") + + else : + # stop looking, deal with what we've got + return + else : # skip to next day continue + # mark have_found + have_found = True + # yield it yield logfile @@ -402,20 +415,18 @@ Uses _iter_backwards + _get_logfile_date to read the yield the given lines from as many logfiles as needed """ - # iterate over logfiles - iter = self._iter_logfile_reverse() - # read the events into here lines = [] - # loop until done - while len(lines) < count : - # next logfile - logfile = iter.next() - + # start reading in those logfiles + for logfile in self._iter_logfile_reverse() : # read the events # XXX: use a queue lines = list(logfile.read_latest(count)) + lines + + # done? + if len(lines) >= count : + break # return the events return lines