[CalendarServer-changes] [8789] CalendarServer/branches/users/glyph/case-insensitive-uid
source_changes at macosforge.org
source_changes at macosforge.org
Wed Feb 29 10:15:55 PST 2012
Revision: 8789
http://trac.macosforge.org/projects/calendarserver/changeset/8789
Author: glyph at apple.com
Date: 2012-02-29 10:15:55 -0800 (Wed, 29 Feb 2012)
Log Message:
-----------
Add a simple interactive Python shell to calendarserver_shell for some diagnostics.
Modified Paths:
--------------
CalendarServer/branches/users/glyph/case-insensitive-uid/calendarserver/tools/shell/cmd.py
Property Changed:
----------------
CalendarServer/branches/users/glyph/case-insensitive-uid/
Modified: CalendarServer/branches/users/glyph/case-insensitive-uid/calendarserver/tools/shell/cmd.py
===================================================================
--- CalendarServer/branches/users/glyph/case-insensitive-uid/calendarserver/tools/shell/cmd.py 2012-02-29 18:15:52 UTC (rev 8788)
+++ CalendarServer/branches/users/glyph/case-insensitive-uid/calendarserver/tools/shell/cmd.py 2012-02-29 18:15:55 UTC (rev 8789)
@@ -23,12 +23,13 @@
from twisted.internet.defer import succeed
from twisted.internet.defer import inlineCallbacks, returnValue
+from twisted.conch.manhole import ManholeInterpreter
+
from txdav.common.icommondatastore import NotFoundError
from calendarserver.tools.tables import Table
from calendarserver.tools.shell.vfs import Folder
-
class UsageError(Exception):
"""
Usage error.
@@ -340,14 +341,47 @@
"""
self.exit()
+
+ interpreter = None
+
def cmd_python(self, tokens):
"""
Switch to a python prompt.
usage: python
"""
- # Crazy idea #19568: switch to an interactive python prompt
- # with self exposed in globals.
- raise NotImplementedError()
+ if self.interpreter is None:
+ # Bring in some helpful local variables.
+ from txdav.common.datastore.sql_tables import schema
+ from twext.enterprise.dal import syntax
+ lcls = dict(self=self, store=self.service.store, schema=schema)
+ for key, value in syntax.__dict__.items():
+ if not key.startswith("_"):
+ lcls[key] = value
+ self.interpreter = ManholeInterpreter(self, lcls)
+ def evalSomePython(line):
+ if line == 'exit':
+ # return to normal command mode.
+ del self.lineReceived
+ del self.ps
+ del self.pn
+ self.drawInputLine()
+ return
+ more = self.interpreter.push(line)
+ self.pn = bool(more)
+ lw = self.terminal.lastWrite
+ if not (lw.endswith("\n") or lw.endswith("\x1bE")):
+ self.terminal.write("\n")
+ self.drawInputLine()
+ self.lineReceived = evalSomePython
+ self.ps = ('>>> ', '... ')
- cmd_python.hidden = "Not implemented"
+ def addOutput(self, bytes, async=False):
+ if async:
+ self.terminal.write("... interrupted for Deferred ...\n")
+ self.terminal.write(bytes)
+ if async:
+ self.terminal.write("\n")
+ self.drawInputLine()
+
+ cmd_python.hidden = "Still experimental / untested."
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120229/ec487e27/attachment-0001.html>
More information about the calendarserver-changes
mailing list