[CalendarServer-changes] [9024] CalendarServer/trunk/calendarserver/tools/shell

source_changes at macosforge.org source_changes at macosforge.org
Tue Apr 10 16:56:47 PDT 2012


Revision: 9024
          http://trac.macosforge.org/projects/calendarserver/changeset/9024
Author:   wsanchez at apple.com
Date:     2012-04-10 16:56:46 -0700 (Tue, 10 Apr 2012)
Log Message:
-----------
Add (incomplete) find_principals command.

Modified Paths:
--------------
    CalendarServer/trunk/calendarserver/tools/shell/cmd.py
    CalendarServer/trunk/calendarserver/tools/shell/vfs.py

Modified: CalendarServer/trunk/calendarserver/tools/shell/cmd.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/shell/cmd.py	2012-04-10 23:06:04 UTC (rev 9023)
+++ CalendarServer/trunk/calendarserver/tools/shell/cmd.py	2012-04-10 23:56:46 UTC (rev 9024)
@@ -18,6 +18,8 @@
 Data store commands.
 """
 
+import operator
+
 #from twisted.python import log
 from twisted.internet.defer import succeed
 from twisted.internet.defer import inlineCallbacks, returnValue
@@ -29,6 +31,7 @@
 from calendarserver.tools.tables import Table
 from calendarserver.tools.shell.vfs import Folder, RootFolder
 
+
 class UsageError(Exception):
     """
     Usage error.
@@ -442,6 +445,63 @@
 
 
     #
+    # Principal tools
+    #
+    @inlineCallbacks
+    def cmd_find_principal(self, tokens):
+        """
+        Search for a principal
+
+        usage: find_principal term
+        """
+        if not tokens:
+            raise UsageError("No search term")
+
+        term = tokens.pop(0)
+
+        if tokens:
+            raise UnknownArguments(tokens)
+
+        searchFieldNames = ("fullName", "firstName", "lastName", "emailAddresses")
+
+        records = sorted(tuple((yield self.protocol.service.directory.recordsMatchingFields(
+            (fieldName, term, True, "contains")
+            for fieldName in searchFieldNames
+        ))), key=operator.attrgetter("fullName"))
+
+        if records:
+            table = Table()
+
+            table.addHeader((
+                "UID",
+                "Record Type",
+                "Short Names",
+                "Email Addresses",
+                "Full Name",
+            ))
+
+            def first(items):
+                if items:
+                    return items[0]
+                else:
+                    return None
+
+            for record in records:
+                table.addRow((
+                    record.uid,
+                    record.recordType,
+                    first(record.shortNames),
+                    first(record.emailAddresses),
+                    record.fullName,
+                ))
+
+            table.printTable(self.terminal)
+            self.terminal.nextLine()
+
+    cmd_find_principal.hidden = "Not done yet"
+
+
+    #
     # Python prompt, for the win
     #
 

Modified: CalendarServer/trunk/calendarserver/tools/shell/vfs.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/shell/vfs.py	2012-04-10 23:06:04 UTC (rev 9023)
+++ CalendarServer/trunk/calendarserver/tools/shell/vfs.py	2012-04-10 23:56:46 UTC (rev 9024)
@@ -693,6 +693,7 @@
     table.printTable(os=output)
     return output.getvalue()
 
+
 def tableStringForProperties(properties):
     return "Properties:\n%s" % (tableString((
         (name.toString(), truncateAtNewline(properties[name]))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120410/3621cb2a/attachment.html>


More information about the calendarserver-changes mailing list