[CalendarServer-changes] [12506] CalendarServer/trunk/txdav/dps

source_changes at macosforge.org source_changes at macosforge.org
Wed Mar 12 11:24:25 PDT 2014


Revision: 12506
          http://trac.calendarserver.org//changeset/12506
Author:   sagen at apple.com
Date:     2014-01-31 12:45:39 -0800 (Fri, 31 Jan 2014)
Log Message:
-----------
Added remote DirectoryService and separate client script

Modified Paths:
--------------
    CalendarServer/trunk/txdav/dps/protocol.py
    CalendarServer/trunk/txdav/dps/service.py

Added Paths:
-----------
    CalendarServer/trunk/txdav/dps/client.py

Added: CalendarServer/trunk/txdav/dps/client.py
===================================================================
--- CalendarServer/trunk/txdav/dps/client.py	                        (rev 0)
+++ CalendarServer/trunk/txdav/dps/client.py	2014-01-31 20:45:39 UTC (rev 12506)
@@ -0,0 +1,44 @@
+##
+# Copyright (c) 2014 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+##
+
+from twext.who.idirectory import RecordType
+from twext.python.log import Logger
+from twisted.internet import reactor
+import cPickle as pickle
+import sys
+
+log = Logger()
+
+print sys.path
+from txdav.dps.service import DirectoryService
+
+
+def makeBetterRequest():
+
+    shortName = sys.argv[1]
+
+    ds = DirectoryService()
+    d = ds.recordWithShortName(RecordType.user, shortName)
+
+    def gotResults(result):
+        result = pickle.loads(result)
+        print('Done: %s' % (result,))
+        reactor.stop()
+    d.addCallback(gotResults)
+    reactor.run()
+
+if __name__ == '__main__':
+    makeBetterRequest()

Modified: CalendarServer/trunk/txdav/dps/protocol.py
===================================================================
--- CalendarServer/trunk/txdav/dps/protocol.py	2014-01-31 20:36:37 UTC (rev 12505)
+++ CalendarServer/trunk/txdav/dps/protocol.py	2014-01-31 20:45:39 UTC (rev 12506)
@@ -16,20 +16,13 @@
 
 from twext.who.idirectory import RecordType
 from twisted.protocols import amp
-from twisted.internet.defer import succeed, inlineCallbacks, returnValue
+from twisted.internet.defer import inlineCallbacks, returnValue
 from twext.python.log import Logger
 
 log = Logger()
 
 
-class DirectoryProxyAMPCommand(amp.Command):
-    """
-    A DirectoryProxy command
-    """
-    arguments = [('command', amp.String())]
-    response = [('result', amp.String())]
 
-
 class RecordWithShortNameCommand(amp.Command):
     arguments = [
         ('recordType', amp.String()),
@@ -54,23 +47,6 @@
         self._directory = directory
 
 
-    @DirectoryProxyAMPCommand.responder
-    # @inlineCallbacks
-    def testCommandReceived(self, command):
-        """
-        Process a command
-
-        @param command: DirectoryProxyAMPCommand
-        @returns: a deferred returning a dict
-        """
-        # command = readPlistFromString(command)
-        log.debug("Command arrived: {cmd}", cmd=command)
-        response = {"result": "plugh", "command": command}
-        log.debug("Responding with: {response}", response=response)
-        # returnValue(dict(result=result))
-        return succeed(response)
-
-
     @RecordWithShortNameCommand.responder
     @inlineCallbacks
     def recordWithShortName(self, recordType, shortName):
@@ -91,9 +67,6 @@
 # A test AMP client
 #
 
-command = "xyzzy"
-
-
 def makeRequest():
     from twisted.internet import reactor
     from twisted.internet.protocol import ClientCreator
@@ -116,5 +89,6 @@
     d.addCallback(gotResults)
     reactor.run()
 
+
 if __name__ == '__main__':
     makeRequest()

Modified: CalendarServer/trunk/txdav/dps/service.py
===================================================================
--- CalendarServer/trunk/txdav/dps/service.py	2014-01-31 20:36:37 UTC (rev 12505)
+++ CalendarServer/trunk/txdav/dps/service.py	2014-01-31 20:45:39 UTC (rev 12506)
@@ -14,11 +14,12 @@
 # limitations under the License.
 ##
 
-from twext.who.xml import DirectoryService
+from twext.who.xml import DirectoryService as XMLDirectoryService
+from twext.who.index import DirectoryService as BaseDirectoryService
 from twisted.python.usage import Options, UsageError
 from twisted.plugin import IPlugin
 from twisted.application import service
-from zope.interface import implements
+from zope.interface import implementer
 from twistedcaldav.config import config
 from twistedcaldav.stdconfig import DEFAULT_CONFIG, DEFAULT_CONFIG_FILE
 from twisted.application.strports import service as strPortsService
@@ -26,11 +27,38 @@
 from twext.python.log import Logger
 from twisted.python.filepath import FilePath
 
-from .protocol import DirectoryProxyAMPProtocol
+from .protocol import DirectoryProxyAMPProtocol, RecordWithShortNameCommand
 
+from twisted.internet import reactor
+from twisted.internet.protocol import ClientCreator
+from twisted.protocols import amp
+import cPickle as pickle
+
 log = Logger()
 
 
+class DirectoryService(BaseDirectoryService):
+
+    def _getConnection(self):
+        path = config.DirectoryProxy.SocketPath
+        return ClientCreator(reactor, amp.AMP).connectUnix(path)
+
+    def recordWithShortName(self, recordType, shortName):
+
+        def serialize(result):
+            return pickle.dumps(result)
+
+        def call(ampProto):
+            return ampProto.callRemote(
+                RecordWithShortNameCommand,
+                recordType=recordType.description.encode("utf-8"),
+                shortName=shortName.encode("utf-8")
+            )
+
+        return self._getConnection().addCallback(call).addCallback(serialize)
+
+
+
 class DirectoryProxyAMPFactory(Factory):
     """
     """
@@ -134,8 +162,8 @@
         self.parent['pidfile'] = None
 
 
+ at implementer(IPlugin, service.IServiceMaker)
 class DirectoryProxyServiceMaker(object):
-    implements(IPlugin, service.IServiceMaker)
 
     tapname = "caldav_directoryproxy"
     description = "Directory Proxy Service"
@@ -152,7 +180,7 @@
         else:
             setproctitle("CalendarServer Directory Proxy Service")
 
-        directory = DirectoryService(FilePath("foo.xml"))
+        directory = XMLDirectoryService(FilePath("foo.xml"))
 
         desc = "unix:{path}:mode=660".format(
             path=config.DirectoryProxy.SocketPath
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140312/9a85bbc4/attachment.html>


More information about the calendarserver-changes mailing list