Esempio n. 1
0
 def getParmsForPage(self, repoPath, repoName):
    rdiffHistory = librdiff.getBackupHistory(repoPath)
    rdiffHistory.reverse()
    entries = []
    cumulativeSize = 0
    if len(rdiffHistory) > 0: cumulativeSize = rdiffHistory[0].size
    
    for historyItem in rdiffHistory:
       fileSize = ""
       incrementSize = ""
       cumulativeSizeStr = ""
       if not historyItem.inProgress:
          fileSize = rdw_helpers.formatFileSizeStr(historyItem.size)
          incrementSize = rdw_helpers.formatFileSizeStr(historyItem.incrementSize)
          cumulativeSize += historyItem.incrementSize
          cumulativeSizeStr = rdw_helpers.formatFileSizeStr(cumulativeSize)
       entries.append({ "date" : historyItem.date.getDisplayString(),
                        "dateinseconds" : historyItem.date.getLocalSeconds(),
                        "inProgress" : historyItem.inProgress,
                        "errors" : historyItem.errors,
                        "cumulativesize" : cumulativeSizeStr,
                        "cumulativesizeinbytes" : cumulativeSize,
                        "size" : fileSize,
                        "sizeinbytes" : historyItem.size })
    return {"title" : "Backup history for " + repoName, "history" : entries, "totalBackups" : len(rdiffHistory)}
    def getParmsForPage(self, repoPath, repoName):
        rdiffHistory = librdiff.getBackupHistory(repoPath)
        rdiffHistory.reverse()
        entries = []
        cumulativeSize = 0
        if len(rdiffHistory) > 0: cumulativeSize = rdiffHistory[0].size

        for historyItem in rdiffHistory:
            fileSize = ""
            incrementSize = ""
            cumulativeSizeStr = ""
            if not historyItem.inProgress:
                fileSize = rdw_helpers.formatFileSizeStr(historyItem.size)
                incrementSize = rdw_helpers.formatFileSizeStr(
                    historyItem.incrementSize)
                cumulativeSize += historyItem.incrementSize
                cumulativeSizeStr = rdw_helpers.formatFileSizeStr(
                    cumulativeSize)
            entries.append({
                "date": historyItem.date.getDisplayString(),
                "inProgress": historyItem.inProgress,
                "errors": historyItem.errors,
                "cumulativeSize": cumulativeSizeStr,
                "size": fileSize
            })
        return {
            "title": "Backup history for " + repoName,
            "history": entries,
            "totalBackups": len(rdiffHistory)
        }
Esempio n. 3
0
    def getParmsForPage(self,
                        repoPath,
                        repoName,
                        allowHistoryDeletion=False,
                        message='',
                        error=''):
        rdiffHistory = librdiff.getBackupHistory(repoPath)
        rdiffHistory.reverse()
        entries = []
        cumulativeSize = 0
        if len(rdiffHistory) > 0: cumulativeSize = rdiffHistory[0].size

        for historyItem in rdiffHistory:
            fileSize = ""
            incrementSize = ""
            cumulativeSizeStr = ""
            if not historyItem.inProgress:
                fileSize = rdw_helpers.formatFileSizeStr(historyItem.size)
                cumulativeSize += historyItem.incrementSize
                cumulativeSizeStr = rdw_helpers.formatFileSizeStr(
                    cumulativeSize)
            entries.append({
                "date": historyItem.date.getDisplayString(),
                "rawDate": historyItem.date.getUrlString(),
                "inProgress": historyItem.inProgress,
                "errors": historyItem.errors,
                "cumulativeSize": cumulativeSizeStr,
                "rawIncrementSize": historyItem.incrementSize,
                "size": fileSize
            })

        # Now, go backwards through the history, and calculate space used by increments
        cumulativeSize = 0
        for entry in reversed(entries):
            entry['priorIncrementsSize'] = rdw_helpers.formatFileSizeStr(
                cumulativeSize)
            cumulativeSize += entry['rawIncrementSize']

        # Don't allow history deletion for the last item
        if entries:
            entries[-1]['allowHistoryDeletion'] = False
        return {
            "title": "Backup history for " + repoName,
            "history": entries,
            "totalBackups": len(rdiffHistory),
            "allowHistoryDeletion": allowHistoryDeletion,
            "message": message,
            "error": error
        }
 def getParmsForPage(self, root, repos):
     repoList = []
     repoErrors = []
     for userRepo in repos:
         try:
             repoHistory = librdiff.getLastBackupHistoryEntry(rdw_helpers.joinPaths(root, userRepo))
         except librdiff.FileError:
             repoSize = "0"
             repoDate = "Error"
             repoErrors.append(
                 {
                     "repoName": userRepo,
                     "repoSize": repoSize,
                     "repoDate": repoDate,
                     "repoBrowseUrl": self.buildBrowseUrl(userRepo, "/", False),
                     "repoHistoryUrl": self.buildHistoryUrl(userRepo),
                 }
             )
         else:
             repoSize = rdw_helpers.formatFileSizeStr(repoHistory.size)
             if repoHistory.inProgress:
                 repoSize = "In Progress"
             repoDate = repoHistory.date.getDisplayString()
             repoList.append(
                 {
                     "repoName": userRepo,
                     "repoSize": repoSize,
                     "repoDate": repoDate,
                     "repoBrowseUrl": self.buildBrowseUrl(userRepo, "/", False),
                     "repoHistoryUrl": self.buildHistoryUrl(userRepo),
                 }
             )
     return {"title": "browse", "repos": repoList, "badrepos": repoErrors}
