wingo - in flumotion/branches/platform-3: . flumotion/component/base
flumotion-commit at lists.fluendo.com
flumotion-commit at lists.fluendo.com
Wed Jun 13 15:56:13 CEST 2007
Author: wingo
Date: Wed Jun 13 15:56:04 2007
New Revision: 5169
Modified:
flumotion/branches/platform-3/ (props changed)
flumotion/branches/platform-3/ChangeLog
flumotion/branches/platform-3/flumotion/component/base/scheduler.py
Log:
svnmerge -r 5168
Modified: flumotion/branches/platform-3/ChangeLog
==============================================================================
--- flumotion/branches/platform-3/ChangeLog (original)
+++ flumotion/branches/platform-3/ChangeLog Wed Jun 13 15:56:04 2007
@@ -1,3 +1,15 @@
+2007-06-13 Andy Wingo <wingo at pobox.com>
+
+ * flumotion/test/test_component_base_scheduler.py
+ (SchedulerTest.testSimple): Add test.
+
+ * flumotion/component/base/scheduler.py (Event.__repr__): Add a
+ nice repr.
+ (EventStore): New class inheriting from AVLTree, warns when an
+ identical event is added instead of throwing an exception.
+ (Scheduler.replaceEvents): Use EventStore rather than the base
+ AVLTree.
+
2007-06-13 Zaheer Abbas Merali <zaheerabbas at merali dot org>
* flumotion/component/feedcomponent.py
Modified: flumotion/branches/platform-3/flumotion/component/base/scheduler.py
==============================================================================
--- flumotion/branches/platform-3/flumotion/component/base/scheduler.py (original)
+++ flumotion/branches/platform-3/flumotion/component/base/scheduler.py Wed Jun 13 15:56:04 2007
@@ -113,6 +113,9 @@
def toTuple(self):
return self.start, self.end, self.content, self.recur
+ def __repr__(self):
+ return '<Event %r>' % (self.toTuple(),)
+
def __lt__(self, other):
return self.toTuple() < other.toTuple()
@@ -123,6 +126,22 @@
return self.toTuple() == other.toTuple()
+class EventStore(avltree.AVLTree, log.Loggable):
+ def __init__(self, events):
+ avltree.AVLTree.__init__(self)
+ for event in events:
+ self.insert(event)
+
+ def insert(self, event):
+ try:
+ avltree.AVLTree.insert(self, event)
+ return True
+ except ValueError:
+ self.warning('an identical event to %r already exists in '
+ 'store', event)
+ return False
+
+
class Scheduler(log.Loggable):
"""
I keep track of upcoming events.
@@ -161,10 +180,10 @@
self.warning('attempted to schedule event in the past: %r',
event)
else:
- self.events.insert(event)
- if event.start < now:
- self._eventStarted(event)
- self._reschedule()
+ if self.events.insert(event):
+ if event.start < now:
+ self._eventStarted(event)
+ self._reschedule()
return event
def removeEvent(self, event):
@@ -192,9 +211,9 @@
now = datetime.now()
for event in events:
if event.end > now:
- self.events.insert(event)
- if event.start < now:
- self._eventStarted(event)
+ if self.events.insert(event):
+ if event.start < now:
+ self._eventStarted(event)
if events:
self._reschedule()
@@ -209,7 +228,7 @@
@type events: a sequence of Event
"""
now = datetime.now(LOCAL)
- self.events = avltree.AVLTree(events)
+ self.events = EventStore(events)
current = []
for event in self.events:
if now < event.start:
More information about the flumotion-commit
mailing list