from .cfg_app import PpCfgAppError, PpConfigApplication
-__version__ = '0.4.1'
+__version__ = '0.4.2'
LOG = logging.getLogger(__name__)
UTC = datetime.timezone.utc
LOG.debug("Status from {f!r}:\n{s}".format(
f=self.statusfile, s=pp(status)))
+ if 'checks' in status:
+ dates = []
+ for date in status['checks'].keys():
+ dates.append(date)
+ if dates:
+ dates.sort()
+ first_date = dates[0].replace(tzinfo=UTC)
+ tdiff = self.now - first_date
+ if tdiff.days > 7 or len(dates) > 5:
+ self.rotate_status_file(dates[-1])
+ return {}
+
return status
+ # -------------------------------------------------------------------------
+ def rotate_status_file(self, date=None):
+
+ if not os.path.isfile(self.statusfile):
+ LOG.debug("File {!r} to rotate does not exists.".format(self.statusfile))
+ return
+
+ if not date:
+ file_stat = os.stat(self.statusfile)
+ date = datetime.datetime.utcfromtimestamp(file_stat.st_mtime)
+ (stem, ext) = os.path.splitext(self.statusfile)
+ new_fname = "{s}.{d}{e}".format(
+ s=stem, d=date.strftime('%Y-%m-%d_%H:%M:%S'), e=ext)
+ LOG.info("Renaming {o!r} -> {n!r}.".format(o=self.statusfile, n=new_fname))
+ os.rename(self.statusfile, new_fname)
+
# -------------------------------------------------------------------------
def write_status_data(self):