Esempio n. 5
0
    def _getUserMessages(self, repos, includeSuccess, includeFailure,
                         earliestDate, latestDate):
        userRoot = self.getUserDB().getUserRoot(self.getUsername())

        repoErrors = []
        allBackups = []
        for repo in repos:
            try:
                backups = librdiff.getBackupHistoryForDateRange(
                    rdw_helpers.joinPaths(userRoot, repo), earliestDate,
                    latestDate)
                allBackups += [{
                    "repo":
                    repo,
                    "date":
                    backup.date,
                    "displayDate":
                    backup.date.getDisplayString(),
                    "size":
                    rdw_helpers.formatFileSizeStr(backup.size),
                    "errors":
                    backup.errors,
                    "repoLink":
                    self.buildBrowseUrl(repo, "/", False)
                } for backup in backups]
            except librdiff.FileError, error:
                repoErrors.append({
                    "repo":
                    repo,
                    "error":
                    error.getErrorString(),
                    "repoLink":
                    self.buildBrowseUrl(repo, "/", False)
                })
Esempio n. 6
0
   def getParmsForPage(self, root, repos):
      repoList = []
      for reponame in repos:
         try:
            repoHistory = librdiff.getLastBackupHistoryEntry(rdw_helpers.joinPaths(root, reponame))
            reposize = rdw_helpers.formatFileSizeStr(repoHistory.size)
            reposizeinbytes = repoHistory.size
            if repoHistory.inProgress:
               reposize = "In Progress"
            repoDate = repoHistory.date.getDisplayString()
            repodateinseconds = repoHistory.date.getLocalSeconds()
            failed = False
         except librdiff.FileError:
            logging.exception("Can't get reference on the last backup history for %s" % reponame)
            reposize = "0"
            reposizeinbytes = 0 
            repoDate = "Error"
            repodateinseconds = 0
            failed = True
         repoList.append({ "reponame" : reponame,
                           "reposize" : reposize,
                           "reposizeinbytes" : reposizeinbytes,
                           "repodate" : repoDate,
                           "repodateinseconds" : repodateinseconds,
                           "repoBrowseUrl" : self.buildBrowseUrl(reponame, "/", False),
                           "repoHistoryUrl" : self.buildHistoryUrl(reponame),
                           'failed': failed})

      self._sortLocations(repoList)
      return { "title" : "browse", "repos" : repoList }
   def getParmsForPage(self, root, repos):
      repoList = []
      for userRepo in repos:
         try:
            repoHistory = librdiff.getLastBackupHistoryEntry(rdw_helpers.joinPaths(root, userRepo))
         except librdiff.FileError:
            repoSize = "0"
            repoDate = "Error"
            repoList.append({ "repoName" : userRepo,
                           "repoSize" : repoSize,
                           "repoDate" : repoDate,
                           "repoBrowseUrl" : self.buildBrowseUrl(userRepo, "/", False),
                           "repoHistoryUrl" : self.buildHistoryUrl(userRepo),
                           'failed': True})
         else:
            repoSize = rdw_helpers.formatFileSizeStr(repoHistory.size)
            if repoHistory.inProgress:
               repoSize = "In Progress"
            repoDate = repoHistory.date.getDisplayString()
            repoList.append({ "repoName" : userRepo,
                              "repoSize" : repoSize,
                              "repoDate" : repoDate,
                              "repoBrowseUrl" : self.buildBrowseUrl(userRepo, "/", False),
                              "repoHistoryUrl" : self.buildHistoryUrl(userRepo),
                              'failed': False})

      self._sortLocations(repoList)
      # Make second pass through list, setting the 'altRow' attribute
      for i in range(0, len(repoList)):
         repoList[i]['altRow'] = (i % 2 == 0)
      return { "title" : "browse", "repos" : repoList }
