[CalendarServer-changes] [13771] twext/trunk/twext/who

source_changes at macosforge.org source_changes at macosforge.org
Thu Jul 17 12:01:43 PDT 2014


Revision: 13771
          http://trac.calendarserver.org//changeset/13771
Author:   cdaboo at apple.com
Date:     2014-07-17 12:01:43 -0700 (Thu, 17 Jul 2014)
Log Message:
-----------
Properly support OD recordType searches to enable resource/location migration to work.

Modified Paths:
--------------
    twext/trunk/twext/who/aggregate.py
    twext/trunk/twext/who/opendirectory/_constants.py
    twext/trunk/twext/who/opendirectory/_service.py
    twext/trunk/twext/who/opendirectory/test/test_service.py
    twext/trunk/twext/who/xml.py

Modified: twext/trunk/twext/who/aggregate.py
===================================================================
--- twext/trunk/twext/who/aggregate.py	2014-07-17 18:54:14 UTC (rev 13770)
+++ twext/trunk/twext/who/aggregate.py	2014-07-17 19:01:43 UTC (rev 13771)
@@ -23,6 +23,7 @@
     "DirectoryService",
 ]
 
+import collections
 from itertools import chain
 
 from twisted.internet.defer import (
@@ -162,10 +163,16 @@
 
     @inlineCallbacks
     def updateRecords(self, records, create=False):
+
+        # When migrating there may be lots of new records so batch this by each service record type
+        recordsByType = collections.defaultdict(list)
         for record in records:
+            recordsByType[record.recordType].append(record)
+
+        for recordType, recordList in recordsByType.items():
             for service in self.services:
-                if record.recordType in service.recordTypes():
-                    yield service.updateRecords([record], create=create)
+                if recordType in service.recordTypes():
+                    yield service.updateRecords(recordList, create=create)
 
 
     @inlineCallbacks

Modified: twext/trunk/twext/who/opendirectory/_constants.py
===================================================================
--- twext/trunk/twext/who/opendirectory/_constants.py	2014-07-17 18:54:14 UTC (rev 13770)
+++ twext/trunk/twext/who/opendirectory/_constants.py	2014-07-17 19:01:43 UTC (rev 13771)
@@ -71,7 +71,8 @@
     group = ValueConstant(u"dsRecTypeStandard:Groups")
     group.recordType = BaseRecordType.group
 
-    location = ValueConstant(u"dsRecTypeStandard:Locations")
+    #location = ValueConstant(u"dsRecTypeStandard:Locations")
+    place = ValueConstant(u"dsRecTypeStandard:Places")
 
     resource = ValueConstant(u"dsRecTypeStandard:Resources")
 
@@ -107,7 +108,6 @@
     # network = ValueConstant(u"dsRecTypeStandard:Networks")
     # passwordServer = ValueConstant(u"dsRecTypeStandard:PasswordServer")
     # person = ValueConstant(u"dsRecTypeStandard:People")
-    # place = ValueConstant(u"dsRecTypeStandard:Places")
     # presetComputer = ValueConstant(u"dsRecTypeStandard:PresetComputers")
     # presetComputerGroup = ValueConstant(u"dsRecTypeStandard:PresetComputerGroups")
     # presetComputerList = ValueConstant(u"dsRecTypeStandard:PresetComputerLists")

Modified: twext/trunk/twext/who/opendirectory/_service.py
===================================================================
--- twext/trunk/twext/who/opendirectory/_service.py	2014-07-17 18:54:14 UTC (rev 13770)
+++ twext/trunk/twext/who/opendirectory/_service.py	2014-07-17 19:01:43 UTC (rev 13771)
@@ -508,27 +508,33 @@
             expression.fieldName = self.fieldName.guid
 
         if expression.fieldName is self.fieldName.recordType:
-            raise QueryNotSupportedError("RecordType match not supported")
 
-        if MatchFlags.NOT in flags:
-            raise NotImplementedError()
+            queryAttribute = None
+            queryValue = None
+            matchType = ODMatchType.any.value
+            caseInsensitive = 0x0
 
-        if recordTypes is None:
-            odRecordTypes = [t.value for t in ODRecordType.iterconstants()]
+            odRecordTypes = [ODRecordType.fromRecordType(expression.fieldValue).value, ]
         else:
-            odRecordTypes = [ODRecordType.fromRecordType(r).value for r in recordTypes]
+            if MatchFlags.NOT in flags:
+                raise NotImplementedError()
 
-        queryAttribute = ODAttribute.fromFieldName(
-            expression.fieldName
-        ).value
+            if recordTypes is None:
+                odRecordTypes = [t.value for t in ODRecordType.iterconstants()]
+            else:
+                odRecordTypes = [ODRecordType.fromRecordType(r).value for r in recordTypes]
 
-        # TODO: Add support other value types:
-        valueType = self.fieldName.valueType(expression.fieldName)
-        if valueType == UUID:
-            queryValue = unicode(expression.fieldValue).upper()
-        else:
-            queryValue = unicode(expression.fieldValue)
+            queryAttribute = ODAttribute.fromFieldName(
+                expression.fieldName
+            ).value
 
+            # TODO: Add support other value types:
+            valueType = self.fieldName.valueType(expression.fieldName)
+            if valueType == UUID:
+                queryValue = unicode(expression.fieldValue).upper()
+            else:
+                queryValue = unicode(expression.fieldValue)
+
         if local:
             node = self.localNode
         else:

Modified: twext/trunk/twext/who/opendirectory/test/test_service.py
===================================================================
--- twext/trunk/twext/who/opendirectory/test/test_service.py	2014-07-17 18:54:14 UTC (rev 13770)
+++ twext/trunk/twext/who/opendirectory/test/test_service.py	2014-07-17 19:01:43 UTC (rev 13771)
@@ -82,7 +82,7 @@
                     [
                         u"dsRecTypeStandard:Users",
                         u"dsRecTypeStandard:Groups",
-                        u"dsRecTypeStandard:Locations",
+                        u"dsRecTypeStandard:Places",
                         u"dsRecTypeStandard:Resources",
                     ]
                 )
