[CalendarServer-changes] [5121] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Mon Feb 15 11:41:08 PST 2010


Revision: 5121
          http://trac.macosforge.org/projects/calendarserver/changeset/5121
Author:   sagen at apple.com
Date:     2010-02-15 11:41:04 -0800 (Mon, 15 Feb 2010)
Log Message:
-----------
principal.setAutoSchedule( ) now hooked up to update augment DB

Modified Paths:
--------------
    CalendarServer/trunk/calendarserver/tools/gateway.py
    CalendarServer/trunk/calendarserver/tools/principals.py
    CalendarServer/trunk/calendarserver/tools/test/gateway/augments.xml
    CalendarServer/trunk/calendarserver/tools/test/test_gateway.py
    CalendarServer/trunk/calendarserver/tools/test/test_principals.py
    CalendarServer/trunk/support/build.sh
    CalendarServer/trunk/twistedcaldav/directory/principal.py

Modified: CalendarServer/trunk/calendarserver/tools/gateway.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/gateway.py	2010-02-15 19:19:19 UTC (rev 5120)
+++ CalendarServer/trunk/calendarserver/tools/gateway.py	2010-02-15 19:41:04 UTC (rev 5121)
@@ -34,6 +34,9 @@
 from calendarserver.tools.util import loadConfig, getDirectory, setupMemcached, setupNotifications
 from calendarserver.tools.principals import principalForPrincipalID, proxySubprincipal, addProxy, removeProxy, ProxyError, ProxyWarning
 
+from twext.python.log import StandardIOObserver
+
+
 def usage(e=None):
 
     name = os.path.basename(sys.argv[0])
@@ -43,6 +46,7 @@
     print ""
     print "options:"
     print "  -h --help: print this help and exit"
+    print "  -e --error: send stderr to stdout"
     print "  -f --config <path>: Specify caldavd.plist configuration path"
     print ""
 
@@ -56,8 +60,9 @@
 
     try:
         (optargs, args) = getopt(
-            sys.argv[1:], "hf:", [
+            sys.argv[1:], "hef:", [
                 "help",
+                "error",
                 "config=",
             ],
         )
@@ -73,6 +78,10 @@
         if opt in ("-h", "--help"):
             usage()
 
+        if opt in ("-e", "--error"):
+            observer = StandardIOObserver()
+            observer.start()
+
         elif opt in ("-f", "--config"):
             configFileName = arg
 
@@ -206,10 +215,14 @@
         guid = command['GeneratedUID']
         record = self.dir.recordWithGUID(guid)
         recordDict = recordToDict(record)
-        # principal = principalForPrincipalID(guid, directory=self.dir)
-        # recordDict['AutoSchedule'] = principal.getAutoSchedule()
+        principal = principalForPrincipalID(guid, directory=self.dir)
+        if principal is None:
+            respondWithError("Principal not found: %s" % (guid,))
+            return
+        recordDict['AutoSchedule'] = principal.getAutoSchedule()
         respond(command, recordDict)
 
+    @inlineCallbacks
     def command_setLocationAttributes(self, command):
 
         kwargs = {}
@@ -222,9 +235,9 @@
             respondWithError(str(e))
             return
 
-        # principal = principalForPrincipalID(command['GeneratedUID'],
-        #     directory=self.dir)
-        # principal.setAutoSchedule(command.get('AutoSchedule', False))
+        principal = principalForPrincipalID(command['GeneratedUID'],
+            directory=self.dir)
+        (yield principal.setAutoSchedule(command.get('AutoSchedule', False)))
 
         self.command_getLocationAttributes(command)
 
@@ -258,13 +271,9 @@
         respondWithRecordsOfType(self.dir, command, "resources")
 
     def command_getResourceAttributes(self, command):
-        guid = command['GeneratedUID']
-        record = self.dir.recordWithGUID(guid)
-        recordDict = recordToDict(record)
-        # principal = principalForPrincipalID(guid, directory=self.dir)
-        # recordDict['AutoSchedule'] = principal.getAutoSchedule()
-        respond(command, recordDict)
+        self.command_getLocationAttributes(command)
 
+    @inlineCallbacks
     def command_setResourceAttributes(self, command):
 
         kwargs = {}
@@ -277,9 +286,9 @@
             respondWithError(str(e))
             return
 
-        # principal = principalForPrincipalID(command['GeneratedUID'],
-        #     directory=self.dir)
-        # principal.setAutoSchedule(command.get('AutoSchedule', False))
+        principal = principalForPrincipalID(command['GeneratedUID'],
+            directory=self.dir)
+        (yield principal.setAutoSchedule(command.get('AutoSchedule', False)))
 
         self.command_getResourceAttributes(command)
 

Modified: CalendarServer/trunk/calendarserver/tools/principals.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/principals.py	2010-02-15 19:19:19 UTC (rev 5120)
+++ CalendarServer/trunk/calendarserver/tools/principals.py	2010-02-15 19:41:04 UTC (rev 5121)
@@ -35,7 +35,6 @@
 
 from twistedcaldav.config import config, ConfigurationError
 from twistedcaldav.directory.directory import UnknownRecordTypeError, DirectoryError
-from twistedcaldav.directory import augment
 
 from calendarserver.tools.util import loadConfig, getDirectory, setupMemcached, setupNotifications, booleanArgument
 
@@ -463,18 +462,8 @@
             { True: "true", False: "false" }[autoSchedule],
             principal,
         )