Esempio n. 8
0
   def getParmsForPage(self, root, repos):
      repoList = []
      for reponame in repos:
         try:
            repoHistory = librdiff.getLastBackupHistoryEntry(rdw_helpers.joinPaths(root, reponame))
            reposize = rdw_helpers.formatFileSizeStr(repoHistory.size)
            reposizeinbytes = repoHistory.size
            if repoHistory.inProgress:
               reposize = "En Progreso"
            repoDate = repoHistory.date.getDisplayString()
            repodateinseconds = repoHistory.date.getLocalSeconds()
            failed = False
         except librdiff.FileError:
            logging.exception("No se puede obtener informacion previa de %s" % reponame)
            reposize = "0"
            reposizeinbytes = 0 
            repoDate = "Error"
            repodateinseconds = 0
            failed = True
         repoList.append({ "reponame" : reponame,
                           "reposize" : reposize,
                           "reposizeinbytes" : reposizeinbytes,
                           "repodate" : repoDate,
                           "repodateinseconds" : repodateinseconds,
                           "repoBrowseUrl" : self.buildBrowseUrl(reponame, "/", False),
                           "repoHistoryUrl" : self.buildHistoryUrl(reponame),
                           'failed': failed})

      self._sortLocations(repoList)
      return { "title" : "browse", "repos" : repoList }
    def index(self):
        page = self.startPage("Backup Locations")
        page = page + self.writeTopLinks()

        repoList = []
        for userRepo in self.userDB.getUserRepoPaths(self.getUsername()):
            try:
                repoHistory = librdiff.getLastBackupHistoryEntry(
                    rdw_helpers.joinPaths(
                        self.userDB.getUserRoot(self.getUsername()), userRepo))
            except librdiff.FileError:
                repoSize = "0"
                repoDate = "Error"
            else:
                repoSize = rdw_helpers.formatFileSizeStr(repoHistory.size)
                repoDate = repoHistory.date.getDisplayString()
            repoList.append({
                "repoName":
                userRepo,
                "repoSize":
                repoSize,
                "repoDate":
                repoDate,
                "repoBrowseUrl":
                self.buildBrowseUrl(userRepo, "/", False),
                "repoHistoryUrl":
                self.buildHistoryUrl(userRepo)
            })
        page = page + self.compileTemplate(
            "repo_listing.html", title="browse", repos=repoList)
        page = page + self.endPage()
        return page
    def getParmsForPage(self, repoPath, repoName, allowHistoryDeletion=False, message="", error=""):
        rdiffHistory = librdiff.getBackupHistory(repoPath)
        rdiffHistory.reverse()
        entries = []
        cumulativeSize = 0
        if len(rdiffHistory) > 0:
            cumulativeSize = rdiffHistory[0].size

        for historyItem in rdiffHistory:
            fileSize = ""
            incrementSize = ""
            cumulativeSizeStr = ""
            if not historyItem.inProgress:
                fileSize = rdw_helpers.formatFileSizeStr(historyItem.size)
                cumulativeSize += historyItem.incrementSize
                cumulativeSizeStr = rdw_helpers.formatFileSizeStr(cumulativeSize)
            entries.append(
                {
                    "date": historyItem.date.getDisplayString(),
                    "rawDate": historyItem.date.getUrlString(),
                    "inProgress": historyItem.inProgress,
                    "errors": historyItem.errors,
                    "cumulativeSize": cumulativeSizeStr,
                    "rawIncrementSize": historyItem.incrementSize,
                    "size": fileSize,
                }
            )

        # Now, go backwards through the history, and calculate space used by increments
        cumulativeSize = 0
        for entry in reversed(entries):
            entry["priorIncrementsSize"] = rdw_helpers.formatFileSizeStr(cumulativeSize)
            cumulativeSize += entry["rawIncrementSize"]

        # Don't allow history deletion for the last item
        if entries:
            entries[-1]["allowHistoryDeletion"] = False
        return {
            "title": "Backup history for " + repoName,
            "history": entries,
            "totalBackups": len(rdiffHistory),
            "allowHistoryDeletion": allowHistoryDeletion,
            "message": message,
            "error": error,
        }
