Revision
9273
Author
glyph@apple.com
Date
2012-05-24 13:33:32 -0700 (Thu, 24 May 2012)

Log Message

UUID normalizer for augment records.

Modified Paths

Diff

Modified: CalendarServer/branches/users/glyph/uuid-normalize/twistedcaldav/directory/augment.py (9272 => 9273)


--- CalendarServer/branches/users/glyph/uuid-normalize/twistedcaldav/directory/augment.py	2012-05-24 20:33:28 UTC (rev 9272)
+++ CalendarServer/branches/users/glyph/uuid-normalize/twistedcaldav/directory/augment.py	2012-05-24 20:33:32 UTC (rev 9273)
@@ -88,8 +88,32 @@
     def __init__(self):
         
         self.cachedRecords = {}
-    
+
+
     @inlineCallbacks
+    def normalizeUUIDs(self):
+        """
+        Normalize (uppercase) all augment UIDs which are parseable as UUIDs.
+
+        @return: a L{Deferred} that fires when all records have been
+            normalized.
+        """
+        from txdav.base.datastore.util import normalizeUUIDOrNot
+        remove = []
+        add = []
+        for uid in (yield self.getAllUIDs()):
+            nuid = normalizeUUIDOrNot(uid)
+            if uid != nuid:
+                old = yield self._lookupAugmentRecord(uid)
+                new = copy.deepcopy(old)
+                new.uid = uid.upper()
+                remove.append(old)
+                add.append(new)
+        yield self.removeAugmentRecords(remove)
+        yield self.addAugmentRecords(add)
+
+
+    @inlineCallbacks
     def getAugmentRecord(self, uid, recordType):
         """
         Get an AugmentRecord for the specified UID or the default.
@@ -244,16 +268,15 @@
         self.lastCached = time.time()
 
 
-    @inlineCallbacks
     def getAllUIDs(self):
         """
         Get all AugmentRecord UIDs.
 
         @return: L{Deferred}
         """
-        
         return succeed(self.db.keys())
 
+
     def _lookupAugmentRecord(self, uid):
         """
         Get an AugmentRecord for the specified UID.