[CalendarServer-changes] [1040]
CalendarServer/branches/users/cdaboo/availability-1018/twistedcaldav
source_changes at macosforge.org
source_changes at macosforge.org
Fri Jan 12 11:49:16 PST 2007
Revision: 1040
http://trac.macosforge.org/projects/calendarserver/changeset/1040
Author: cdaboo at apple.com
Date: 2007-01-12 11:49:16 -0800 (Fri, 12 Jan 2007)
Log Message:
-----------
Make sure AVAILABLE components "unblock" VAVAILABILITY busy blocks.
Modified Paths:
--------------
CalendarServer/branches/users/cdaboo/availability-1018/twistedcaldav/instance.py
CalendarServer/branches/users/cdaboo/availability-1018/twistedcaldav/method/report_common.py
Modified: CalendarServer/branches/users/cdaboo/availability-1018/twistedcaldav/instance.py
===================================================================
--- CalendarServer/branches/users/cdaboo/availability-1018/twistedcaldav/instance.py 2007-01-12 19:44:11 UTC (rev 1039)
+++ CalendarServer/branches/users/cdaboo/availability-1018/twistedcaldav/instance.py 2007-01-12 19:49:16 UTC (rev 1040)
@@ -136,6 +136,12 @@
self._addFreeBusyComponent(component, limit)
elif component.name() == "VAVAILABILITY":
self._addAvailabilityComponent(component, limit)
+ elif component.name() == "AVAILABLE":
+ if component.hasProperty("RECURRENCE-ID"):
+ overrides.append(component)
+ else:
+ # AVAILABLE components are just like VEVENT components
+ self._addMasterEventComponent(component, limit)
for component in overrides:
if component.name() == "VEVENT":
@@ -145,6 +151,9 @@
elif component.name() == "VJOURNAL":
#TODO: VJOURNAL
raise NotImplementedError("VJOURNAL recurrence expansion not supported yet")
+ elif component.name() == "AVAILABLE":
+ # AVAILABLE components are just like VEVENT components
+ self._addOverrideEventComponent(component)
def addInstance(self, instance):
"""
Modified: CalendarServer/branches/users/cdaboo/availability-1018/twistedcaldav/method/report_common.py
===================================================================
--- CalendarServer/branches/users/cdaboo/availability-1018/twistedcaldav/method/report_common.py 2007-01-12 19:44:11 UTC (rev 1039)
+++ CalendarServer/branches/users/cdaboo/availability-1018/twistedcaldav/method/report_common.py 2007-01-12 19:49:16 UTC (rev 1040)
@@ -43,6 +43,7 @@
from twistedcaldav.caldavxml import caldav_namespace
from twistedcaldav.dateops import clipPeriod, normalizePeriodList, timeRangesOverlap
from twistedcaldav.ical import Component, Property, iCalendarProductID
+from twistedcaldav.instance import InstanceList
from vobject.icalendar import utc
@@ -470,7 +471,6 @@
@param timerange: the time range to restrict free busy data to.
"""
- tempfbinfo = ([], [], [])
for vav in [x for x in calendar.subcomponents() if x.name() == "VAVAILABILITY"]:
# Get overall start/end
@@ -487,16 +487,72 @@
# Now get periods for each instance of AVAILABLE sub-components
periods = processAvailablePeriods(vav, timerange)
+
+ # Now invert the periods and store in accumulator
+ busyperiods = []
+ last_end = timerange.start
+ for period in periods:
+ if last_end < period[0]:
+ busyperiods.append((last_end, period[0]))
+ last_end = period[1]
+ if last_end < timerange.end:
+ busyperiods.append((last_end, timerange.end))
+ # Add to actual results mapped by busy type
+ fbtype = vav.propertyValue("BUSYTYPE")
+ if fbtype is None:
+ fbtype = "BUSY-UNAVAILABLE"
+
+ mapper = {"BUSY": 0, "BUSY-TENTATIVE": 1, "BUSY-UNAVAILABLE": 2}
+ fbinfo[mapper.get(fbtype, 2)].extend(busyperiods)
+
+
def processAvailablePeriods(calendar, timerange):
"""
Extract instance period data from an AVAILABLE component.
@param calendar: the L{Component} that is the VAVAILABILITY containing the AVAILABLE's.
- @param fbinfo: the tuple used to store the three types of fb data.
@param timerange: the time range to restrict free busy data to.
"""
- pass
+
+ periods = []
+ # First we need to group all AVAILABLE sub-components by UID
+ uidmap = {}
+ for component in calendar.subcomponents():
+ if component.name() == "AVAILABLE":
+ uid = component.propertyValue("UID")
+ uidmap.setdefault(uid, []).append(component)
+
+ # Then we expand each uid set seperately
+ for componentSet in uidmap.itervalues():
+ instances = InstanceList()
+ instances.expandTimeRanges(componentSet, timerange.end)
+
+ # Now convert instances into period list
+ for key in instances:
+ instance = instances[key]
+ # Ignore any with floating times (which should not happen as the spec requires UTC or local
+ # but we will try and be safe here).
+ start = instance.start
+ if start.tzinfo is None:
+ continue
+ end = instance.end
+ if end.tzinfo is None:
+ continue
+
+ # Clip period for this instance - use duration for period end if that
+ # is what original component used
+ if instance.component.hasProperty("DURATION"):
+ period = (start, end - start)
+ else:
+ period = (start, end)
+ clipped = clipPeriod(period, (timerange.start, timerange.end))
+ if clipped:
+ periods.append(clipped)
+
+ normalizePeriodList(periods)
+ return periods
+
def buildFreeBusyResult(fbinfo, timerange, organizer=None, attendee=None, uid=None):
"""
Generate a VCALENDAR object containing a single VFREEBUSY that is the
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20070112/1098d175/attachment.html
More information about the calendarserver-changes
mailing list