[CalendarServer-changes] [2295] CalendarServer/branches/propfind-cache/twistedcaldav

source_changes at macosforge.org source_changes at macosforge.org
Thu Apr 10 11:34:27 PDT 2008


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

Log Message:
-----------
Implement the CalendarHomeFile.changed method which initializes cache tokens and updates them on changes.

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

Modified: CalendarServer/branches/propfind-cache/twistedcaldav/static.py
===================================================================
--- CalendarServer/branches/propfind-cache/twistedcaldav/static.py	2008-04-10 09:23:14 UTC (rev 2294)
+++ CalendarServer/branches/propfind-cache/twistedcaldav/static.py	2008-04-10 18:34:26 UTC (rev 2295)
@@ -44,6 +44,7 @@
 from twisted.web2 import responsecode
 from twisted.web2.http import HTTPError, StatusResponse
 from twisted.web2.dav import davxml
+
 from twisted.web2.dav.fileop import mkcollection, rmdir
 from twisted.web2.dav.http import ErrorResponse
 from twisted.web2.dav.idav import IDAVResource
@@ -536,7 +537,7 @@
             NotificationsCollectionFileClass = NotificationsCollectionFile
         else:
             NotificationsCollectionFileClass = None
-            
+
         cls = {
             "inbox"        : ScheduleInboxFile,
             "outbox"       : ScheduleOutboxFile,
@@ -562,6 +563,37 @@
 
         return super(CalendarHomeFile, self).getChild(name)
 
+
+    def _newCacheToken(self, property=False, data=False):
+        import ctypes, ctypes.util
+        _uuid = ctypes.create_string_buffer(16)
+        libc = ctypes.CDLL(ctypes.util.find_library('c'))
+        libc.uuid_generate_time(_uuid)
+
+        uuid = "%032x" % (long("%02x"*16 % tuple(map(ord, _uuid.raw)), 16),)
+        return "%s-%s-%s-%s-%s" % (
+            uuid[:8], uuid[8:12], uuid[12:16], uuid[16:20], uuid[20:])
+
+
+    def changed(self, request, uri, properties=False, data=False):
+        try:
+            oldCacheTokens = self.readDeadProperty(CacheTokensProperty.qname())
+            propToken, dataToken = oldCacheTokens.children[0].data.split(':')
+
+            if properties is True:
+                propToken = self._newCacheToken(property=True)
+
+            if data is True:
+                dataToken = self._newCacheToken(data=True)
+
+        except HTTPError, e:
+            propToken, dataToken = (self._newCacheToken(property=True),
+                                    self._newCacheToken(data=True))
+
+        self.writeDeadProperty(
+            CacheTokensProperty.fromString('%s:%s' % (propToken, dataToken)))
+
+
 class ScheduleFile (AutoProvisioningFileMixIn, CalDAVFile):
     def __init__(self, path, parent):
         super(ScheduleFile, self).__init__(path, principalCollections=parent.principalCollections())
@@ -819,6 +851,13 @@
 
 calendarPrivilegeSet = _calendarPrivilegeSet()
 
+
+class CacheTokensProperty(davxml.WebDAVTextElement):
+    namespace = davxml.twisted_private_namespace
+    name = "cacheTokens"
+
+davxml.registerElement(CacheTokensProperty)
+
 ##
 # Attach methods
 ##

Modified: CalendarServer/branches/propfind-cache/twistedcaldav/test/test_resource.py
===================================================================
--- CalendarServer/branches/propfind-cache/twistedcaldav/test/test_resource.py	2008-04-10 09:23:14 UTC (rev 2294)
+++ CalendarServer/branches/propfind-cache/twistedcaldav/test/test_resource.py	2008-04-10 18:34:26 UTC (rev 2295)
@@ -49,7 +49,7 @@
 
 class ChangedNotificationTestCase(TestCase):
     """
-    Test that CalDAVREsource's changed implementation propogates change
+    Test that CalDAVResource's changed implementation propogates change
     notifications to it's parent.
     """
     def setUp(self):

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


More information about the calendarserver-changes mailing list