[CalendarServer-changes] [12503] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Wed Mar 12 11:23:53 PDT 2014


Revision: 12503
          http://trac.calendarserver.org//changeset/12503
Author:   sagen at apple.com
Date:     2014-01-31 11:42:44 -0800 (Fri, 31 Jan 2014)
Log Message:
-----------
First pass at an AMP directory call

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

Modified: CalendarServer/trunk/calendarserver/tap/caldav.py
===================================================================
--- CalendarServer/trunk/calendarserver/tap/caldav.py	2014-01-31 19:01:07 UTC (rev 12502)
+++ CalendarServer/trunk/calendarserver/tap/caldav.py	2014-01-31 19:42:44 UTC (rev 12503)
@@ -77,6 +77,7 @@
     UpgradeDatabaseSchemaStep, UpgradeDatabaseAddressBookDataStep,
     UpgradeAcquireLockStep, UpgradeReleaseLockStep, UpgradeDatabaseNotificationDataStep)
 from txdav.common.datastore.work.revision_cleanup import scheduleFirstFindMinRevision
+from txdav.dps.service import DirectoryProxyServiceMaker
 
 from twistedcaldav import memcachepool
 from twistedcaldav.config import config, ConfigurationError
@@ -1264,6 +1265,11 @@
                 except ImportError:
                     print("Manhole access could not enabled because manhole_tap could not be imported")
 
+            # Optionally enable Directory Proxy
+            if config.DirectoryProxy.Enabled:
+                dps = DirectoryProxyServiceMaker().makeService(None)
+                dps.setServiceParent(result)
+
             def decorateTransaction(txn):
                 txn._pushDistributor = pushDistributor
                 txn._rootResource = result.rootResource

Modified: CalendarServer/trunk/txdav/dps/protocol.py
===================================================================
--- CalendarServer/trunk/txdav/dps/protocol.py	2014-01-31 19:01:07 UTC (rev 12502)
+++ CalendarServer/trunk/txdav/dps/protocol.py	2014-01-31 19:42:44 UTC (rev 12503)
@@ -14,9 +14,9 @@
 # limitations under the License.
 ##
 
-# import twext.who
+from twext.who.idirectory import RecordType
 from twisted.protocols import amp
-from twisted.internet.defer import succeed
+from twisted.internet.defer import succeed, inlineCallbacks, returnValue
 from twext.python.log import Logger
 
 log = Logger()
@@ -30,15 +30,28 @@
     response = [('result', amp.String())]
 
 
+class RecordWithShortNameCommand(amp.Command):
+    arguments = [
+        ('recordType', amp.String()),
+        ('shortName', amp.String()),
+    ]
+    response = [
+        ('fullNames', amp.ListOf(amp.String())),
+        ('shortNames', amp.ListOf(amp.String())),
+        ('emailAddresses', amp.ListOf(amp.String())),
+    ]
 
+
+
 class DirectoryProxyAMPProtocol(amp.AMP):
     """
     """
 
-    def __init__(self):
+    def __init__(self, directory):
         """
         """
         amp.AMP.__init__(self)
+        self._directory = directory
 
 
     @DirectoryProxyAMPCommand.responder
@@ -58,6 +71,22 @@
         return succeed(response)
 
 
+    @RecordWithShortNameCommand.responder
+    @inlineCallbacks
+    def recordWithShortName(self, recordType, shortName):
+        log.debug("RecordWithShortName: {r} {n}", r=recordType, n=shortName)
+        record = (yield self._directory.recordWithShortName(
+            RecordType.lookupByName(recordType), shortName)
+        )
+        response = {
+            "fullNames": [i.encode("utf-8") for i in record.fullNames],
+            "shortNames": [i.encode("utf-8") for i in record.shortNames],
+            "emailAddresses": [i.encode("utf-8") for i in record.emailAddresses],
+        }
+        log.debug("Responding with: {response}", response=response)
+        returnValue(response)
+
+
 #
 # A test AMP client
 #
@@ -73,19 +102,19 @@
     d = creator.connectUNIX("data/Logs/state/directory-proxy.sock")
 
     def connected(ampProto):
-        return ampProto.callRemote(DirectoryProxyAMPCommand, command=command)
+        import sys
+        shortName = sys.argv[1]
+        return ampProto.callRemote(
+            RecordWithShortNameCommand,
+            shortName=shortName,
+            recordType=RecordType.user.description.encode("utf-8"))
     d.addCallback(connected)
 
-    def resulted(result):
-        return result['result']
-    d.addCallback(resulted)
-
-    def done(result):
+    def gotResults(result):
         print('Done: %s' % (result,))
         reactor.stop()
-    d.addCallback(done)
+    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 19:01:07 UTC (rev 12502)
+++ CalendarServer/trunk/txdav/dps/service.py	2014-01-31 19:42:44 UTC (rev 12503)
@@ -14,7 +14,7 @@
 # limitations under the License.
 ##
 
-import twext.who
+from twext.who.xml import DirectoryService
 from twisted.python.usage import Options, UsageError
 from twisted.plugin import IPlugin
 from twisted.application import service
@@ -24,6 +24,7 @@
 from twisted.application.strports import service as strPortsService
 from twisted.internet.protocol import Factory
 from twext.python.log import Logger
+from twisted.python.filepath import FilePath
 
 from .protocol import DirectoryProxyAMPProtocol
 
@@ -36,8 +37,11 @@
     protocol = DirectoryProxyAMPProtocol
 
 
+    def __init__(self, directory):
+        self._directory = directory
+
     def buildProtocol(self, addr):
-        return DirectoryProxyAMPProtocol()
+        return DirectoryProxyAMPProtocol(self._directory)
 
 
 
@@ -148,7 +152,9 @@
         else:
             setproctitle("CalendarServer Directory Proxy Service")
 
+        directory = DirectoryService(FilePath("foo.xml"))
+
         desc = "unix:{path}:mode=660".format(
             path=config.DirectoryProxy.SocketPath
         )
-        return strPortsService(desc, DirectoryProxyAMPFactory())
+        return strPortsService(desc, DirectoryProxyAMPFactory(directory))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140312/67cd1002/attachment.html>


More information about the calendarserver-changes mailing list