[CalendarServer-changes] [3963] PyOpenDirectory/trunk/duplicateguids.py

source_changes at macosforge.org source_changes at macosforge.org
Thu Apr 9 06:42:05 PDT 2009


Revision: 3963
          http://trac.macosforge.org/projects/calendarserver/changeset/3963
Author:   cdaboo at apple.com
Date:     2009-04-09 06:42:02 -0700 (Thu, 09 Apr 2009)
Log Message:
-----------
Script to check for duplicate GUIDs in the directory.

Added Paths:
-----------
    PyOpenDirectory/trunk/duplicateguids.py

Added: PyOpenDirectory/trunk/duplicateguids.py
===================================================================
--- PyOpenDirectory/trunk/duplicateguids.py	                        (rev 0)
+++ PyOpenDirectory/trunk/duplicateguids.py	2009-04-09 13:42:02 UTC (rev 3963)
@@ -0,0 +1,57 @@
+##
+# Copyright (c) 2006-2009 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.
+##
+
+import opendirectory
+import dsattributes
+from dsquery import expression, match
+
+try:
+	ref = opendirectory.odInit("/Search")
+	if ref is None:
+		print "Failed odInit"
+	else:
+		print "OK odInit"
+
+	guids = {}
+	for recordType in (
+		dsattributes.kDSStdRecordTypeUsers,
+		dsattributes.kDSStdRecordTypeGroups,
+		dsattributes.kDSStdRecordTypePlaces,
+		dsattributes.kDSStdRecordTypeResources):
+		
+		d = opendirectory.listAllRecordsWithAttributes(ref, recordType,
+													   (
+													   	dsattributes.kDS1AttrGeneratedUID,
+													   ))
+
+		for name, attrs in d.iteritems():
+			name = "%s/%s" % (recordType, name,)
+			try:
+				guid = attrs[dsattributes.kDS1AttrGeneratedUID]
+				if guid in guids:
+					print "Duplicate GUIDs for %s and %s: %s" % (guids[guid], name, guid,)
+				else:
+					guids[guid] = name
+			except KeyError:
+				print "No GUID for %s" % (name,)
+
+	ref = None
+except opendirectory.ODError, ex:
+	print ex
+except Exception, e:
+	print e
+
+print "Done."
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20090409/ed67d868/attachment.html>


More information about the calendarserver-changes mailing list