<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[12506] CalendarServer/trunk/txdav/dps</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.calendarserver.org//changeset/12506">12506</a></dd>
<dt>Author</dt> <dd>sagen@apple.com</dd>
<dt>Date</dt> <dd>2014-01-31 12:45:39 -0800 (Fri, 31 Jan 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Added remote DirectoryService and separate client script</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunktxdavdpsprotocolpy">CalendarServer/trunk/txdav/dps/protocol.py</a></li>
<li><a href="#CalendarServertrunktxdavdpsservicepy">CalendarServer/trunk/txdav/dps/service.py</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#CalendarServertrunktxdavdpsclientpy">CalendarServer/trunk/txdav/dps/client.py</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunktxdavdpsclientpy"></a>
<div class="addfile"><h4>Added: CalendarServer/trunk/txdav/dps/client.py (0 => 12506)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/dps/client.py         (rev 0)
+++ CalendarServer/trunk/txdav/dps/client.py        2014-01-31 20:45:39 UTC (rev 12506)
</span><span class="lines">@@ -0,0 +1,44 @@
</span><ins>+##
+# 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()
</ins></span></pre></div>
<a id="CalendarServertrunktxdavdpsprotocolpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/dps/protocol.py (12505 => 12506)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -16,20 +16,13 @@
</span><span class="cx">
</span><span class="cx"> from twext.who.idirectory import RecordType
</span><span class="cx"> from twisted.protocols import amp
</span><del>-from twisted.internet.defer import succeed, inlineCallbacks, returnValue
</del><ins>+from twisted.internet.defer import inlineCallbacks, returnValue
</ins><span class="cx"> from twext.python.log import Logger
</span><span class="cx">
</span><span class="cx"> log = Logger()
</span><span class="cx">
</span><span class="cx">
</span><del>-class DirectoryProxyAMPCommand(amp.Command):
- """
- A DirectoryProxy command
- """
- arguments = [('command', amp.String())]
- response = [('result', amp.String())]
</del><span class="cx">
</span><del>-
</del><span class="cx"> class RecordWithShortNameCommand(amp.Command):
</span><span class="cx"> arguments = [
</span><span class="cx"> ('recordType', amp.String()),
</span><span class="lines">@@ -54,23 +47,6 @@
</span><span class="cx"> self._directory = directory
</span><span class="cx">
</span><span class="cx">
</span><del>- @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)
-
-
</del><span class="cx"> @RecordWithShortNameCommand.responder
</span><span class="cx"> @inlineCallbacks
</span><span class="cx"> def recordWithShortName(self, recordType, shortName):
</span><span class="lines">@@ -91,9 +67,6 @@
</span><span class="cx"> # A test AMP client
</span><span class="cx"> #
</span><span class="cx">
</span><del>-command = "xyzzy"
-
-
</del><span class="cx"> def makeRequest():
</span><span class="cx"> from twisted.internet import reactor
</span><span class="cx"> from twisted.internet.protocol import ClientCreator
</span><span class="lines">@@ -116,5 +89,6 @@
</span><span class="cx"> d.addCallback(gotResults)
</span><span class="cx"> reactor.run()
</span><span class="cx">
</span><ins>+
</ins><span class="cx"> if __name__ == '__main__':
</span><span class="cx"> makeRequest()
</span></span></pre></div>
<a id="CalendarServertrunktxdavdpsservicepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/dps/service.py (12505 => 12506)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -14,11 +14,12 @@
</span><span class="cx"> # limitations under the License.
</span><span class="cx"> ##
</span><span class="cx">
</span><del>-from twext.who.xml import DirectoryService
</del><ins>+from twext.who.xml import DirectoryService as XMLDirectoryService
+from twext.who.index import DirectoryService as BaseDirectoryService
</ins><span class="cx"> from twisted.python.usage import Options, UsageError
</span><span class="cx"> from twisted.plugin import IPlugin
</span><span class="cx"> from twisted.application import service
</span><del>-from zope.interface import implements
</del><ins>+from zope.interface import implementer
</ins><span class="cx"> from twistedcaldav.config import config
</span><span class="cx"> from twistedcaldav.stdconfig import DEFAULT_CONFIG, DEFAULT_CONFIG_FILE
</span><span class="cx"> from twisted.application.strports import service as strPortsService
</span><span class="lines">@@ -26,11 +27,38 @@
</span><span class="cx"> from twext.python.log import Logger
</span><span class="cx"> from twisted.python.filepath import FilePath
</span><span class="cx">
</span><del>-from .protocol import DirectoryProxyAMPProtocol
</del><ins>+from .protocol import DirectoryProxyAMPProtocol, RecordWithShortNameCommand
</ins><span class="cx">
</span><ins>+from twisted.internet import reactor
+from twisted.internet.protocol import ClientCreator
+from twisted.protocols import amp
+import cPickle as pickle
+
</ins><span class="cx"> log = Logger()
</span><span class="cx">
</span><span class="cx">
</span><ins>+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)
+
+
+
</ins><span class="cx"> class DirectoryProxyAMPFactory(Factory):
</span><span class="cx"> """
</span><span class="cx"> """
</span><span class="lines">@@ -134,8 +162,8 @@
</span><span class="cx"> self.parent['pidfile'] = None
</span><span class="cx">
</span><span class="cx">
</span><ins>+@implementer(IPlugin, service.IServiceMaker)
</ins><span class="cx"> class DirectoryProxyServiceMaker(object):
</span><del>- implements(IPlugin, service.IServiceMaker)
</del><span class="cx">
</span><span class="cx"> tapname = "caldav_directoryproxy"
</span><span class="cx"> description = "Directory Proxy Service"
</span><span class="lines">@@ -152,7 +180,7 @@
</span><span class="cx"> else:
</span><span class="cx"> setproctitle("CalendarServer Directory Proxy Service")
</span><span class="cx">
</span><del>- directory = DirectoryService(FilePath("foo.xml"))
</del><ins>+ directory = XMLDirectoryService(FilePath("foo.xml"))
</ins><span class="cx">
</span><span class="cx"> desc = "unix:{path}:mode=660".format(
</span><span class="cx"> path=config.DirectoryProxy.SocketPath
</span></span></pre>
</div>
</div>
</body>
</html>