wingo - in flumotion/trunk: . flumotion/component/base
flumotion/test
flumotion-commit at lists.fluendo.com
flumotion-commit at lists.fluendo.com
Mon May 14 18:26:34 CEST 2007
Author: wingo
Date: Mon May 14 18:26:31 2007
New Revision: 4943
Modified:
flumotion/trunk/ChangeLog
flumotion/trunk/flumotion/component/base/scheduler.py
flumotion/trunk/flumotion/test/test_component_base_scheduler.py
Log:
2007-05-14 Andy Wingo <wingo at pobox.com>
* flumotion/component/base/scheduler.py (Scheduler.addEvent): Add
a now argument.
(Scheduler.getCurrentEvents): New accessor.
(Scheduler._reschedule): Convert timedelta objects to seconds.
* flumotion/test/test_component_base_scheduler.py
(SchedulerTest.testSimple): Test some more scheduler bits.
Modified: flumotion/trunk/ChangeLog
==============================================================================
--- flumotion/trunk/ChangeLog (original)
+++ flumotion/trunk/ChangeLog Mon May 14 18:26:31 2007
@@ -1,3 +1,13 @@
+2007-05-14 Andy Wingo <wingo at pobox.com>
+
+ * flumotion/component/base/scheduler.py (Scheduler.addEvent): Add
+ a now argument.
+ (Scheduler.getCurrentEvents): New accessor.
+ (Scheduler._reschedule): Convert timedelta objects to seconds.
+
+ * flumotion/test/test_component_base_scheduler.py
+ (SchedulerTest.testSimple): Test some more scheduler bits.
+
2007-05-14 Michael Smith <msmith at fluendo.com>
* flumotion/component/producers/playlist/playlist.py:
Modified: flumotion/trunk/flumotion/component/base/scheduler.py
==============================================================================
--- flumotion/trunk/flumotion/component/base/scheduler.py (original)
+++ flumotion/trunk/flumotion/component/base/scheduler.py Mon May 14 18:26:31 2007
@@ -89,7 +89,7 @@
self.subscribers = {}
self.replaceEvents([])
- def addEvent(self, start, end, content, recur=None):
+ def addEvent(self, start, end, content, recur=None, now=None):
"""Add a new event to the scheduler.
@param start: wall-clock time of event start
@@ -105,7 +105,8 @@
so desired. The event will be removed or rescheduled
automatically when it stops.
"""
- now = datetime.now()
+ if now is None:
+ now = datetime.now()
event = Event(start, end, content, recur, now)
if event.end < now:
self.warning('attempted to schedule event in the past: %r',
@@ -129,6 +130,9 @@
self._eventStopped(currentEvent)
self._reschedule()
+ def getCurrentEvents(self):
+ return [e.content for e in self.current]
+
def replaceEvents(self, events):
"""Replace the set of events in the scheduler.
@@ -230,12 +234,15 @@
stop = _getNextStop()
now = datetime.now()
+ def toSeconds(td):
+ return max(td.days*24*3600 + td.seconds + td.microseconds/1e6, 0)
+
if start and (not stop or start.start < stop.end):
- dc = reactor.callLater(max (start.start - now, 0), doStart,
- start)
+ dc = reactor.callLater(toSeconds(start.start - now),
+ doStart, start)
elif stop:
- dc = reactor.callLater(max (stop.end - now, 0), doStop,
- stop)
+ dc = reactor.callLater(toSeconds(stop.end - now),
+ doStop, stop)
else:
dc = None
Modified: flumotion/trunk/flumotion/test/test_component_base_scheduler.py
==============================================================================
--- flumotion/trunk/flumotion/test/test_component_base_scheduler.py (original)
+++ flumotion/trunk/flumotion/test/test_component_base_scheduler.py Mon May 14 18:26:31 2007
@@ -80,3 +80,30 @@
class SchedulerTest(unittest.TestCase):
def testInstantiate(self):
scheduler.Scheduler()
+
+ def testSimple(self):
+ now = datetime.now()
+ start = now - timedelta(hours=1)
+ end = now + timedelta(minutes=1)
+
+ calls = []
+ started = lambda c: calls.append(('started', c))
+ stopped = lambda c: calls.append(('stopped', c))
+
+ s = scheduler.Scheduler()
+ sid = s.subscribe(started, stopped)
+
+ self.assertEquals(calls, [])
+
+ e = s.addEvent(start, end, 'foo', now=now)
+
+ self.assertEquals(calls, [('started', 'foo')])
+ self.assertEquals(s.getCurrentEvents(), ['foo'])
+
+ s.removeEvent(e)
+
+ self.assertEquals(calls, [('started', 'foo'),
+ ('stopped', 'foo')])
+ self.assertEquals(s.getCurrentEvents(), [])
+
+ s.unsubscribe(sid)
More information about the flumotion-commit
mailing list