Esempio n. 11
0
   def _getUserMessages(self, repos, includeSuccess, includeFailure, earliestDate, latestDate):
      userRoot = self.userDB.getUserRoot(self.getUsername())

      repoErrors = []
      allBackups = []
      for repo in repos:
         try:
            backups = librdiff.getBackupHistoryForDateRange(rdw_helpers.joinPaths(userRoot, repo), earliestDate, latestDate);
            allBackups += [{"repo": repo, "date": backup.date, "displayDate": backup.date.getDisplayString(),
               "size": rdw_helpers.formatFileSizeStr(backup.size), "errors": backup.errors} for backup in backups]
         except librdiff.FileError, error:
            repoErrors.append({"repo": repo, "error": error.getErrorString()})
 def getParmsForPage(self, repoPath, repoName):
    rdiffHistory = librdiff.getBackupHistory(repoPath)
    rdiffHistory.reverse()
    entries = []
    for historyItem in rdiffHistory:
       sizeStr = ""
       if not historyItem.inProgress:
          sizeStr = rdw_helpers.formatFileSizeStr(historyItem.size)
       entries.append({ "date" : historyItem.date.getDisplayString(),
                        "inProgress" : historyItem.inProgress,
                        "errors" : historyItem.errors,
                        "size" : sizeStr })
    return {"title" : "Backup history for "+repoName, "history" : entries}
 def getParmsForPage(self, repoPath, repoName):
     rdiffHistory = librdiff.getBackupHistory(repoPath)
     rdiffHistory.reverse()
     entries = []
     for historyItem in rdiffHistory:
         sizeStr = ""
         if not historyItem.inProgress:
             sizeStr = rdw_helpers.formatFileSizeStr(historyItem.size)
         entries.append({
             "date": historyItem.date.getDisplayString(),
             "inProgress": historyItem.inProgress,
             "errors": historyItem.errors,
             "size": sizeStr
         })
     return {"title": "Backup history for " + repoName, "history": entries}
    def getParmsForPage(self, root, repos):
        repoList = []
        for userRepo in repos:
            try:
                repoHistory = librdiff.getLastBackupHistoryEntry(
                    rdw_helpers.joinPaths(root, userRepo))
            except librdiff.FileError:
                repoSize = "0"
                repoDate = "Error"
                repoList.append({
                    "repoName":
                    userRepo,
                    "repoSize":
                    repoSize,
                    "repoDate":
                    repoDate,
                    "repoBrowseUrl":
                    self.buildBrowseUrl(userRepo, "/", False),
                    "repoHistoryUrl":
                    self.buildHistoryUrl(userRepo),
                    'failed':
                    True
                })
            else:
                repoSize = rdw_helpers.formatFileSizeStr(repoHistory.size)
                if repoHistory.inProgress:
                    repoSize = "In Progress"
                repoDate = repoHistory.date.getDisplayString()
                repoList.append({
                    "repoName":
                    userRepo,
                    "repoSize":
                    repoSize,
                    "repoDate":
                    repoDate,
                    "repoBrowseUrl":
                    self.buildBrowseUrl(userRepo, "/", False),
                    "repoHistoryUrl":
                    self.buildHistoryUrl(userRepo),
                    'failed':
                    False
                })

        self._sortLocations(repoList)
        # Make second pass through list, setting the 'altRow' attribute
        for i in range(0, len(repoList)):
            repoList[i]['altRow'] = (i % 2 == 0)
        return {"title": "browse", "repos": repoList}
Esempio n. 15
0
   def _getUserMessages(self):
      userRoot = self.userDB.getUserRoot(self.getUsername())
      userRepos = self.userDB.getUserRepoPaths(self.getUsername())

      asOfDate = rdw_helpers.rdwTime()
      asOfDate.initFromMidnightUTC(-5)

      # build list of all backups
      allBackups = []
      repoErrors = []
      for repo in userRepos:
         try:
            backups = librdiff.getBackupHistorySinceDate(rdw_helpers.joinPaths(userRoot, repo), asOfDate)
            allBackups += [{"repo": repo, "date": backup.date, "displayDate": backup.date.getDisplayString(),
               "size": rdw_helpers.formatFileSizeStr(backup.size), "errors": backup.errors} for backup in backups]
         except librdiff.FileError, error:
            repoErrors.append({"repo": repo, "error": error.getErrorString()})
Esempio n. 16
0
 def getParmsForPage(self, root, repos):
     repoList = []
     repoErrors = []
     for userRepo in repos:
         try:
             repoHistory = librdiff.getLastBackupHistoryEntry(
                 rdw_helpers.joinPaths(root, userRepo))
         except librdiff.FileError:
             repoSize = "0"
             repoDate = "Error"
             repoErrors.append({
                 "repoName":
                 userRepo,
                 "repoSize":
                 repoSize,
                 "repoDate":
                 repoDate,
                 "repoBrowseUrl":
                 self.buildBrowseUrl(userRepo, "/", False),
                 "repoHistoryUrl":
                 self.buildHistoryUrl(userRepo)
             })
         else:
             repoSize = rdw_helpers.formatFileSizeStr(repoHistory.size)
             if repoHistory.inProgress:
                 repoSize = "In Progress"
             repoDate = repoHistory.date.getDisplayString()
             repoList.append({
                 "repoName":
                 userRepo,
                 "repoSize":
                 repoSize,
                 "repoDate":
                 repoDate,
                 "repoBrowseUrl":
                 self.buildBrowseUrl(userRepo, "/", False),
                 "repoHistoryUrl":
                 self.buildHistoryUrl(userRepo)
             })
     return {"title": "browse", "repos": repoList, "badrepos": repoErrors}
   def index(self):
      page = self.startPage("Backup Locations")
      page = page + self.writeTopLinks()

      repoList = []
      for userRepo in self.userDB.getUserRepoPaths(self.getUsername()):
         try:
            repoHistory = librdiff.getBackupHistory(rdw_helpers.joinPaths(self.userDB.getUserRoot(self.getUsername()), userRepo), 1)
         except librdiff.FileError:
            repoSize = "0"
            repoDate = "Error"
         else:
            repoSize = rdw_helpers.formatFileSizeStr(repoHistory[0].size)
            repoDate = repoHistory[0].date.getDisplayString()
         repoList.append({ "repoName" : userRepo,
                           "repoSize" : repoSize,
                           "repoDate" : repoDate,
                           "repoBrowseUrl" : self.buildBrowseUrl(userRepo, "/"),
                           "repoHistoryUrl" : self.buildHistoryUrl(userRepo) })
      page = page + self.compileTemplate("repo_listing.html", title="browse", repos=repoList)
      page = page + self.endPage()
      return page
