Exemple #1
0
    def _get_user_messages_for_day(self, date):
        userRepos = self.app.currentuser.repos

        # Set the start and end time to be the start and end of the day,
        # respectively, to get all entries for that day
        startTime = librdiff.RdiffTime(date)
        startTime.set_time(0, 0, 0)

        endTime = librdiff.RdiffTime(date)
        endTime.set_time(23, 59, 59)

        return self._getUserMessages(userRepos, True, False, startTime,
                                     endTime)
Exemple #2
0
    def send_notifications(self):
        """
        Loop trough all the user repository and send notifications.
        """

        now = librdiff.RdiffTime()

        def _user_repos():
            """Return a generator trought user repos to be notified."""
            for user in self.app.userdb.list():
                # Check if user has email.
                if not user.email:
                    continue
                # Identify old repo for current user.
                old_repos = []
                for repo in user.repo_list:
                    # Check if repo has age configured (in days)
                    maxage = repo.maxage
                    if not maxage or maxage <= 0:
                        continue
                    # Check repo age.
                    r = librdiff.RdiffRepo(user.user_root, repo.name)
                    if r.last_backup_date < (now - datetime.timedelta(days=maxage)):
                        old_repos.append(r)
                # Return an item only if user had old repo
                if old_repos:
                    yield user, old_repos

        # For each candidate, send mail.
        for user, repos in _user_repos():
            parms = {'user': user, 'repos': repos}
            self.send_mail(user, _('Notification'), 'email_notification.html', **parms)
Exemple #3
0
    def _get_recent_user_messages(self, failuresOnly):
        user_repos = self.app.currentuser.repos

        asOfDate = librdiff.RdiffTime() - timedelta(days=5)

        return self._getUserMessages(user_repos, not failuresOnly, True,
                                     asOfDate, None)
Exemple #4
0
    def entry(self, path_b=b"", date=""):
        self.assertIsInstance(path_b, bytes)
        self.assertIsInstance(date, str)
        # Validate date
        try:
            entry_time = librdiff.RdiffTime(int(date))
        except:
            logger.exception("invalid date")
            raise cherrypy.HTTPError(400, _("Invalid date."))

        if not path_b:
            userMessages = self._get_user_messages_for_day(entry_time)
        else:
            # Validate repo parameter
            repo_obj = self.validate_user_path(path_b)[0]

            userMessages = self._getUserMessages([repo_obj.path], False, True,
                                                 entry_time, entry_time)

        return self._compileStatusPageTemplate(False, userMessages, False)
Exemple #5
0
    def _remove_older(self, user, repo, keepdays):
        """
        Take action to remove older.
        """
        assert isinstance(keepdays, int)
        assert keepdays > 0
        # Get instance of the repo.
        r = librdiff.RdiffRepo(user.user_root, repo.name)
        # Check history date.
        if not r.last_backup_date:
            _logger.info("no backup dates for [%r]", r.full_path)
            return
        d = librdiff.RdiffTime() - r.last_backup_date
        d = d.days + keepdays

        _logger.info("execute rdiff-backup --force --remove-older-than=%sD %r",
                     d, r.full_path)
        r.execute(
            b'--force',
            b'--remove-older-than=' + str(d).encode(encoding='latin1') + b'D',
            r.full_path)