예제 #1
0
    def test_time_from_session(self):
        """Test getting time from session number (as in Time.time_from_session)

        Test here instead of in timetest because it depends on an
        rdiff-backup-data directory already being laid out.

        """
        restore.MirrorStruct._mirror_time = None  # Reset
        Globals.rbdir = rpath.RPath(
            lc,
            os.path.join(old_test_dir, b"restoretest3", b"rdiff-backup-data"))
        assert Time.genstrtotime("0B") == Time.time_from_session(0)
        assert Time.genstrtotime("2B") == Time.time_from_session(2)
        assert Time.genstrtotime("23B") == Time.time_from_session(23)

        assert Time.time_from_session(0) == 40000, Time.time_from_session(0)
        assert Time.time_from_session(2) == 20000, Time.time_from_session(2)
        assert Time.time_from_session(5) == 10000, Time.time_from_session(5)
예제 #2
0
    def _get_parsed_time(self, timestr, ref_rp=None):
        """
        Parse time string, potentially using the given remote path as reference

        Returns None if the time string couldn't be parsed, else the time in
        seconds.
        The reference remote path is used when the time string consists in a
        number of past backups.
        """
        try:
            if Globals.get_api_version() < 201:  # compat200
                return Time.genstrtotime(timestr, rp=ref_rp)
            else:
                sessions = self.repo.get_increment_times(ref_rp)
                return Time.genstrtotime(timestr, session_times=sessions)
        except Time.TimeException as exc:
            log.Log("Time string '{ts}' couldn't be parsed "
                    "due to '{ex}'".format(ts=timestr, ex=exc), log.ERROR)
            return None
예제 #3
0
    def _get_parsed_time(self, timestr, ref_rp=None):
        """
        Parse time string, potentially using the given remote path as reference

        Returns None if the time string couldn't be parsed, else the time in
        seconds.
        The reference remote path is used when the time string consists in a
        number of past backups.
        """
        try:
            return Time.genstrtotime(timestr, rp=ref_rp)
        except Time.TimeException as exc:
            log.Log("Time string '{ts}' couldn't be parsed "
                    "due to '{ex}'".format(ts=timestr, ex=exc), log.ERROR)
            return None