Beispiel #1
0
    def _get_tail(self):
        "Read the part of the data after last_timeseries_end_date"
        self.tail = []
        date = self.last_timeseries_end_date
        saveddir = os.getcwd()
        try:
            os.chdir(self.filename)

            # We assume that the first possible file we need to read is the
            # previous than what it seems initially, because of the possibility
            # of a DST offset interfering (I think that actually a negative DST
            # offset would be needed for this to be a problem - but let's be
            # safe and not sorry) (note that if the date is 0001-01-01 it
            # means that the time series in the database is empty and we'll
            # upload it in its entirety anyway, so no need to do the trick
            # [which would fail because dates can't be less than that]).
            a = add_months_to_datetime(date, -1) if date.year > 1 else date
            first_file = '{0.year:04}-{0.month:02}.wlk'.format(a)

            filename_regexp = re.compile(r'\d{4}-\d{2}.wlk$')
            data_files = [x for x in glob('*.wlk')
                          if filename_regexp.match(x) and x >= first_file]
            data_files.sort()
            for current_file in data_files:
                self.tail.extend(self._get_tail_part(date, current_file))
        finally:
            os.chdir(saveddir)