[CalendarServer-changes] [9002] CalendarServer/trunk/calendarserver/tools/shell
source_changes at macosforge.org
source_changes at macosforge.org
Mon Apr 9 17:41:20 PDT 2012
Revision: 9002
http://trac.macosforge.org/projects/calendarserver/changeset/9002
Author: wsanchez at apple.com
Date: 2012-04-09 17:41:20 -0700 (Mon, 09 Apr 2012)
Log Message:
-----------
Have ShellProtocol keep a Commands object as an attribute instead of subclassing from Commands.
Modified Paths:
--------------
CalendarServer/trunk/calendarserver/tools/shell/cmd.py
CalendarServer/trunk/calendarserver/tools/shell/terminal.py
Modified: CalendarServer/trunk/calendarserver/tools/shell/cmd.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/shell/cmd.py 2012-04-10 00:29:13 UTC (rev 9001)
+++ CalendarServer/trunk/calendarserver/tools/shell/cmd.py 2012-04-10 00:41:20 UTC (rev 9002)
@@ -45,9 +45,16 @@
class CommandsBase(object):
- def __init__(self, wd):
+ def __init__(self, protocol, wd):
+ self.service = protocol.service
+ self.protocol = protocol
+
self.wd = wd
+ @property
+ def terminal(self):
+ return self.protocol.terminal
+
#
# Utilities
#
@@ -131,7 +138,7 @@
if tokens:
raise UnknownArguments(tokens)
- self.exit()
+ self.protocol.exit()
def cmd_help(self, tokens):
@@ -215,8 +222,8 @@
usage: emulate editor
"""
if not tokens:
- if self.emulate:
- self.terminal.write("Emulating %s.\n" % (self.emulate,))
+ if self.protocol.emulate:
+ self.terminal.write("Emulating %s.\n" % (self.protocol.emulate,))
else:
self.terminal.write("Emulation disabled.\n")
return
@@ -229,12 +236,12 @@
if editor == "none":
self.terminal.write("Disabling emulation.\n")
editor = None
- elif editor in self.emulation_modes:
+ elif editor in self.protocol.emulation_modes:
self.terminal.write("Emulating %s.\n" % (editor,))
else:
raise UsageError("Unknown editor: %s" % (editor,))
- self.emulate = editor
+ self.protocol.emulate = editor
# FIXME: Need to update key registrations
@@ -242,9 +249,9 @@
def complete_emulate(self, tokens):
if len(tokens) == 0:
- return self.emulation_modes
+ return self.protocol.emulation_modes
elif len(tokens) == 1:
- return self.complete(tokens[0], self.emulation_modes)
+ return self.complete(tokens[0], self.protocol.emulation_modes)
else:
return ()
@@ -325,7 +332,7 @@
def complete_cd(self, tokens):
returnValue((yield self.complete_files(
tokens,
- filter = lambda item: issubclass(item[0], Folder)
+ filter = lambda item: True #issubclass(item[0], Folder)
)))
@@ -421,26 +428,26 @@
if not key.startswith("_"):
localVariables[key] = value
- self._interpreter = ManholeInterpreter(self, localVariables)
+ self._interpreter = ManholeInterpreter(self.protocol, localVariables)
def evalSomePython(line):
if line == "exit":
# Return to normal command mode.
- del self.lineReceived
- del self.ps
- del self.pn
- self.drawInputLine()
+ del self.protocol.lineReceived
+ del self.protocol.ps
+ del self.protocol.pn
+ self.protocol.drawInputLine()
return
more = self._interpreter.push(line)
- self.pn = bool(more)
+ self.protocol.pn = bool(more)
lw = self.terminal.lastWrite
if not (lw.endswith("\n") or lw.endswith("\x1bE")):
self.terminal.write("\n")
- self.drawInputLine()
+ self.protocol.drawInputLine()
- self.lineReceived = evalSomePython
- self.ps = (">>> ", "... ")
+ self.protocol.lineReceived = evalSomePython
+ self.protocol.ps = (">>> ", "... ")
cmd_python.hidden = "Still experimental / untested."
@@ -454,7 +461,7 @@
self.terminal.write(bytes)
if async:
self.terminal.write("\n")
- self.drawInputLine()
+ self.protocol.drawInputLine()
#
Modified: CalendarServer/trunk/calendarserver/tools/shell/terminal.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/shell/terminal.py 2012-04-10 00:29:13 UTC (rev 9001)
+++ CalendarServer/trunk/calendarserver/tools/shell/terminal.py 2012-04-10 00:41:20 UTC (rev 9002)
@@ -114,7 +114,7 @@
os.write(self.terminalFD, "\r\x1bc\r")
-class ShellProtocol(ReceiveLineProtocol, Commands):
+class ShellProtocol(ReceiveLineProtocol):
"""
Data store shell protocol.
"""
@@ -129,9 +129,9 @@
def __init__(self, service):
ReceiveLineProtocol.__init__(self)
- Commands.__init__(self, RootFolder(service))
self.service = service
self.inputLines = []
+ self.commands = Commands(self, RootFolder(service))
self.activeCommand = None
self.emulate = "emacs"
@@ -209,7 +209,7 @@
if cmd and (tokens or word == ""):
# Completing arguments
- m = getattr(self, "complete_%s" % (cmd,), None)
+ m = getattr(self.commands, "complete_%s" % (cmd,), None)
if not m:
return
completions = tuple((yield m(tokens)))
@@ -217,7 +217,7 @@
log.msg("COMPLETIONS: %r" % (completions,))
else:
# Completing command name
- completions = tuple(self._complete_commands(cmd))
+ completions = tuple(self.commands.complete_commands(cmd))
if len(completions) == 1:
for completion in completions:
@@ -265,7 +265,7 @@
cmd = tokens.pop(0)
#print "Arguments: %r" % (tokens,)
- m = getattr(self, "cmd_%s" % (cmd,), None)
+ m = getattr(self.commands, "cmd_%s" % (cmd,), None)
if m:
def handleUsageError(f):
f.trap(CommandUsageError)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120409/f0837d16/attachment.html>
More information about the calendarserver-changes
mailing list