[CalendarServer-changes] [6703] CalendarServer/branches/users/cdaboo/batchupload-6699/twistedcaldav/ storebridge.py

source_changes at macosforge.org source_changes at macosforge.org
Mon Dec 20 13:06:39 PST 2010


Revision: 6703
          http://trac.macosforge.org/projects/calendarserver/changeset/6703
Author:   cdaboo at apple.com
Date:     2010-12-20 13:06:35 -0800 (Mon, 20 Dec 2010)
Log Message:
-----------
Properly handle splitting up a VCALENDAR object into multiple VCALENDARs by UID for simple batch POST processing.

Modified Paths:
--------------
    CalendarServer/branches/users/cdaboo/batchupload-6699/twistedcaldav/storebridge.py

Modified: CalendarServer/branches/users/cdaboo/batchupload-6699/twistedcaldav/storebridge.py
===================================================================
--- CalendarServer/branches/users/cdaboo/batchupload-6699/twistedcaldav/storebridge.py	2010-12-20 15:12:50 UTC (rev 6702)
+++ CalendarServer/branches/users/cdaboo/batchupload-6699/twistedcaldav/storebridge.py	2010-12-20 21:06:35 UTC (rev 6703)
@@ -35,7 +35,8 @@
 from twistedcaldav import customxml, carddavxml, caldavxml
 from twistedcaldav.caldavxml import caldav_namespace
 from twistedcaldav.config import config
-from twistedcaldav.ical import Component as VCalendar, Property as VProperty
+from twistedcaldav.ical import Component as VCalendar, Property as VProperty,\
+    iCalendarProductID
 from twistedcaldav.memcachelock import MemcacheLock, MemcacheLockTimeoutError
 from twistedcaldav.method.put_addressbook_common import StoreAddressObjectResource
 from twistedcaldav.method.put_common import StoreCalendarObjectResource
@@ -936,8 +937,50 @@
 
     @classmethod
     def componentsFromData(cls, data):
-        return VCalendar.allFromString(data)
+        """
+        Need to split a single VCALENDAR into separate ones based on UID with the
+        appropriate VTIEMZONES included.
+        """
+        
+        results = []
 
+        # Split into components by UID and TZID
+        vcal =  VCalendar.fromString(data)
+        by_uid = {}
+        by_tzid = {}
+        for subcomponent in vcal.subcomponents():
+            if subcomponent.name() == "VTIMEZONE":
+                by_tzid[subcomponent.propertyValue("TZID")] = subcomponent
+            else:
+                by_uid.setdefault(subcomponent.propertyValue("UID"), []).append(subcomponent)
+        
+        # Re-constitute as separate VCALENDAR objects
+        for components in by_uid.values():
+            
+            newvcal = VCalendar("VCALENDAR")
+            newvcal.addProperty(VProperty("PRODID", vcal.propertyValue("PRODID")))
+            
+            # Get the set of TZIDs and include them
+            tzids = set()
+            for component in components:
+                tzids.update(component.timezoneIDs())
+            for tzid in tzids:
+                try:
+                    tz = by_tzid[tzid]
+                    newvcal.addComponent(tz)
+                except KeyError:
+                    # We ignore the error and generate invalid ics which someone will
+                    # complain about at some point
+                    pass
+            
+            # Now add each component
+            for component in components:
+                newvcal.addComponent(component)
+ 
+            results.append(newvcal)
+        
+        return results
+
     @classmethod
     def resourceSuffix(cls):
         return ".ics"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20101220/a81e95ae/attachment.html>


More information about the calendarserver-changes mailing list