[CalendarServer-changes] [5263] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Fri Mar 5 16:46:18 PST 2010


Revision: 5263
          http://trac.macosforge.org/projects/calendarserver/changeset/5263
Author:   sagen at apple.com
Date:     2010-03-05 16:46:15 -0800 (Fri, 05 Mar 2010)
Log Message:
-----------
Set autoSchedule default for locations/resources to True.  Invalidate memcached records when autoSchedule is changed.

Modified Paths:
--------------
    CalendarServer/trunk/calendarserver/tools/gateway.py
    CalendarServer/trunk/calendarserver/tools/principals.py
    CalendarServer/trunk/calendarserver/tools/test/test_gateway.py
    CalendarServer/trunk/twistedcaldav/directory/xmlfile.py

Modified: CalendarServer/trunk/calendarserver/tools/gateway.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/gateway.py	2010-03-05 23:28:02 UTC (rev 5262)
+++ CalendarServer/trunk/calendarserver/tools/gateway.py	2010-03-06 00:46:15 UTC (rev 5263)
@@ -199,17 +199,29 @@
     def command_getLocationList(self, command):
         respondWithRecordsOfType(self.dir, command, "locations")
 
+    @inlineCallbacks
     def command_createLocation(self, command):
 
         kwargs = {}
         for key, info in attrMap.iteritems():
             if command.has_key(key):
                 kwargs[info['attr']] = command[key]
+
         try:
-            self.dir.createRecord("locations", **kwargs)
+            record = self.dir.createRecord("locations", **kwargs)
         except DirectoryError, e:
             respondWithError(str(e))
             return
+
+        principal = self.dir.principalCollection.principalForRecord(record)
+        (yield principal.setAutoSchedule(command.get('AutoSchedule', True)))
+
+        try:
+            self.dir.updateRecord("locations", **kwargs)
+        except DirectoryError, e:
+            respondWithError(str(e))
+            return
+
         respondWithRecordsOfType(self.dir, command, "locations")
 
     def command_getLocationAttributes(self, command):
@@ -229,6 +241,12 @@
     @inlineCallbacks
     def command_setLocationAttributes(self, command):
 
+        # Set autoSchedule prior to the updateRecord so that the right
+        # value ends up in memcached
+        principal = principalForPrincipalID(command['GeneratedUID'],
+            directory=self.dir)
+        (yield principal.setAutoSchedule(command.get('AutoSchedule', False)))
+
         kwargs = {}
         for key, info in attrMap.iteritems():
             if command.has_key(key):
@@ -239,10 +257,6 @@
             respondWithError(str(e))
             return
 
-        principal = principalForPrincipalID(command['GeneratedUID'],
-            directory=self.dir)
-        (yield principal.setAutoSchedule(command.get('AutoSchedule', False)))
-
         self.command_getLocationAttributes(command)
 
     def command_deleteLocation(self, command):
@@ -262,16 +276,28 @@
     def command_getResourceList(self, command):
         respondWithRecordsOfType(self.dir, command, "resources")
 
+    @inlineCallbacks
     def command_createResource(self, command):
         kwargs = {}
         for key, info in attrMap.iteritems():
             if command.has_key(key):
                 kwargs[info['attr']] = command[key]
+
         try:
-            self.dir.createRecord("resources", **kwargs)
+            record = self.dir.createRecord("resources", **kwargs)
         except DirectoryError, e:
             respondWithError(str(e))
             return
+
+        principal = self.dir.principalCollection.principalForRecord(record)
+        (yield principal.setAutoSchedule(command.get('AutoSchedule', True)))
+
+        try:
+            self.dir.updateRecord("resources", **kwargs)
+        except DirectoryError, e:
+            respondWithError(str(e))
+            return
+
         respondWithRecordsOfType(self.dir, command, "resources")
 
     def command_getResourceAttributes(self, command):
@@ -280,6 +306,12 @@
     @inlineCallbacks
     def command_setResourceAttributes(self, command):
 
