[CalendarServer-changes] [9031] CalendarServer/trunk/calendarserver/tools/shell/cmd.py
source_changes at macosforge.org
source_changes at macosforge.org
Wed Apr 11 15:15:14 PDT 2012
Revision: 9031
http://trac.macosforge.org/projects/calendarserver/changeset/9031
Author: wsanchez at apple.com
Date: 2012-04-11 15:15:14 -0700 (Wed, 11 Apr 2012)
Log Message:
-----------
Keep the terminal from wedging when in python sub-shell.
Allow multiple args to find_principals.
Modified Paths:
--------------
CalendarServer/trunk/calendarserver/tools/shell/cmd.py
Modified: CalendarServer/trunk/calendarserver/tools/shell/cmd.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/shell/cmd.py 2012-04-11 15:45:12 UTC (rev 9030)
+++ CalendarServer/trunk/calendarserver/tools/shell/cmd.py 2012-04-11 22:15:14 UTC (rev 9031)
@@ -457,17 +457,13 @@
if not tokens:
raise UsageError("No search term")
- term = tokens.pop(0)
+ for token in tokens:
+ searchFieldNames = ("fullName", "firstName", "lastName", "emailAddresses")
+ searchFields = tuple(
+ (fieldName, token, True, "contains")
+ for fieldName in searchFieldNames
+ )
- if tokens:
- raise UnknownArguments(tokens)
-
- searchFieldNames = ("fullName", "firstName", "lastName", "emailAddresses")
- searchFields = tuple(
- (fieldName, term, True, "contains")
- for fieldName in searchFieldNames
- )
-
records = (yield self.protocol.service.directory.recordsMatchingFields(searchFields))
records = sorted(tuple(records), key=operator.attrgetter("fullName"))
@@ -530,19 +526,35 @@
if not key.startswith("_"):
localVariables[key] = value
- self._interpreter = ManholeInterpreter(self.protocol, localVariables)
+ class Handler(object):
+ def addOutput(innerSelf, bytes, async=False):
+ """
+ This is a delegate method, called by ManholeInterpreter.
+ """
+ if async:
+ self.terminal.write("... interrupted for Deferred ...\n")
+ self.terminal.write(bytes)
+ if async:
+ self.terminal.write("\n")
+ self.protocol.drawInputLine()
+ self._interpreter = ManholeInterpreter(Handler(), localVariables)
+
def evalSomePython(line):
if line == "exit":
# Return to normal command mode.
del self.protocol.lineReceived
del self.protocol.ps
- del self.protocol.pn
+ try:
+ del self.protocol.pn
+ except AttributeError:
+ pass
self.protocol.drawInputLine()
return
more = self._interpreter.push(line)
self.protocol.pn = bool(more)
+
lw = self.terminal.lastWrite
if not (lw.endswith("\n") or lw.endswith("\x1bE")):
self.terminal.write("\n")
@@ -554,18 +566,6 @@
cmd_python.hidden = "Still experimental / untested."
- def addOutput(self, bytes, async=False):
- """
- This is a delegate method, called by ManholeInterpreter.
- """
- if async:
- self.terminal.write("... interrupted for Deferred ...\n")
- self.terminal.write(bytes)
- if async:
- self.terminal.write("\n")
- self.protocol.drawInputLine()
-
-
#
# SQL prompt, for not as winning
#
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120411/f5b16707/attachment-0001.html>
More information about the calendarserver-changes
mailing list