Esempio n. 18
0
                    x.getDisplayString()
                } for x in entryChangeDates]

            showNoRevisionsText = (len(changeDates)
                                   == 0) and (not libEntry.isDir)
            entries.append({
                "filename":
                libEntry.name,
                "fileRestoreUrl":
                entryLink,
                "exists":
                libEntry.exists,
                "date":
                libEntry.changeDates[-1].getDisplayString(),
                "size":
                rdw_helpers.formatFileSizeStr(libEntry.fileSize),
                "hasPrevRevisions":
                len(changeDates) > 0,
                "showNoRevisionsText":
                showNoRevisionsText,
                "changeDates":
                changeDates
            })

        # Start page
        title = "Browse " + repo
        page = self.startPage(title)
        page = page + self.writeTopLinks()
        page = page + self.compileTemplate("dir_listing.html",
                                           title=title,
                                           files=entries,
            return self.writeErrorPage("Backup location not specified.")
        if not repo in self.userDB.getUserRepoPaths(self.getUsername()):
            return self.writeErrorPage("Access is denied.")

        page = self.startPage("Backup History")
        page = page + self.writeTopLinks()
        try:
            rdiffHistory = librdiff.getBackupHistory(
                joinPaths(self.userDB.getUserRoot(self.getUsername()), repo))
        except librdiff.FileError, error:
            return self.writeErrorPage(error.getErrorString())

        rdiffHistory.reverse()
        entries = []
        for historyItem in rdiffHistory:
            entries.append({
                "date":
                historyItem.date.getDisplayString(),
                "errors":
                historyItem.errors,
                "size":
                rdw_helpers.formatFileSizeStr(historyItem.size)
            })
        page = page + self.compileTemplate("history.html",
                                           title="Backup history for " + repo,
                                           history=entries)
        page = page + self.endPage()
        return page

    index.exposed = True
Esempio n. 20
0
    def getParmsForPage(self, userRoot, repo="", path="", restore=""):
        repo = encodePath(repo)
        path = encodePath(path)
        # Build "parent directories" links
        parentDirs = []
        parentDirs.append({
            "parentPath": self.buildBrowseUrl(repo, "/", False),
            "parentDir": repo.lstrip("/")
        })
        parentDirPath = "/"
        for parentDir in path.split("/"):
            if parentDir:
                parentDirPath = joinPaths(parentDirPath, parentDir)
                parentDirs.append({
                    "parentPath":
                    self.buildBrowseUrl(repo, parentDirPath, False),
                    "parentDir":
                    parentDir
                })
        parentDirs[-1][
            "parentPath"] = ""  # Clear link for last parent, so it doesn't show it as a link

        # Set up warning about in-progress backups, if necessary
        if librdiff.backupIsInProgressForRepo(joinPaths(userRoot, repo)):
            backupWarning = "Warning: a backup is currently in progress to this location.  The displayed data may be inconsistent."
        else:
            backupWarning = ""

        restoreUrl = ""
        viewUrl = ""
        if restore == "T":
            title = "Restore"
            viewUrl = self.buildBrowseUrl(repo, path, False)
            tempDates = librdiff.getDirRestoreDates(joinPaths(userRoot, repo),
                                                    path)
            tempDates.reverse()  # sort latest first
            restoreDates = []
            for x in tempDates:
                restoreDates.append({
                    "dateStr":
                    x.getDisplayString(),
                    "dirRestoreUrl":
                    self.buildRestoreUrl(repo, path, x)
                })
            entries = []
        else:
            title = "Browse"
            restoreUrl = self.buildBrowseUrl(repo, path, True)
            restoreDates = []

            # Get list of actual directory entries
            fullRepoPath = joinPaths(userRoot, repo)
            libEntries = librdiff.getDirEntries(fullRepoPath, path)

            entries = []
            for libEntry in libEntries:
                entryLink = ""
                if libEntry.isDir:
                    entryLink = self.buildBrowseUrl(
                        repo, joinPaths(path, libEntry.name), False)
                    fileType = "folder"
                    size = " "
                    sizeinbytes = 0
                    changeDates = []
                else:
                    entryLink = self.buildRestoreUrl(
                        repo, joinPaths(path, libEntry.name),
                        libEntry.changeDates[-1])
                    fileType = "file"
                    entryChangeDates = libEntry.changeDates[:-1]
                    entryChangeDates.reverse()
                    size = rdw_helpers.formatFileSizeStr(libEntry.fileSize)
                    sizeinbytes = libEntry.fileSize
                    changeDates = [{
                        "changeDateUrl":
                        self.buildRestoreUrl(repo,
                                             joinPaths(path, libEntry.name),
                                             x),
                        "changeDateStr":
                        x.getDisplayString()
                    } for x in entryChangeDates]

                showRevisionsText = (len(changeDates) > 0) or libEntry.isDir
                entries.append({
                    "filename":
                    libEntry.name,
                    "fileRestoreUrl":
                    entryLink,
                    "filetype":
                    fileType,
                    "exists":
                    libEntry.exists,
                    "date":
                    libEntry.changeDates[-1].getDisplayString(),
                    "dateinseconds":
                    libEntry.changeDates[-1].getLocalSeconds(),
                    "size":
                    size,
                    "sizeinbytes":
                    sizeinbytes,
                    "hasPrevRevisions":
                    len(changeDates) > 0,
                    "numPrevRevisions":
                    str(len(changeDates)),
                    "hasMultipleRevisions":
                    len(changeDates) > 1,
                    "showRevisionsText":
                    showRevisionsText,
                    "changeDates":
                    changeDates
                })

        return {
            "title": title,
            "files": entries,
            "parentDirs": parentDirs,
            "restoreUrl": restoreUrl,
            "viewUrl": viewUrl,
            "restoreDates": restoreDates,
            "warning": backupWarning
        }
class rdiffHistoryPage(page_main.rdiffPage):
   def index(self, repo):
      repo = rdw_helpers.decodeUrl(repo)
      try:
         rdw_helpers.ensurePathValid(repo)
      except rdw_helpers.accessDeniedError, error:
         return self.writeErrorPage(str(error))

      if not repo: return self.writeErrorPage("Backup location not specified.")
      if not repo in self.userDB.getUserRepoPaths(self.getUsername()):
         return self.writeErrorPage("Access is denied.")

      page = self.startPage("Backup History")
      page = page + self.writeTopLinks()
      try:
         rdiffHistory = librdiff.getBackupHistory(joinPaths(self.userDB.getUserRoot(self.getUsername()), repo))
      except librdiff.FileError, error:
         return self.writeErrorPage(error.getErrorString())

      rdiffHistory.reverse()
      entries = []
      for historyItem in rdiffHistory:
         entries.append({ "date" : historyItem.date.getDisplayString(),
                          "errors" : historyItem.errors,
                          "size" : rdw_helpers.formatFileSizeStr(historyItem.size) })
      page = page + self.compileTemplate("history.html", title="Backup history for "+repo, history=entries)
      page = page + self.endPage()
      return page
   index.exposed = True
Esempio n. 22
0
   def getParmsForPage(self, userRoot, repo="", path="", restore=""):
      # Build "parent directories" links
      parentDirs = [{ "parentPath" : self.buildLocationsUrl(), "parentDir" : "Backup Locations" }]
      parentDirs.append({ "parentPath" : self.buildBrowseUrl(repo, "/", False), "parentDir" : repo.lstrip("/") })
      parentDirPath = "/"
      for parentDir in path.split("/"):
         if parentDir:
            parentDirPath = joinPaths(parentDirPath, parentDir)
            parentDirs.append({ "parentPath" : self.buildBrowseUrl(repo, parentDirPath, False), "parentDir" : parentDir })
      parentDirs[-1]["parentPath"] = "" # Clear link for last parent, so it doesn't show it as a link

      # Set up warning about in-progress backups, if necessary
      if librdiff.backupIsInProgressForRepo(joinPaths(userRoot, repo)):
         backupWarning = "Warning: a backup is currently in progress to this location.  The displayed data may be inconsistent."
      else:
         backupWarning = ""

      restoreUrl = ""
      viewUrl = ""
      if restore == "T":
         title = "Restore "+repo
         viewUrl = self.buildBrowseUrl(repo, path, False)
         restoreDates = librdiff.getDirRestoreDates(joinPaths(userRoot, repo), path)
         restoreDates.reverse() # sort latest first
         restoreDates = [ { "dateStr" : x.getDisplayString(), "dirRestoreUrl" : self.buildRestoreUrl(repo, path, x) }
                         for x in restoreDates ]
         entries = []
      else:
         title = "Browse "+repo
         restoreUrl = self.buildBrowseUrl(repo, path, True)
         restoreDates = []

         # Get list of actual directory entries
         fullRepoPath = joinPaths(userRoot, repo)
         libEntries = librdiff.getDirEntries(fullRepoPath, path)

         entries = []
         for libEntry in libEntries:
            altEntry = (len(entries) % 2 != 0)
            entryLink = ""
            if libEntry.isDir:
               entryLink = self.buildBrowseUrl(repo, joinPaths(path, libEntry.name), False)
               fileType = "folder"
               fileSize= " "
               changeDates = []
            else:
               entryLink = self.buildRestoreUrl(repo, joinPaths(path, libEntry.name), libEntry.changeDates[-1])
               fileType = "file"
               entryChangeDates = libEntry.changeDates[:-1]
               entryChangeDates.reverse()
               fileSize = rdw_helpers.formatFileSizeStr(libEntry.fileSize)
               changeDates = [ { "changeDateUrl" : self.buildRestoreUrl(repo, joinPaths(path, libEntry.name), x),
                                 "changeDateStr" : x.getDisplayString() } for x in entryChangeDates]

            showRevisionsText = (len(changeDates) > 0) or libEntry.isDir
            entries.append({ "filename" : libEntry.name,
                           "fileRestoreUrl" : entryLink,
                           "filetype" : fileType,
                           "exists" : libEntry.exists,
                           "date" : libEntry.changeDates[-1].getDisplayString(),
                           "size" : fileSize,
                           "hasPrevRevisions" : len(changeDates) > 0,
                           "numPrevRevisions" : str(len(changeDates)), 
                           "hasMultipleRevisions" : len(changeDates) > 1,
                           "showRevisionsText" : showRevisionsText,
                           "changeDates" : changeDates,
                           "altRow": altEntry })

      return { "title" : title, "files" : entries, "parentDirs" : parentDirs, "restoreUrl" : restoreUrl, "viewUrl" : viewUrl, "restoreDates" : restoreDates, "warning" : backupWarning }
Esempio n. 23
0
    def getParmsForPage(self,
                        root,
                        repos,
                        allowRepoDeletion=False,
                        message='',
                        error=''):
        repoList = []
        for userRepo in repos:
            try:
                repoHistory = librdiff.getLastBackupHistoryEntry(
                    rdw_helpers.joinPaths(root, userRepo))
            except librdiff.FileError:
                repoSize = "0"
                repoDate = "Error"
                repoList.append({
                    "repoName":
                    userRepo,
                    "repoSize":
                    repoSize,
                    "repoDate":
                    repoDate,
                    "repoBrowseUrl":
                    self.buildBrowseUrl(userRepo, "/", False),
                    "repoHistoryUrl":
                    self.buildHistoryUrl(userRepo),
                    'failed':
                    True
                })
            else:
                repoSize = rdw_helpers.formatFileSizeStr(repoHistory.size)
                if repoHistory.inProgress:
                    repoSize = "In Progress"
                repoDate = repoHistory.date.getDisplayString()
                repoList.append({
                    "repoName":
                    userRepo,
                    "repoSize":
                    repoSize,
                    "repoDate":
                    repoDate,
                    "repoBrowseUrl":
                    self.buildBrowseUrl(userRepo, "/", False),
                    "repoHistoryUrl":
                    self.buildHistoryUrl(userRepo),
                    'failed':
                    False
                })

        self._sortLocations(repoList)
        # Make second pass through list, setting the 'altRow' attribute
        for i in range(0, len(repoList)):
            repoList[i]['altRow'] = (i % 2 == 0)
        # Calculate disk usage
        diskUsage = ''
        diskUsageCommand = rdw_config.getConfigSetting('diskUsageCommand')
        if diskUsageCommand:
            diskUsage = subprocess.Popen(
                [
                    diskUsageCommand,
                    self.getUsername(),
                    self.getUserDB().getUserRoot(self.getUsername())
                ],
                stdout=subprocess.PIPE).communicate()[0]
            try:
                diskUsageNum = int(diskUsage)
            except:
                pass
            else:
                diskUsage = rdw_helpers.formatFileSizeStr(diskUsageNum)
        # Allow repository deletion?
        return {
            "title": "browse",
            "repos": repoList,
            "diskUsage": diskUsage,
            "allowRepoDeletion": allowRepoDeletion,
            "message": message,
            "error": error
        }
Esempio n. 24
0
class rdiffBrowsePage(page_main.rdiffPage):
   def index(self, repo="", path="", restore=""):

      repo = rdw_helpers.decodeUrl(repo)
      path = rdw_helpers.decodeUrl(path)
      restore = rdw_helpers.decodeUrl(restore)
      try:
         rdw_helpers.ensurePathValid(repo)
         rdw_helpers.ensurePathValid(path)
      except rdw_helpers.accessDeniedError, error:
         return self.writeErrorPage(str(error))

      # NOTE: a blank path parm is allowed, since that just results in a listing of the repo root
      if not repo: return self.writeErrorPage("Backup location not specified.")
      if not repo in self.userDB.getUserRepoPaths(self.getUsername()):
         return self.writeErrorPage("Access is denied.")

      # Build "parent directories" links
      parentDirs = [{ "parentPath" : self.buildLocationsUrl(), "parentDir" : "Backup Locations" }]
      parentDirs.append({ "parentPath" : self.buildBrowseUrl(repo, "/", False), "parentDir" : repo.lstrip("/") })
      parentDirPath = "/"
      for parentDir in path.split("/"):
         if parentDir:
            parentDirPath = joinPaths(parentDirPath, parentDir)
            parentDirs.append({ "parentPath" : self.buildBrowseUrl(repo, parentDirPath, False), "parentDir" : parentDir })
      parentDirs[-1]["parentPath"] = "" # Clear link for last parent, so it doesn't show it as a link

      # Set up warning about in-progress backups, if necessary
      if librdiff.backupIsInProgress(joinPaths(self.userDB.getUserRoot(self.getUsername()), repo)):
         backupWarning = "Warning: a backup is currently in progress to this location.  The displayed data may be inconsistent."
      else:
         backupWarning = ""

      restoreUrl = ""
      viewUrl = ""
      if restore == "T":
         title = "Restore "+repo
         viewUrl = self.buildBrowseUrl(repo, path, False)
         restoreDates = librdiff.getDirRestoreDates(joinPaths(self.userDB.getUserRoot(self.getUsername()), repo), path)
         restoreDates.reverse() # sort latest first
         restoreDates = [ { "dateStr" : x.getDisplayString(), "dirRestoreUrl" : self.buildRestoreUrl(repo, path, x) }
                         for x in restoreDates ]
         entries = []
      else:
         title = "Browse "+repo
         restoreUrl = self.buildBrowseUrl(repo, path, True)
         restoreDates = []

         # Get list of actual directory entries
         try:
            fullRepoPath = joinPaths(self.userDB.getUserRoot(self.getUsername()), repo)
            libEntries = librdiff.getDirEntries(fullRepoPath, path)
         except librdiff.FileError, error:
            return self.writeErrorPage(str(error))

         entries = []
         for libEntry in libEntries:
            entryLink = ""
            if libEntry.isDir:
               entryLink = self.buildBrowseUrl(repo, joinPaths(path, libEntry.name), False)
               changeDates = []
            else:
               entryLink = self.buildRestoreUrl(repo, joinPaths(path, libEntry.name), libEntry.changeDates[-1])
               entryChangeDates = libEntry.changeDates[:-1]
               entryChangeDates.reverse()
               changeDates = [ { "changeDateUrl" : self.buildRestoreUrl(repo, joinPaths(path, libEntry.name), x),
                                 "changeDateStr" : x.getDisplayString() } for x in entryChangeDates]

            showNoRevisionsText = (len(changeDates) == 0) and (not libEntry.isDir)
            entries.append({ "filename" : libEntry.name,
                           "fileRestoreUrl" : entryLink,
                           "exists" : libEntry.exists,
                           "date" : libEntry.changeDates[-1].getDisplayString(),
                           "size" : rdw_helpers.formatFileSizeStr(libEntry.fileSize),
                           "hasPrevRevisions" : len(changeDates) > 0,
                           "showNoRevisionsText" : showNoRevisionsText,
                           "changeDates" : changeDates })
Esempio n. 25
0
         if libEntry.isDir:
            entryLink = self.buildBrowseUrl(repo, joinPaths(path, libEntry.name))
            changeDates = []
         else:
            entryLink = self.buildRestoreUrl(repo, joinPaths(path, libEntry.name), libEntry.changeDates[-1])
            entryChangeDates = libEntry.changeDates[:-1]
            entryChangeDates.reverse()
            changeDates = [ { "changeDateUrl" : self.buildRestoreUrl(repo, joinPaths(path, libEntry.name), x),
                              "changeDateStr" : x.getDisplayString() } for x in entryChangeDates]

         showNoRevisionsText = (len(changeDates) == 0) and (not libEntry.isDir)
         entries.append({ "filename" : libEntry.name,
                          "fileRestoreUrl" : entryLink,
                          "exists" : libEntry.exists,
                          "date" : libEntry.changeDates[-1].getDisplayString(),
                          "size" : rdw_helpers.formatFileSizeStr(libEntry.fileSize),
                          "hasPrevRevisions" : len(changeDates) > 0,
                          "showNoRevisionsText" : showNoRevisionsText,
                          "changeDates" : changeDates })

      # Start page
      title = "Browse "+repo
      page = self.startPage(title)
      page = page + self.writeTopLinks()
      page = page + self.compileTemplate("dir_listing.html", title=title, files=entries, parentDirs=parentDirs)
      page = page + self.endPage()
      return page

   index.exposed = True