[CalendarServer-changes] [5042] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Wed Feb 3 16:20:44 PST 2010


Revision: 5042
          http://trac.macosforge.org/projects/calendarserver/changeset/5042
Author:   wsanchez at apple.com
Date:     2010-02-03 16:20:43 -0800 (Wed, 03 Feb 2010)
Log Message:
-----------
Start hacking the index into here

Modified Paths:
--------------
    CalendarServer/trunk/twistedcaldav/index.py
    CalendarServer/trunk/txcaldav/calendarstore/file.py
    CalendarServer/trunk/txcaldav/calendarstore/test/test_file.py
    CalendarServer/trunk/txcaldav/icalendarstore.py

Modified: CalendarServer/trunk/twistedcaldav/index.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/index.py	2010-02-03 23:31:23 UTC (rev 5041)
+++ CalendarServer/trunk/twistedcaldav/index.py	2010-02-04 00:20:43 UTC (rev 5042)
@@ -829,9 +829,11 @@
         assert resource.isCalendarCollection(), "non-calendar collection resource %s has no index." % (resource,)
         super(Index, self).__init__(resource)
 
-        if config.Memcached.Pools.Default.ClientEnabled:
+        if (
+            hasattr(config, "Memcached") and
+            config.Memcached.Pools.Default.ClientEnabled
+        ):
             self.reserver = MemcachedUIDReserver(self)
-
         else:
             self.reserver = SQLUIDReserver(self)
 

Modified: CalendarServer/trunk/txcaldav/calendarstore/file.py
===================================================================
--- CalendarServer/trunk/txcaldav/calendarstore/file.py	2010-02-03 23:31:23 UTC (rev 5041)
+++ CalendarServer/trunk/txcaldav/calendarstore/file.py	2010-02-04 00:20:43 UTC (rev 5042)
@@ -30,6 +30,7 @@
 from zope.interface import implements
 
 from twisted.python.filepath import FilePath
+from twisted.internet.defer import inlineCallbacks, returnValue
 
 from twext.log import LoggingMixIn
 from twext.python.icalendar import Component as iComponent
@@ -49,6 +50,7 @@
 from txcaldav.icalendarstore import InternalDataStoreError
 
 from twistedcaldav.index import Index
+from twistedcaldav.memcachelock import MemcacheLock, MemcacheLockTimeoutError
 
 
 class CalendarStore(LoggingMixIn):
@@ -159,19 +161,69 @@
     def __repr__(self):
         return "<%s: %s>" % (self.__class__.__name__, self.path.path)
 
+    def index(self):
+        #
+        # OK, here's where we get ugly.
+        # The index code needs to be rewritten also, but in the meantime...
+        #
+        class StubResource(object):
+            """
+            Just enough resource to keep the Index class going.
+            """
+            def __init__(self, calendar):
+                self.calendar = calendar
+                self.fp = self.calendar.path
+
+            def isCalendarCollection(self):
+                return True
+
+            def getChild(self, name):
+                calendarObject = self.calendar.calendarObjectWithName(name)
+                if calendarObject:
+                    class ChildResource(object):
+                        def __init__(self, calendarObject):
+                            self.calendarObject = calendarObject
+
+                        def iCalendar(self):
+                            return self.calendarObject.component()
+
+                    return ChildResource(calendarObject)
+                else:
+                    return None
+
+            def bumpSyncToken(self, reset=False):
+                return self.calendar._updateSyncToken(reset)
+
+        if not hasattr(self, "_index"):
+            self._index = Index(StubResource(self))
+        return self._index
+
     def name(self):
         return self.path.basename()
 
     def ownerCalendarHome(self):
         return self.calendarHome
 
-    def calendarObjects(self):
+    def _calendarObjects_index(self):
+        for name, uid, componentType in self.index().bruteForceSearch():
+            calendarObject = self.calendarObjectWithName(name)
+
+            # Precache what we found in the index
+            calendarObject._uid = uid
+            calendarObject._componentType = componentType
+
+            yield calendarObject
+
+    def _calendarObjects_listdir(self):
         return (
             self.calendarObjectWithName(name)
             for name in self.path.listdir()
             if not name.startswith(".")
         )
 