-        principal.setAutoSchedule(autoSchedule)
-        record = principal.record
-        aug = (yield augment.AugmentService.getAugmentRecord(record.guid))
-        aug.autoSchedule = autoSchedule
+        (yield principal.setAutoSchedule(autoSchedule))
 
-        # FIXME: This doesn't seem like a good idea, but I don't see a way
-        # to know whether there is already a record there, so I'm currently
-        # removing the record before adding it.
-        (yield augment.AugmentService.removeAugmentRecords([record.guid]))
-
-        (yield augment.AugmentService.addAugmentRecords([aug]))
-
 def action_getAutoSchedule(principal):
     autoSchedule = principal.getAutoSchedule()
     print "Autoschedule for %s is %s" % (

Modified: CalendarServer/trunk/calendarserver/tools/test/gateway/augments.xml
===================================================================
--- CalendarServer/trunk/calendarserver/tools/test/gateway/augments.xml	2010-02-15 19:19:19 UTC (rev 5120)
+++ CalendarServer/trunk/calendarserver/tools/test/gateway/augments.xml	2010-02-15 19:41:04 UTC (rev 5121)
@@ -20,6 +20,12 @@
 
 <augments>
   <record>
+    <uid>Default</uid>
+    <enable>true</enable>
+    <enable-calendar>true</enable-calendar>
+    <enable-addressbook>true</enable-addressbook>
+  </record>
+  <record>
     <uid>user01</uid>
     <enable>true</enable>
     <enable-calendar>true</enable-calendar>

Modified: CalendarServer/trunk/calendarserver/tools/test/test_gateway.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/test/test_gateway.py	2010-02-15 19:19:19 UTC (rev 5120)
+++ CalendarServer/trunk/calendarserver/tools/test/test_gateway.py	2010-02-15 19:41:04 UTC (rev 5121)
@@ -26,7 +26,9 @@
 from twistedcaldav.test.util import TestCase, CapturingProcessProtocol
 from calendarserver.tools.util import getDirectory
 
+from twistedcaldav.directory import augment
 
+
 class GatewayTestCase(TestCase):
 
     def setUp(self):
@@ -69,7 +71,7 @@
         return d
 
     @inlineCallbacks
-    def runCommand(self, command):
+    def runCommand(self, command, error=False):
         """
         Run the given command by feeding it as standard input to
         calendarserver_command_gateway in a subprocess.
@@ -79,6 +81,9 @@
         gateway = os.path.join(sourceRoot, "bin", "calendarserver_command_gateway")
 
         args = [python, gateway, "-f", self.configFileName]
+        if error:
+            args.append("--error")
+
         cwd = sourceRoot
 
         deferred = Deferred()
@@ -112,6 +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)
 
     @inlineCallbacks
     def test_getResourceList(self):
@@ -156,6 +162,11 @@
         record = directory.recordWithUID("836B1B66-2E9A-4F46-8B1C-3DD6772C20B2")
         yield self.runCommand(command_setLocationAttributes)
         directory.flushCaches()
+
+        # This appears to be necessary in order for record.autoSchedule to
+        # reflect the change
+        augment.AugmentService.refresh()
+
         record = directory.recordWithUID("836B1B66-2E9A-4F46-8B1C-3DD6772C20B2")
 
         self.assertEquals(record.extras['comment'], "Updated Test Comment")
@@ -168,7 +179,12 @@
         self.assertEquals(record.extras['zip'], "95015")
         self.assertEquals(record.extras['country'], "Updated USA")
         self.assertEquals(record.extras['phone'], "(408) 555-1213")
+        self.assertEquals(record.autoSchedule, True)
 
+        results = yield self.runCommand(command_getLocationAttributes)
+        self.assertEquals(results['result']['AutoSchedule'], True)
+
+
     @inlineCallbacks
     def test_destroyLocation(self):
         directory = getDirectory()
@@ -379,7 +395,7 @@
         <key>command</key>
         <string>listReadProxies</string>
         <key>Principal</key>
-        <string>locations:location01</string>
+        <string>836B1B66-2E9A-4F46-8B1C-3DD6772C20B2</string>
 </dict>
 </plist>
 """
@@ -391,7 +407,7 @@
         <key>command</key>
         <string>listWriteProxies</string>
         <key>Principal</key>
-        <string>locations:location01</string>
+        <string>836B1B66-2E9A-4F46-8B1C-3DD6772C20B2</string>
 </dict>
 </plist>
 """
@@ -431,7 +447,7 @@
         <key>command</key>
         <string>setLocationAttributes</string>
         <key>AutoSchedule</key>
-        <false/>
+        <true/>
         <key>GeneratedUID</key>
         <string>836B1B66-2E9A-4F46-8B1C-3DD6772C20B2</string>
         <key>RealName</key>

Modified: CalendarServer/trunk/calendarserver/tools/test/test_principals.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/test/test_principals.py	2010-02-15 19:19:19 UTC (rev 5120)
+++ CalendarServer/trunk/calendarserver/tools/test/test_principals.py	2010-02-15 19:41:04 UTC (rev 5121)
@@ -15,8 +15,6 @@
 ##
 
 import os
-import plistlib
-import xml
 
 from twisted.python.filepath import FilePath
 from twisted.internet import reactor
@@ -24,7 +22,6 @@
 
 from twistedcaldav.config import config
 from twistedcaldav.test.util import TestCase, CapturingProcessProtocol
-from calendarserver.tools.util import getDirectory
 
 
 class MangePrincipalsTestCase(TestCase):

Modified: CalendarServer/trunk/support/build.sh
===================================================================
--- CalendarServer/trunk/support/build.sh	2010-02-15 19:19:19 UTC (rev 5120)
+++ CalendarServer/trunk/support/build.sh	2010-02-15 19:41:04 UTC (rev 5121)
@@ -494,7 +494,7 @@
     false true true true 219;
 
   # Tool dependencies.  The code itself doesn't depend on these, but you probably want them.
-  svn_get "CalDAVTester" "${top}/CalDAVTester" "${svn_uri_base}/CalDAVTester/trunk" 4912;
+  svn_get "CalDAVTester" "${top}/CalDAVTester" "${svn_uri_base}/CalDAVTester/trunk" HEAD;
   svn_get "Pyflakes" "${top}/Pyflakes" http://divmod.org/svn/Divmod/trunk/Pyflakes HEAD;
 }
 

Modified: CalendarServer/trunk/twistedcaldav/directory/principal.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/principal.py	2010-02-15 19:19:19 UTC (rev 5120)
+++ CalendarServer/trunk/twistedcaldav/directory/principal.py	2010-02-15 19:41:04 UTC (rev 5121)
@@ -56,6 +56,7 @@
 from twistedcaldav.config import config
 from twistedcaldav.cache import DisabledCacheNotifier, PropfindCacheMixin
 from twistedcaldav.directory import calendaruserproxy
+from twistedcaldav.directory import augment
 from twistedcaldav.directory.calendaruserproxy import CalendarUserProxyPrincipalResource
 from twistedcaldav.directory.directory import DirectoryService, DirectoryRecord
 from twistedcaldav.directory.util import NotFilePath
@@ -488,7 +489,6 @@
             subType = None
 
         record = self.directory.recordWithUID(primaryUID)
-
         primaryPrincipal = self.principalForRecord(record) if record and record.enabled else None
         if primaryPrincipal is None:
             log.err("No principal found for UID: %s" % (name,))
@@ -786,8 +786,12 @@
     # Extra resource info
     ##
 
+    @inlineCallbacks
     def setAutoSchedule(self, autoSchedule):
         self.record.autoSchedule = autoSchedule
+        augmentRecord = (yield augment.AugmentService.getAugmentRecord(self.record.guid))
+        augmentRecord.autoSchedule = autoSchedule
+        (yield augment.AugmentService.addAugmentRecords([augmentRecord]))
 
     def getAutoSchedule(self):
         return self.record.autoSchedule
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100215/7065f362/attachment-0001.html>


More information about the calendarserver-changes mailing list