[CalendarServer-changes] [2340] CalendarServer/branches/propfind-cache/twistedcaldav/static.py

source_changes at macosforge.org source_changes at macosforge.org
Thu Apr 24 10:59:28 PDT 2008


Revision: 2340
          http://trac.macosforge.org/projects/calendarserver/changeset/2340
Author:   dreid at apple.com
Date:     2008-04-24 10:59:26 -0700 (Thu, 24 Apr 2008)

Log Message:
-----------
In updateCTag trigger a dataChanged notification and in createSimilarFile attach the cacheNotifier

Modified Paths:
--------------
    CalendarServer/branches/propfind-cache/twistedcaldav/static.py

Modified: CalendarServer/branches/propfind-cache/twistedcaldav/static.py
===================================================================
--- CalendarServer/branches/propfind-cache/twistedcaldav/static.py	2008-04-24 00:11:49 UTC (rev 2339)
+++ CalendarServer/branches/propfind-cache/twistedcaldav/static.py	2008-04-24 17:59:26 UTC (rev 2340)
@@ -71,6 +71,8 @@
 from twistedcaldav.directory.calendar import DirectoryCalendarHomeResource
 from twistedcaldav.directory.resource import AutoProvisioningResourceMixIn
 
+from twistedcaldav.cache import CacheChangeNotifier
+
 class CalDAVFile (CalDAVResource, DAVFile):
     """
     CalDAV-accessible L{DAVFile} resource.
@@ -117,9 +119,9 @@
                     responsecode.FORBIDDEN,
                     (caldavxml.caldav_namespace, "calendar-collection-location-ok")
                 ))
-    
+
             return self.createCalendarCollection()
-            
+
         parent = self._checkParents(request, isPseudoCalendarCollectionResource)
         parent.addCallback(_defer)
         return parent
@@ -131,13 +133,13 @@
         def onCalendarCollection(status):
             if status != responsecode.CREATED:
                 raise HTTPError(status)
-    
+
             # Initialize CTag on the calendar collection
             self.updateCTag()
-            
+
             # Create the index so its ready when the first PUTs come in
             self.index().create()
-            
+
             return status
 
         d = self.createSpecialCollection(davxml.ResourceType.calendar)
@@ -151,10 +153,10 @@
         def onCollection(status):
             if status != responsecode.CREATED:
                 raise HTTPError(status)
-    
+
             self.writeDeadProperty(resourceType)
             return status
-        
+
         def onError(f):
             try:
                 rmdir(self.fp)
@@ -167,7 +169,7 @@
             d.addCallback(onCollection)
         d.addErrback(onError)
         return d
- 
+
     def iCalendarRolledup(self, request):
         if self.isPseudoCalendarCollection():
             # Generate a monolithic calendar
@@ -189,7 +191,7 @@
                     child = IDAVResource(child)
                 except TypeError:
                     child = None
-    
+
                 if child is not None:
                     # Check privileges of child - skip if access denied
                     try:
@@ -203,7 +205,7 @@
 
                     for component in subcalendar.subcomponents():
                         calendar.addComponent(component)
-                        
+
             yield calendar
             return
 
@@ -256,7 +258,7 @@
             d = self.locateParent(request, request.urlForResource(self))
             d.addCallback(gotParent)
             return d
-        
+
         return super(CalDAVFile, self).supportedPrivileges(request)
 
     ##
@@ -284,6 +286,9 @@
 
     def updateCTag(self):
         assert self.isCollection()
+        if hasattr(self, 'cacheNotifier'):
+            self.cacheNotifier.dataChanged()
+
         self.writeDeadProperty(customxml.GETCTag(str(datetime.datetime.now())))
 
     ##
@@ -303,17 +308,17 @@
                 """
                 Recursively descend the directory tree rooted at top,
                 calling the callback function for each regular file
-                
+
                 @param top: L{FilePath} for the directory to walk.
                 """
-            
+
                 total = 0
                 for f in top.listdir():
-    
+
                     # Ignore the database
                     if f.startswith("."):
                         continue
-    
+
                     child = top.child(f)
                     if child.isdir():
                         # It's a directory, recurse into it
@@ -326,11 +331,11 @@
                     else:
                         # Unknown file type, print a message
                         pass
-            
+
                 yield total
-            
+
             walktree = deferredGenerator(walktree)
-    
+
             return walktree(self.fp)
         else:
             return succeed(self.fp.getsize())
@@ -354,20 +359,20 @@
         #
         # Parse the URI
         #
-    
+
         (scheme, host, path, query, fragment) = urlsplit(uri) #@UnusedVariable
-    
+
         # Request hostname and child uri hostname have to be the same.
         if host and host != request.headers.getHeader("host"):
             return False
-        
+
         # Child URI must start with request uri text.
         parent = request.uri
         if not parent.endswith("/"):
             parent += "/"
-            
+
         return path.startswith(parent) and (len(path) > len(parent)) and (not immediateChild or (path.find("/", len(parent)) == -1))
-    
+
     def _checkParents(self, request, test):
         """
         @param request: the request being processed.
@@ -392,7 +397,7 @@
                 return
 
         yield None
-    
+
     _checkParents = deferredGenerator(_checkParents)
 
 class AutoProvisioningFileMixIn (AutoProvisioningResourceMixIn):
@@ -413,7 +418,7 @@
             parent = self.parent
             if not parent.exists() and isinstance(parent, AutoProvisioningFileMixIn):
                 parent.provision()
-                
+
             assert parent.exists(), "Parent %s of %s does not exist" % (parent, self)
             assert parent.isCollection(), "Parent %s of %s is not a collection" % (parent, self)
 
@@ -434,7 +439,7 @@
 
 class CalendarHomeProvisioningFile (AutoProvisioningFileMixIn, DirectoryCalendarHomeProvisioningResource, DAVFile):
     """
-    Resource which provisions calendar home collections as needed.    
+    Resource which provisions calendar home collections as needed.
     """
     def __init__(self, path, directory, url):
         """
@@ -526,6 +531,7 @@
         """
         CalDAVFile.__init__(self, path)
         DirectoryCalendarHomeResource.__init__(self, parent, record)
+        self.cacheNotifier = CacheChangeNotifier(self.deadProperties())
 
     def provisionChild(self, name):
         if config.EnableDropBox:
@@ -536,7 +542,7 @@
             NotificationsCollectionFileClass = NotificationsCollectionFile
         else:
             NotificationsCollectionFileClass = None
-            
+
         cls = {
             "inbox"        : ScheduleInboxFile,
             "outbox"       : ScheduleOutboxFile,
@@ -553,7 +559,9 @@
         if path == self.fp.path:
             return self
         else:
-            return CalDAVFile(path, principalCollections=self.principalCollections())
+            similar = CalDAVFile(path, principalCollections=self.principalCollections())
+            similar.cacheNotifier = self.cacheNotifier
+            return similar
 
     def getChild(self, name):
         # This avoids finding case variants of put children on case-insensitive filesystems.
@@ -721,9 +729,9 @@
         elements = []
         elements.append(customxml.TimeStamp.fromString(timestamp))
         elements.append(customxml.Changed(davxml.HRef.fromString(parentURL)))
-                          
+
         xml = customxml.Notification(*elements)
-        
+
         d = waitForDeferred(put_common_base.storeResource(request, data=xml.toxml(), destination=self, destination_uri=request.urlForResource(self)))
         yield d
         d.getResult()

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20080424/2365c5e7/attachment-0001.html


More information about the calendarserver-changes mailing list