[CalendarServer-changes] [6367] CalendarServer/branches/users/glyph/more-deferreds-6/twistedcaldav

source_changes at macosforge.org source_changes at macosforge.org
Thu Sep 23 19:29:36 PDT 2010


Revision: 6367
          http://trac.macosforge.org/projects/calendarserver/changeset/6367
Author:   glyph at apple.com
Date:     2010-09-23 19:29:35 -0700 (Thu, 23 Sep 2010)
Log Message:
-----------
postCreateHome and makeChild must be async because their dependencies are

Modified Paths:
--------------
    CalendarServer/branches/users/glyph/more-deferreds-6/twistedcaldav/resource.py
    CalendarServer/branches/users/glyph/more-deferreds-6/twistedcaldav/storebridge.py

Modified: CalendarServer/branches/users/glyph/more-deferreds-6/twistedcaldav/resource.py
===================================================================
--- CalendarServer/branches/users/glyph/more-deferreds-6/twistedcaldav/resource.py	2010-09-24 02:28:28 UTC (rev 6366)
+++ CalendarServer/branches/users/glyph/more-deferreds-6/twistedcaldav/resource.py	2010-09-24 02:29:35 UTC (rev 6367)
@@ -1961,7 +1961,7 @@
             transaction, name)
         resource = cls(parent, name, transaction, home)
         if created:
-            resource.postCreateHome()
+            yield resource.postCreateHome()
         returnValue(resource)
 
 
@@ -2040,33 +2040,34 @@
     def canShare(self):
         raise NotImplementedError
 
+
+    @inlineCallbacks
     def makeChild(self, name):
-        
         # Try built-in children first
         if name in self._provisionedChildren:
             cls = self._provisionedChildren[name]
             from twistedcaldav.notifications import NotificationCollectionResource
             if cls is NotificationCollectionResource:
-                return self.createNotificationsCollection()
-            child = self._provisionedChildren[name](self)
+                returnValue((yield self.createNotificationsCollection()))
+            child = yield self._provisionedChildren[name](self)
             self.propagateTransaction(child)
             self.putChild(name, child)
-            return child
-        
+            returnValue(child)
+
         # Try built-in links next
         if name in self._provisionedLinks:
             child = LinkResource(self, self._provisionedLinks[name])
             self.putChild(name, child)
-            return child
-        
+            returnValue(child)
+
         # Try shares next
         if self.canShare():
-            child = self.provisionShare(name)
+            child = yield self.provisionShare(name)
             if child:
-                return child
+                returnValue(child)
 
         # Do normal child types
-        return self.makeRegularChild(name)
+        returnValue((yield self.makeRegularChild(name)))
 
     def createNotificationsCollection(self):
         
@@ -2258,7 +2259,7 @@
 
         # Cache children which must be of a specific type
         from twistedcaldav.storebridge import StoreScheduleInboxResource
-        self._provisionedChildren["inbox"] = StoreScheduleInboxResource
+        self._provisionedChildren["inbox"] = StoreScheduleInboxResource.maybeCreateInbox
 
         from twistedcaldav.schedule import ScheduleOutboxResource
         self._provisionedChildren["outbox"] = ScheduleOutboxResource
@@ -2276,14 +2277,16 @@
             self._provisionedChildren["notification"] = NotificationCollectionResource
 
 
+    @inlineCallbacks
     def postCreateHome(self):
         # This is a bit of a hack.  Really we ought to be always generating
         # this URL live from a back-end method that tells us what the
         # default calendar is.
-        inbox = self.getChild("inbox")
+        inbox = yield self.getChild("inbox")
         childURL = joinURL(self.url(), "calendar")
         inbox.processFreeBusyCalendar(childURL, True)
 
+
     def canShare(self):
         return config.Sharing.Enabled and config.Sharing.Calendars.Enabled and self.exists()
 

Modified: CalendarServer/branches/users/glyph/more-deferreds-6/twistedcaldav/storebridge.py
===================================================================
--- CalendarServer/branches/users/glyph/more-deferreds-6/twistedcaldav/storebridge.py	2010-09-24 02:28:28 UTC (rev 6366)
+++ CalendarServer/branches/users/glyph/more-deferreds-6/twistedcaldav/storebridge.py	2010-09-24 02:29:35 UTC (rev 6367)
@@ -295,19 +295,26 @@
     def __init__(self, *a, **kw):
         super(StoreScheduleInboxResource, self).__init__(*a, **kw)
         self.parent.propagateTransaction(self)
+
+
+    @classmethod
+    @inlineCallbacks
+    def maybeCreateInbox(cls, *a, **kw):
+        self = cls(*a, **kw)
         home = self.parent._newStoreHome
-        storage = home.calendarWithName("inbox")
+        storage = yield home.calendarWithName("inbox")
         if storage is None:
             # raise RuntimeError("backend should be handling this for us")
             # FIXME: spurious error, sanity check, should not be needed;
             # unfortunately, user09's calendar home does not have an inbox, so
             # this is a temporary workaround.
             home.createCalendarWithName("inbox")
-            storage = home.calendarWithName("inbox")
+            storage = yield home.calendarWithName("inbox")
         self._initializeWithCalendar(
             storage,
             self.parent._newStoreHome
         )
+        returnValue(self)
 
 
     def name(self):
@@ -965,20 +972,19 @@
         return self.createCalendarCollection()
 
 
+    @inlineCallbacks
     def createCalendarCollection(self):
         """
         Override C{createCalendarCollection} to actually do the work.
         """
-        d = succeed(CREATED)
-
         self._newStoreParentHome.createCalendarWithName(self._name)
-        newStoreCalendar = self._newStoreParentHome.calendarWithName(
+        newStoreCalendar = yield self._newStoreParentHome.calendarWithName(
             self._name
         )
         CalendarCollectionResource.transform(
             self, newStoreCalendar, self._newStoreParentHome
         )
-        return d
+        returnValue(CREATED)
 
 
     def exists(self):
@@ -1579,20 +1585,19 @@
         return self.createAddressBookCollection()
 
 
+    @inlineCallbacks
     def createAddressBookCollection(self):
         """
         Override C{createAddressBookCollection} to actually do the work.
         """
-        d = succeed(CREATED)
-
         self._newStoreParentHome.createAddressBookWithName(self._name)
-        newStoreAddressBook = self._newStoreParentHome.addressbookWithName(
+        newStoreAddressBook = yield self._newStoreParentHome.addressbookWithName(
             self._name
         )
         AddressBookCollectionResource.transform(
             self, newStoreAddressBook, self._newStoreParentHome
         )
-        return d
+        returnValue(CREATED)
 
 
     def exists(self):
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100923/6cdbcdaf/attachment-0001.html>


More information about the calendarserver-changes mailing list