+        # Set autoSchedule prior to the updateRecord so that the right
+        # value ends up in memcached
+        principal = principalForPrincipalID(command['GeneratedUID'],
+            directory=self.dir)
+        (yield principal.setAutoSchedule(command.get('AutoSchedule', False)))
+
         kwargs = {}
         for key, info in attrMap.iteritems():
             if command.has_key(key):
@@ -290,10 +322,6 @@
             respondWithError(str(e))
             return
 
-        principal = principalForPrincipalID(command['GeneratedUID'],
-            directory=self.dir)
-        (yield principal.setAutoSchedule(command.get('AutoSchedule', False)))
-
         self.command_getResourceAttributes(command)
 
     def command_deleteResource(self, command):

Modified: CalendarServer/trunk/calendarserver/tools/principals.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/principals.py	2010-03-05 23:28:02 UTC (rev 5262)
+++ CalendarServer/trunk/calendarserver/tools/principals.py	2010-03-06 00:46:15 UTC (rev 5263)
@@ -227,7 +227,6 @@
             usage("Too many arguments")
 
         try:
-            print config.directory
             for record in config.directory.listRecords(listPrincipals):
                 print record
         except UnknownRecordTypeError, e:
@@ -470,6 +469,14 @@
         )
         (yield principal.setAutoSchedule(autoSchedule))
 
+        # Invalidate the directory cache by updating this record
+        config.directory.updateRecord(principal.record.recordType,
+            guid=principal.record.guid,
+            shortNames=principal.record.shortNames,
+            fullName=principal.record.fullName,
+            **principal.record.extras
+        )
+
 def action_getAutoSchedule(principal):
     autoSchedule = principal.getAutoSchedule()
     print "Autoschedule for %s is %s" % (

Modified: CalendarServer/trunk/calendarserver/tools/test/test_gateway.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/test/test_gateway.py	2010-03-05 23:28:02 UTC (rev 5262)
+++ CalendarServer/trunk/calendarserver/tools/test/test_gateway.py	2010-03-06 00:46:15 UTC (rev 5263)
@@ -117,7 +117,7 @@
         self.assertEquals(results['result']['Street'], "1 Infinite Loop")
         self.assertEquals(results['result']['RealName'], "Created Location 01")
         self.assertEquals(results['result']['Comment'], "Test Comment")
-        self.assertEquals(results['result']['AutoSchedule'], False)
+        self.assertEquals(results['result']['AutoSchedule'], True)
 
     @inlineCallbacks
     def test_getResourceList(self):
@@ -140,8 +140,15 @@
         yield self.runCommand(command_createLocation)
 
         directory.flushCaches()
+
+        # This appears to be necessary in order for record.autoSchedule to
+        # reflect the change prior to the directory record expiration
+        augment.AugmentService.refresh()
+
         record = directory.recordWithUID("836B1B66-2E9A-4F46-8B1C-3DD6772C20B2")
+
         self.assertNotEquals(record, None)
+        self.assertEquals(record.autoSchedule, True)
 
         self.assertEquals(record.extras['comment'], "Test Comment")
         self.assertEquals(record.extras['building'], "Test Building")

Modified: CalendarServer/trunk/twistedcaldav/directory/xmlfile.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/xmlfile.py	2010-03-05 23:28:02 UTC (rev 5262)
+++ CalendarServer/trunk/twistedcaldav/directory/xmlfile.py	2010-03-06 00:46:15 UTC (rev 5263)
@@ -351,7 +351,9 @@
 
         self._persistRecords(accountsElement)
 
+        return self.recordWithGUID(guid)
 
+
     def destroyRecord(self, recordType, guid=None):
         """
         Remove the record matching guid.  In this XML-based implementation,
@@ -409,7 +411,10 @@
 
         # Force a cache update - both local and memcached
         self.queryDirectory([recordType], self.INDEX_TYPE_GUID, guid)
+        for shortName in shortNames:
+            self.queryDirectory([recordType], self.INDEX_TYPE_SHORTNAME, shortName)
 
+        return self.recordWithGUID(guid)
 
 class XMLDirectoryRecord(CachingDirectoryRecord):
     """
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100305/890b767b/attachment-0001.html>


More information about the calendarserver-changes mailing list