def _getUserMessages(self, repos, includeSuccess, includeFailure, earliest_date, latest_date): repoErrors = [] allBackups = [] for repo_obj in repos: backups = repo_obj.get_history_entries(-1, earliest_date, latest_date) allBackups += [{ "repo": repo_obj, "date": backup.date, "size": backup.size, "errors": backup.errors } for backup in backups] allBackups.sort(key=lambda x: x["date"]) failedBackups = [x for x in allBackups if x["errors"]] # group successful backups by day successfulBackups = [x for x in allBackups if not x["errors"]] if successfulBackups: lastSuccessDate = successfulBackups[0]["date"] successfulBackups = rdw_helpers.groupby( successfulBackups, lambda x: x["date"].get_local_day_since_epoch()) userMessages = [] # generate failure messages if includeFailure: for job in failedBackups: date = job["date"] job.update({ "is_success": False, "date": date, "repoErrors": [], "backups": [] }) userMessages.append(job) # generate success messages (publish date is most recent backup date) if includeSuccess: for day in list(successfulBackups.keys()): date = successfulBackups[day][0]["date"] # include repository errors in most recent entry if date == lastSuccessDate: repoErrorsForMsg = repoErrors else: repoErrorsForMsg = [] userMessages.append({ "is_success": True, "date": date, "repoErrors": repoErrorsForMsg, "backups": successfulBackups[day] }) # sort messages by date userMessages.sort(key=lambda x: x["date"]) return userMessages
def dir_entries(self): """Get directory entries for the current path. It is similar to listdir() but for rdiff-backup.""" logger.debug("get directory entries for [%r]", self.full_path) # Group increments by filename grouped_increment_entries = rdw_helpers.groupby( self._repo._get_increment_entries(self.path), lambda x: x.filename) # Check if the directory exists. It may not exist if # it has been delete existing_entries = [] if os.path.isdir(self.full_path) and os.access(self.full_path, os.F_OK): # Get entries from directory structure existing_entries = os.listdir(self.full_path) # Remove "rdiff-backup-data" directory if self.path == b'': existing_entries.remove(RDIFF_BACKUP_DATA) # Process each increment entries and combine this with the existing # entries entriesDict = {} for filename, increments in iteritems(grouped_increment_entries): # Check if filename exists exists = filename in existing_entries # Create DirEntry to represent the item new_entry = DirEntry( self, filename, exists, increments) entriesDict[filename] = new_entry # Then add existing entries for filename in existing_entries: # Check if the entry was created by increments entry if filename in entriesDict: continue # The entry doesn't exists (mostly because it ever change). So # create a DirEntry to represent it new_entry = DirEntry( self, filename, True, []) entriesDict[filename] = new_entry # Return the values (so the DirEntry objects) return list(entriesDict.values())