[CalendarServer-changes] [5399] CalendarServer/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Thu Mar 25 11:39:02 PDT 2010
Revision: 5399
http://trac.macosforge.org/projects/calendarserver/changeset/5399
Author: sagen at apple.com
Date: 2010-03-25 11:39:01 -0700 (Thu, 25 Mar 2010)
Log Message:
-----------
Reviving calendarserver_manage_principals --search
Modified Paths:
--------------
CalendarServer/trunk/calendarserver/tools/principals.py
CalendarServer/trunk/calendarserver/tools/test/test_principals.py
CalendarServer/trunk/doc/calendarserver_manage_principals.8
Modified: CalendarServer/trunk/calendarserver/tools/principals.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/principals.py 2010-03-25 03:43:52 UTC (rev 5398)
+++ CalendarServer/trunk/calendarserver/tools/principals.py 2010-03-25 18:39:01 UTC (rev 5399)
@@ -65,7 +65,7 @@
print " -f --config <path>: Specify caldavd.plist configuration path"
print ""
print "actions:"
- #print " --search <search-string>: search for matching resources"
+ print " --search <search-string>: search for matching principals"
print " --list-principal-types: list all of the known principal types"
print " --list-principals type: list all principals of the given type"
print " --read-property=property: read DAV property (eg.: {DAV:}group-member-set)"
@@ -89,7 +89,7 @@
sys.argv[1:], "hf:P:", [
"help",
"config=",
- #"search=",
+ "search=",
"list-principal-types",
"list-principals=",
"read-property=",
@@ -112,6 +112,7 @@
configFileName = None
listPrincipalTypes = False
listPrincipals = None
+ searchPrincipals = None
principalActions = []
for opt, arg in optargs:
@@ -127,6 +128,9 @@
elif opt in ("", "--list-principals"):
listPrincipals = arg
+ elif opt in ("", "--search"):
+ searchPrincipals = arg
+
elif opt in ("", "--read-property"):
try:
qname = sname2qname(arg)
@@ -223,7 +227,7 @@
return
- if listPrincipals:
+ elif listPrincipals:
if args:
usage("Too many arguments")
@@ -237,27 +241,35 @@
return
- #
- # Do a quick sanity check that arguments look like principal
- # identifiers.
- #
- if not args:
- usage("No principals specified.")
+ elif searchPrincipals:
+ params = (runSearch, searchPrincipals)
- for arg in args:
- try:
- principalForPrincipalID(arg, checkOnly=True)
- except ValueError, e:
- abort(e)
+ else:
+ #
+ # Do a quick sanity check that arguments look like principal
+ # identifiers.
+ #
+ if not args:
+ usage("No principals specified.")
+ for arg in args:
+ try:
+ principalForPrincipalID(arg, checkOnly=True)
+ except ValueError, e:
+ abort(e)
+
+ params = (runPrincipalActions, args, principalActions)
+
#
# Start the reactor
#
- reactor.callLater(0, run, args, principalActions)
+ reactor.callLater(0, *params)
reactor.run()
+
+
@inlineCallbacks
-def run(principalIDs, actions):
+def runPrincipalActions(principalIDs, actions):
try:
for principalID in principalIDs:
# Resolve the given principal IDs to principals
@@ -281,7 +293,44 @@
#
reactor.stop()
+ at inlineCallbacks
+def runSearch(searchTerm):
+ try:
+ fields = []
+ for fieldName in ("fullName", "firstName", "lastName", "emailAddresses"):
+ fields.append((fieldName, searchTerm, True, "contains"))
+
+ records = list((yield config.directory.recordsMatchingFields(fields)))
+ if records:
+ records.sort(key=operator.attrgetter('fullName'))
+ print "%d matches found:" % (len(records),)
+ for record in records:
+ print "\n%s (%s)" % (record.fullName,
+ { "users" : "User",
+ "groups" : "Group",
+ "locations" : "Place",
+ "resources" : "Resource",
+ }.get(record.recordType),
+ )
+ print " GUID: %s" % (record.guid,)
+ print " Record name(s): %s" % (", ".join(record.shortNames),)
+ if record.authIDs:
+ print " Auth ID(s): %s" % (", ".join(record.authIDs),)
+ if record.emailAddresses:
+ print " Email(s): %s" % (", ".join(record.emailAddresses),)
+ else:
+ print "No matches found"
+
+ print ""
+
+ finally:
+ #
+ # Stop the reactor
+ #
+ reactor.stop()
+
+
def principalForPrincipalID(principalID, checkOnly=False, directory=None):
# Allow a directory parameter to be passed in, but default to config.directory
@@ -488,44 +537,26 @@
)
@inlineCallbacks
-def _run(directory, root, optargs, principalIDs):
+def action_searchPrincipals(principal, *proxyTypes):
+ for proxyType in proxyTypes:
+ subPrincipal = proxySubprincipal(principal, proxyType)
+ if subPrincipal is None:
+ print "No %s proxies for %s" % (proxyType, principal)
+ continue
- print ""
+ membersProperty = (yield subPrincipal.readProperty(davxml.GroupMemberSet, None))
- for opt, arg in optargs:
+ if membersProperty.children:
+ print "%s proxies for %s:" % (
+ {"read": "Read-only", "write": "Read/write"}[proxyType],
+ principal,
+ )
+ for member in membersProperty.children:
+ print " *", member
+ else:
+ print "No %s proxies for %s" % (proxyType, principal)
- if opt in ("-s", "--search",):
- fields = []
- for fieldName in ("fullName", "firstName", "lastName",
- "emailAddresses"):
- fields.append((fieldName, arg, True, "contains"))
- records = list((yield config.directory.recordsMatchingFields(fields)))
- if records:
- records.sort(key=operator.attrgetter('fullName'))
- print "%d matches found:" % (len(records),)
- for record in records:
- print "\n%s (%s)" % (record.fullName,
- { "users" : "User",
- "groups" : "Group",
- "locations" : "Place",
- "resources" : "Resource",
- }.get(record.recordType),
- )
- print record.guid
- print " Record names: %s" % (", ".join(record.shortNames),)
- if record.authIDs:
- print " Auth IDs: %s" % (", ".join(record.authIDs),)
- if record.emailAddresses:
- print " Emails: %s" % (", ".join(record.emailAddresses),)
- else:
- print "No matches found"
-
- print ""
-
- # reactor.callLater(0, reactor.stop)
- reactor.stop()
-
def abort(msg, status=1):
sys.stdout.write("%s\n" % (msg,))
try:
Modified: CalendarServer/trunk/calendarserver/tools/test/test_principals.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/test/test_principals.py 2010-03-25 03:43:52 UTC (rev 5398)
+++ CalendarServer/trunk/calendarserver/tools/test/test_principals.py 2010-03-25 18:39:01 UTC (rev 5399)
@@ -105,6 +105,13 @@
self.assertTrue("user%02d" % (i,) in results)
@inlineCallbacks
+ def test_search(self):
+ results = yield self.runCommand("--search=user")
+ self.assertTrue("10 matches found" in results)
+ for i in xrange(1, 10):
+ self.assertTrue("user%02d" % (i,) in results)
+
+ @inlineCallbacks
def test_modifyWriteProxies(self):
results = yield self.runCommand("--add-write-proxy=users:user01",
"locations:location01")
Modified: CalendarServer/trunk/doc/calendarserver_manage_principals.8
===================================================================
--- CalendarServer/trunk/doc/calendarserver_manage_principals.8 2010-03-25 03:43:52 UTC (rev 5398)
+++ CalendarServer/trunk/doc/calendarserver_manage_principals.8 2010-03-25 18:39:01 UTC (rev 5399)
@@ -26,6 +26,7 @@
.Op Fl -read-property Ar property
.Op Fl -list-principal-types
.Op Fl -list-principals Ar type
+.Op Fl -search Ar search-string
.Op Fl -list-read-proxies
.Op Fl -list-write-proxies
.Op Fl -list-proxies
@@ -89,6 +90,8 @@
List all of the known principals types.
.It Fl -list-principals Ar type
List all of the principals of the given type.
+.It Fl -search Ar search-string
+Search for principals whose name or email address contains the search string.
.It Fl -list-read-proxies
List the read proxies.
.It Fl -list-write-proxies
@@ -125,6 +128,10 @@
.Pp
.Dl "calendarserver_manage_principals --set-auto-schedule true --get-auto-schedule resources:projector"
.Pp
+Search for all principals named Joe:
+.Pp
+.Dl "calendarserver_manage_principals --search joe"
+.Pp
.Sh FILES
.Bl -tag -width flag
.It /etc/caldavd/caldavd.plist
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100325/a71aa1ff/attachment.html>
More information about the calendarserver-changes
mailing list