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