def get_signature_chain_at_time(self, time): """ Return signature chain covering specified time Tries to find the signature chain covering the given time. If there is none, return the earliest chain before, and failing that, the earliest chain. """ if not self.all_sig_chains: raise CollectionsError("No signature chains found") covering_chains = [c for c in self.all_sig_chains if c.start_time <= time <= c.end_time] if covering_chains: return covering_chains[-1] # prefer local if multiple sig chains old_chains = [c for c in self.all_sig_chains if c.end_time < time] if old_chains: return old_chains[-1] else: # no chains are old enough, give oldest and warn user oldest = self.all_sig_chains[0] if time < oldest.start_time: log.Warn(_("No signature chain for the requested time. " "Using oldest available chain, starting at time %s.") % dup_time.timetopretty(oldest.start_time), log.WarningCode.no_sig_for_time, dup_time.timetostring(oldest.start_time)) return oldest
def testStringtotime(self): """Test converting string to time""" timesec = int(time.time()) assert timesec == int(dup_time.stringtotime(dup_time.timetostring(timesec))) assert not dup_time.stringtotime("2001-18-83T03:03:03Z") assert not dup_time.stringtotime("2001-01-23L03:03:03L") assert not dup_time.stringtotime("2001_01_23T03:03:03Z")
def testStringtotime(self): u"""Test converting string to time""" timesec = int(time.time()) assert timesec == int(dup_time.stringtotime(dup_time.timetostring(timesec))) assert not dup_time.stringtotime(u"2001-18-83T03:03:03Z") assert not dup_time.stringtotime(u"2001-01-23L03:03:03L") assert not dup_time.stringtotime(u"2001_01_23T03:03:03Z")
def testConversion(self): u"""test timetostring and stringtotime""" dup_time.setcurtime() assert type(dup_time.curtime) in integer_types assert isinstance(dup_time.curtimestr, (str, u"".__class__)) assert (dup_time.cmp(int(dup_time.curtime), dup_time.curtimestr) == 0 or dup_time.cmp(int(dup_time.curtime) + 1, dup_time.curtimestr) == 0) time.sleep(1.05) assert dup_time.cmp(time.time(), dup_time.curtime) == 1 assert dup_time.cmp(dup_time.timetostring(time.time()), dup_time.curtimestr) == 1
def testConversion(self): """test timetostring and stringtotime""" dup_time.setcurtime() assert type(dup_time.curtime) in (types.IntType, types.LongType) assert type(dup_time.curtimestr) is types.StringType assert (dup_time.cmp(int(dup_time.curtime), dup_time.curtimestr) == 0 or dup_time.cmp(int(dup_time.curtime) + 1, dup_time.curtimestr) == 0) time.sleep(1.05) assert dup_time.cmp(time.time(), dup_time.curtime) == 1 assert dup_time.cmp(dup_time.timetostring(time.time()), dup_time.curtimestr) == 1
def testConversion(self): """test timetostring and stringtotime""" dup_time.setcurtime() assert type(dup_time.curtime) in integer_types assert isinstance(dup_time.curtimestr, types.StringType) assert (dup_time.cmp(int(dup_time.curtime), dup_time.curtimestr) == 0 or dup_time.cmp(int(dup_time.curtime) + 1, dup_time.curtimestr) == 0) time.sleep(1.05) assert dup_time.cmp(time.time(), dup_time.curtime) == 1 assert dup_time.cmp(dup_time.timetostring(time.time()), dup_time.curtimestr) == 1
def testConversion(self): """test timetostring and stringtotime""" dup_time.setcurtime() assert type(dup_time.curtime) in (types.IntType, types.LongType) assert type(dup_time.curtimestr) is types.StringType assert (dup_time.cmp(int(dup_time.curtime), dup_time.curtimestr) == 0 or dup_time.cmp( int(dup_time.curtime) + 1, dup_time.curtimestr) == 0) time.sleep(1.05) assert dup_time.cmp(time.time(), dup_time.curtime) == 1 assert dup_time.cmp(dup_time.timetostring(time.time()), dup_time.curtimestr) == 1
def to_log_info(self, prefix=''): """ Return summary, suitable for printing to log """ l = [] for s in self.get_all_sets(): if s.time: type = "full" time = s.time else: type = "inc" time = s.end_time enc = "enc" if s.encrypted else "noenc" l.append("%s%s %s %d %s" % (prefix, type, dup_time.timetostring(time), (len(s)), enc)) return l
def to_log_info(self, prefix=''): """ Return summary, suitable for printing to log """ l = [] for s in self.get_all_sets(): if s.time: type = "full" time = s.time else: type = "inc" time = s.end_time if s.encrypted: enc = "enc" else: enc = "noenc" l.append("%s%s %s %d %s" % (prefix, type, dup_time.timetostring(time), (len(s)), enc)) return l
def testConvertion(self): t = int(time.time()) assert dup_time.stringtotime(dup_time.timetostring(t)) == t