log_source.py
changeset 94 6673de9bc911
parent 93 48fca00689e3
child 97 6165f1ba458d
equal deleted inserted replaced
93:48fca00689e3 94:6673de9bc911
   160             Return a sequence of dates, telling which days in the given month (as a datetime) have logs available
   160             Return a sequence of dates, telling which days in the given month (as a datetime) have logs available
   161         """
   161         """
   162 
   162 
   163         abstract
   163         abstract
   164     
   164     
   165     def get_modified (self, dt=None) :
   165     def get_modified (self, dt=None, after=None) :
   166         """
   166         """
   167             Returns a sequence of LogLines that may have been *modified* from their old values since the given datetime.
   167             Returns a sequence of LogLines that may have been *modified* from their old values since the given datetime.
   168 
   168 
   169             If the datetime is not given, *all* lines are returned
   169             If the datetime is not given, *all* lines are returned.
       
   170 
       
   171             If after is given, only lines after said date will be returned, regardless of modification.
   170 
   172 
   171             The LogLines should be in time order.
   173             The LogLines should be in time order.
   172         """
   174         """
   173 
   175 
   174         abstract
   176         abstract
   411                 return None
   413                 return None
   412 
   414 
   413             else :
   415             else :
   414                 raise
   416                 raise
   415     
   417     
   416     def _iter_logfile_dates (self) :
   418     def _iter_logfile_dates (self, after=None) :
   417         """
   419         """
   418             Yields a series of naive datetime objects representing the logfiles that are available, in time order
   420             Yields a series of naive datetime objects representing the logfiles that are available, in time order.
       
   421 
       
   422             If after is given, only dates after said date will be returned
   419         """
   423         """
   420 
   424 
   421         # listdir
   425         # listdir
   422         filenames = os.listdir(self.path)
   426         filenames = os.listdir(self.path)
   423 
   427 
   425         filenames.sort()
   429         filenames.sort()
   426 
   430 
   427         # iter files
   431         # iter files
   428         for filename in filenames :
   432         for filename in filenames :
   429             try :
   433             try :
   430                 # parse date + yield
   434                 # parse date
   431                 yield datetime.datetime.strptime(filename, self.filename_fmt).replace(tzinfo=self.tz)
   435                 date = datetime.datetime.strptime(filename, self.filename_fmt).replace(tzinfo=self.tz)
   432             
   436             
   433             except :
   437             except :
   434                 # ignore
   438                 # ignore
   435                 continue
   439                 continue
       
   440 
       
   441             else :
       
   442                 # ignore after?
       
   443                 if after and date < after :
       
   444                     continue
       
   445 
       
   446                 else :
       
   447                     # yield
       
   448                     yield date
   436             
   449             
   437     def _iter_date_reverse (self, dt=None) :
   450     def _iter_date_reverse (self, dt=None) :
   438         """
   451         """
   439             Yields an infinite series of naive date objects in our timezone, iterating backwards in time starting at the
   452             Yields an infinite series of naive date objects in our timezone, iterating backwards in time starting at the
   440             given *datetime*, or the the current date, if none given
   453             given *datetime*, or the the current date, if none given
   602             # test for it
   615             # test for it
   603             if self._get_logfile_date(log_date, load=False) :
   616             if self._get_logfile_date(log_date, load=False) :
   604                 # valid
   617                 # valid
   605                 yield dt.date()
   618                 yield dt.date()
   606 
   619 
   607     def get_modified (self, dt=None) :
   620     def get_modified (self, dt=None, after=None) :
   608         """
   621         """
   609             Returns the contents off all logfiles with mtimes past the given date
   622             Returns the contents off all logfiles with mtimes past the given date
   610         """
   623         """
   611         
   624 
   612         # iterate through all available logfiles in date order, as datetimes
   625         # iterate through all available logfiles in date order, as datetimes, from the given date on
   613         for log_date in self._iter_logfile_dates() :
   626         for log_date in self._iter_logfile_dates(after) :
   614             # compare against dt?
   627             # compare against dt?
   615             if dt :
   628             if dt :
   616                 # stat
   629                 # stat
   617                 st = self._get_logfile_date(log_date, load=False, stat=True)
   630                 st = self._get_logfile_date(log_date, load=False, stat=True)
   618 
   631