+    calendarObjects = _calendarObjects_listdir
+   #calendarObjects = _calendarObjects_index
+
     def calendarObjectWithName(self, name):
         childPath = self.path.child(name)
         if childPath.isfile():
@@ -209,6 +261,31 @@
     def syncToken(self):
         raise NotImplementedError()
 
+    @inlineCallbacks
+    def _updateSyncToken(self, reset=False):
+        return
+
+        lock = MemcacheLock("Calendar", self.fp.path, timeout=60.0)
+        try:
+            try:
+                yield lock.acquire()
+            except MemcacheLockTimeoutError:
+                raise InternalDataStoreError("Timed out on calendar lock")
+
+            def newToken():
+                raise NotImplementedError()
+
+            if reset:
+                token = newToken()
+
+            raise NotImplementedError()
+
+        finally:
+            yield lock.clean()
+
+
+        raise NotImplementedError()
+
     def calendarObjectsInTimeRange(self, start, end, timeZone):
         raise NotImplementedError()
 
@@ -239,6 +316,16 @@
             raise TypeError(iComponent)
 
         try:
+            if component.resourceUID() != self.uid():
+                raise InvalidCalendarComponentError(
+                    "UID may not change (%s != %s)" % (
+                        component.resourceUID(), self.uid()
+                     )
+                )
+        except NoSuchCalendarObjectError:
+            pass
+
+        try:
             component.validateForCalDAV()
         except InvalidICalendarDataError, e:
             raise InvalidCalendarComponentError(e)

Modified: CalendarServer/trunk/txcaldav/calendarstore/test/test_file.py
===================================================================
--- CalendarServer/trunk/txcaldav/calendarstore/test/test_file.py	2010-02-03 23:31:23 UTC (rev 5041)
+++ CalendarServer/trunk/txcaldav/calendarstore/test/test_file.py	2010-02-04 00:20:43 UTC (rev 5042)
@@ -78,7 +78,7 @@
       "END:VTIMEZONE\r\n"
       "BEGIN:VEVENT\r\n"
         "CREATED:20100203T013849Z\r\n"
-        "UID:4\r\n"
+        "UID:uid4\r\n"
         "DTEND;TZID=US/Pacific:20100207T173000\r\n"
         "TRANSP:OPAQUE\r\n"
         "SUMMARY:New Event\r\n"
@@ -95,7 +95,10 @@
     "END:VCALENDAR\r\n"
 )
 
-event1modified_text = event4_text.replace("\r\nUID:4\r\n", "\r\nUID:1\r\n")
+event1modified_text = event4_text.replace(
+    "\r\nUID:uid4\r\n",
+    "\r\nUID:uid1\r\n"
+)
 
 event4notCalDAV_text = (
     "BEGIN:VCALENDAR\r\n"
@@ -647,13 +650,12 @@
         calendarObject = self.calendar1.calendarObjectWithName("1.ics")
         self.assertEquals(calendarObject.component(), component)
 
-    @featureUnimplemented
     def test_setComponent_uidchanged(self):
         component = iComponent.fromString(event4_text)
 
         calendarObject = self.calendar1.calendarObjectWithName("1.ics")
         self.assertRaises(
-            CalendarObjectUIDAlreadyExistsError,
+            InvalidCalendarComponentError,
             calendarObject.setComponent, component
         )
 

Modified: CalendarServer/trunk/txcaldav/icalendarstore.py
===================================================================
--- CalendarServer/trunk/txcaldav/icalendarstore.py	2010-02-03 23:31:23 UTC (rev 5041)
+++ CalendarServer/trunk/txcaldav/icalendarstore.py	2010-02-04 00:20:43 UTC (rev 5042)
@@ -32,6 +32,7 @@
     "NoSuchCalendarError",
     "NoSuchCalendarObjectError",
     "InvalidCalendarComponentError",
+    "TryAgainLaterError",
     "InternalDataStoreError",
 
     # Classes
@@ -110,6 +111,11 @@
     Invalid calendar component.
     """
 
+class TryAgainLaterError(CalendarStoreError):
+    """
+    Requested resource is in use.  Try again later.
+    """
+
 class InternalDataStoreError(CalendarStoreError):
     """
     Uh, oh.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100203/bbfb455e/attachment.html>


More information about the calendarserver-changes mailing list