@@ -112,7 +112,7 @@
                 [
                     u"dsRecTypeStandard:Users",
                     u"dsRecTypeStandard:Groups",
-                    u"dsRecTypeStandard:Locations",
+                    u"dsRecTypeStandard:Places",
                     u"dsRecTypeStandard:Resources",
                 ]
             )
@@ -143,7 +143,7 @@
                 [
                     u"dsRecTypeStandard:Users",
                     u"dsRecTypeStandard:Groups",
-                    u"dsRecTypeStandard:Locations",
+                    u"dsRecTypeStandard:Places",
                     u"dsRecTypeStandard:Resources",
                 ]
             )
@@ -176,7 +176,7 @@
             set(
                 [
                     u"dsRecTypeStandard:Groups", u"dsRecTypeStandard:Users",
-                    u"dsRecTypeStandard:Locations", u"dsRecTypeStandard:Resources",
+                    u"dsRecTypeStandard:Places", u"dsRecTypeStandard:Resources",
                 ]
             )
         )
@@ -229,7 +229,7 @@
                 [
                     u"dsRecTypeStandard:Users",
                     u"dsRecTypeStandard:Groups",
-                    u"dsRecTypeStandard:Locations",
+                    u"dsRecTypeStandard:Places",
                     u"dsRecTypeStandard:Resources",
                 ]
             )
@@ -270,7 +270,7 @@
                 [
                     u"dsRecTypeStandard:Users",
                     u"dsRecTypeStandard:Groups",
-                    u"dsRecTypeStandard:Locations",
+                    u"dsRecTypeStandard:Places",
                     u"dsRecTypeStandard:Resources",
                 ]
             )
@@ -383,7 +383,7 @@
             set(
                 [
                     u"dsRecTypeStandard:Groups",
-                    u"dsRecTypeStandard:Locations",
+                    u"dsRecTypeStandard:Places",
                     u"dsRecTypeStandard:Resources",
                 ]
             )

Modified: twext/trunk/twext/who/xml.py
===================================================================
--- twext/trunk/twext/who/xml.py	2014-07-17 18:54:14 UTC (rev 13770)
+++ twext/trunk/twext/who/xml.py	2014-07-17 19:01:43 UTC (rev 13771)
@@ -472,6 +472,7 @@
         directoryNode = self._directoryNodeForEditing()
 
         def fillRecordNode(recordNode, record):
+            subNode = None
             for (name, value) in record.fields.items():
                 if name == self.fieldName.recordType:
                     if value in recordTypes:
@@ -498,6 +499,7 @@
                             if isinstance(value, UUID):
                                 value = str(value)
                             subNode.text = value
+                            subNode.tail = "\n    "
                             recordNode.append(subNode)
 
                     else:
@@ -505,6 +507,11 @@
                             "Unknown field name: {0!r}".format(name)
                         )
 
+            if subNode is not None:
+                subNode.tail = "\n"
+            recordNode.text = "\n    "
+            recordNode.tail = "\n"
+
         # Walk through the record nodes in the XML tree and apply
         # updates.
         for recordNode in directoryNode:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140717/313172b5/attachment-0001.html>


More information about the calendarserver-changes mailing list