def ConfigurePeriodicInform(self): """Commit changes to PeriodicInform parameters.""" if self._periodic_callback: self._periodic_callback.stop() self._periodic_callback = None if self._start_periodic_timeout: self.ioloop.remove_timeout(self._start_periodic_timeout) self._start_periodic_timeout = None # Delete the old periodic callback. if self._periodic_callback: self._periodic_callback.stop() self._periodic_callback = None if (self.config._PeriodicInformEnable and self.config._PeriodicInformInterval > 0): msec = self.config._PeriodicInformInterval * 1000 self._periodic_callback = PERIODIC_CALLBACK( self.start_periodic_session, msec, self.ioloop) if self.config._PeriodicInformTime: # PeriodicInformTime is just meant as an offset, not an actual time. # So if it's 25.5 hours in the future and the interval is 1 hour, then # the interesting part is the 0.5 hours, not the 25. # # timetuple might be in the past, but that's okay; the modulus # makes sure it's never negative. (ie. (-3 % 5) == 2, in python) timetuple = cwmpdate.parse( self.config._PeriodicInformTime).timetuple() offset = ((time.mktime(timetuple) - time.time()) % float(self.config._PeriodicInformInterval)) else: offset = 0.0 self._start_periodic_timeout = self.ioloop.add_timeout( datetime.timedelta(seconds=offset), self.StartPeriodicInform)
def ConfigurePeriodicInform(self): """Commit changes to PeriodicInform parameters.""" if self._periodic_callback: self._periodic_callback.stop() self._periodic_callback = None if self._start_periodic_timeout: self.ioloop.remove_timeout(self._start_periodic_timeout) self._start_periodic_timeout = None # Delete the old periodic callback. if self._periodic_callback: self._periodic_callback.stop() self._periodic_callback = None if (self.config._PeriodicInformEnable and self.config._PeriodicInformInterval > 0): msec = self.config._PeriodicInformInterval * 1000 self._periodic_callback = PERIODIC_CALLBACK(self.start_periodic_session, msec, self.ioloop) if self.config._PeriodicInformTime: # PeriodicInformTime is just meant as an offset, not an actual time. # So if it's 25.5 hours in the future and the interval is 1 hour, then # the interesting part is the 0.5 hours, not the 25. # # timetuple might be in the past, but that's okay; the modulus # makes sure it's never negative. (ie. (-3 % 5) == 2, in python) timetuple = cwmpdate.parse(self.config._PeriodicInformTime).timetuple() offset = ((time.mktime(timetuple) - time.time()) % float(self.config._PeriodicInformInterval)) else: offset = 0.0 self._start_periodic_timeout = self.ioloop.add_timeout( datetime.timedelta(seconds=offset), self.StartPeriodicInform)
def validate(self, obj, value): # pylint: disable=g-explicit-bool-comparison if value is None or value == '': return None try: f = float(value) except ValueError: return cwmpdate.parse(value) else: return datetime.datetime.utcfromtimestamp(f)
def testParse(self): dt = cwmpdate.parse('2012-01-12T00:20:03.217691Z') timestamp = calendar.timegm(dt.timetuple()) self.assertEqual(timestamp, 1326327603.0)