Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 3 commits
  • 1 file changed
  • 0 commit comments
  • 1 contributor
Showing with 47 additions and 7 deletions.
  1. +47 −7 twisted/plugins/warp_plugin.py
View
54 twisted/plugins/warp_plugin.py
@@ -34,6 +34,11 @@ class CommandOptions(usage.Options):
def parseArgs(self, fqn):
self['fqn'] = fqn
+class ConsoleOptions(usage.Options):
+ def parseArgs(self, interpreter=None):
+ if interpreter:
+ self["interpreter"] = interpreter
+
class Options(usage.Options):
optParameters = (
("siteDir", "d", ".", "Base directory of the warp site"),
@@ -44,7 +49,7 @@ class Options(usage.Options):
("node", None, NodeOptions, "Create a new node"),
("crud", None, CrudOptions, "Create a new CRUD node"),
("adduser", None, usage.Options, "Add a user (interactive)"),
- ("console", None, usage.Options, "Python console with Warp runtime available"),
+ ("console", None, ConsoleOptions, "Python console with Warp runtime available"),
("command", "c", CommandOptions, "Run a site-specific command"),
)
@@ -107,18 +112,36 @@ def makeService(self, options):
if hasattr(configModule, 'startup'):
configModule.startup()
+ # Start a console instead of the site
if options.subCommand == "console":
- import code
locals = {'store': runtime.store}
- c = code.InteractiveConsole(locals)
- c.interact()
+ interpreter = options.subOptions.get("interpreter",
+ config.get("console", {}).get("interpreter", "python"))
+ if interpreter == "python":
+ import code
+ c = code.InteractiveConsole(locals)
+ c.interact()
+ elif interpreter == "bpython":
+ try:
+ from bpython import cli
+ cli.main(["-i", "-q"], locals_ = locals, banner = "Available: %s" % locals)
+ except ImportError:
+ print "bpython module not found!"
+ elif interpreter == "ipython":
+ try:
+ from IPython.Shell import IPShellEmbed
+ IPShellEmbed()(local_ns = locals, header = "Available: %s" % locals)
+ except ImportError:
+ print "ipython module not found!"
+ else:
+ print "Unsupported interpreter"
raise SystemExit
-
+
if options.subCommand == 'command':
obj = reflect.namedObject(options.subOptions['fqn'])
obj()
raise SystemExit
-
+
if config.get('ssl'):
from warp.webserver import sslcontext
@@ -130,7 +153,24 @@ def makeService(self, options):
if hasattr(configModule, 'mungeService'):
service = configModule.mungeService(service)
- return service
+ # Start a remote console if console:port and
+ # console:passwd_file are specified
+ passwd = config.get("console", {}).get("passwd_file")
+ if passwd:
+ from twisted.conch import manhole_tap
+ from twisted.application.service import MultiService
+ manhole = manhole_tap.makeService({
+ "namespace": {"store": runtime.store},
+ "sshPort": "tcp:%s:interface=127.0.0.1" % config["console"]["sshPort"],
+ "telnetPort": "tcp:%s:interface=127.0.0.1" % config["console"]["telnetPort"],
+ "passwd": passwd,
+ })
+
+ ms = MultiService()
+ manhole.setServiceParent(ms)
+ service.setServiceParent(ms)
+ return ms
+ return service
serviceMaker = WarpServiceMaker()

No commit comments for this range

Something went wrong with that request. Please try again.