From cb8ee7cd32917fe58a12d4ae767b167356f0a1f5 Mon Sep 17 00:00:00 2001 From: Andrea Crotti Date: Tue, 13 Mar 2012 00:46:31 +0000 Subject: - add a section in the schema to customize the shell - add the shell completion to the python shell - add an option to use IPython, disabled by default --- src/mailman/commands/cli_withlist.py | 32 ++++++++++++++++++++++++++++++-- src/mailman/config/schema.cfg | 9 +++++++++ src/mailman/interact.py | 4 ++-- 3 files changed, 41 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/mailman/commands/cli_withlist.py b/src/mailman/commands/cli_withlist.py index 61e1bec7c..bc25363b1 100644 --- a/src/mailman/commands/cli_withlist.py +++ b/src/mailman/commands/cli_withlist.py @@ -28,6 +28,8 @@ __all__ = [ import re +from lazr.config import as_boolean + from zope.component import getUtility from zope.interface import implements @@ -148,8 +150,34 @@ class Withlist: commit=config.db.commit, abort=config.db.abort, config=config, - ) - interact(upframe=False, banner=banner, overrides=overrides) + ) + banner = '\n'.join([unicode(config.shell.banner), banner]) + if as_boolean(config.shell.use_ipython): + self._start_ipython(overrides, banner) #config.shell.banner) + else: + self._start_python(overrides, banner) #config.shell.banner) + + def _start_ipython(self, overrides, banner): + try: + from IPython.frontend.terminal.embed import InteractiveShellEmbed + ipshell = InteractiveShellEmbed(banner1=banner, + user_ns=overrides) + ipshell() + except ImportError: + print _("ipython is not available, set use_ipython to no") + + def _start_python(self, overrides, banner): + # set the tab completion + import sys + try: + import readline, rlcompleter + readline.parse_and_bind('tab: complete') + except ImportError: + pass + else: + sys.ps1 = config.shell.ps1 + ' ' + interact(upframe=False, banner=config.shell.banner, + overrides=overrides) def _details(self): """Print detailed usage.""" diff --git a/src/mailman/config/schema.cfg b/src/mailman/config/schema.cfg index cde01cbd7..22ad878c7 100644 --- a/src/mailman/config/schema.cfg +++ b/src/mailman/config/schema.cfg @@ -62,6 +62,15 @@ post_hook: # Which paths.* file system layout to use. layout: dev +[shell] + +# customize the interpreter prompt +ps1: << MM >> +# banner to show on startup +banner: welcome to the mailman shell +# if IPython is found use it as the shell +use_ipython: no + [paths.master] # Important directories for Mailman operation. These are defined here so that diff --git a/src/mailman/interact.py b/src/mailman/interact.py index 3e7715c00..613a85b0d 100644 --- a/src/mailman/interact.py +++ b/src/mailman/interact.py @@ -28,7 +28,7 @@ import os import sys import code -DEFAULT_BANNER = object() +DEFAULT_BANNER = "" @@ -69,7 +69,7 @@ def interact(upframe=True, banner=DEFAULT_BANNER, overrides=None): except: pass # We don't want the funky console object in parentheses in the banner. - if banner is DEFAULT_BANNER: + if banner == DEFAULT_BANNER: banner = '''\ Python %s on %s Type "help", "copyright", "credits" or "license" for more information.''' % ( -- cgit v1.2.3-70-g09d2 From f66b5879531dc37509402cc17c1e7bfe817d964c Mon Sep 17 00:00:00 2001 From: Andrea Crotti Date: Tue, 13 Mar 2012 03:39:46 +0000 Subject: various small fixes after reviewing with Barry Warsaw --- src/mailman/commands/cli_withlist.py | 20 +++++++++----------- src/mailman/config/schema.cfg | 8 +++++--- src/mailman/interact.py | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/mailman/commands/cli_withlist.py b/src/mailman/commands/cli_withlist.py index bc25363b1..dd1596227 100644 --- a/src/mailman/commands/cli_withlist.py +++ b/src/mailman/commands/cli_withlist.py @@ -27,9 +27,9 @@ __all__ = [ import re +import sys from lazr.config import as_boolean - from zope.component import getUtility from zope.interface import implements @@ -150,25 +150,24 @@ class Withlist: commit=config.db.commit, abort=config.db.abort, config=config, - ) - banner = '\n'.join([unicode(config.shell.banner), banner]) + ) + + banner = config.shell.banner + '\n' + banner if as_boolean(config.shell.use_ipython): - self._start_ipython(overrides, banner) #config.shell.banner) + self._start_ipython(overrides, banner) else: - self._start_python(overrides, banner) #config.shell.banner) + self._start_python(overrides, banner) def _start_ipython(self, overrides, banner): try: from IPython.frontend.terminal.embed import InteractiveShellEmbed - ipshell = InteractiveShellEmbed(banner1=banner, - user_ns=overrides) + ipshell = InteractiveShellEmbed(banner1=banner, user_ns=overrides) ipshell() except ImportError: - print _("ipython is not available, set use_ipython to no") + print _('ipython is not available, set use_ipython to no') def _start_python(self, overrides, banner): # set the tab completion - import sys try: import readline, rlcompleter readline.parse_and_bind('tab: complete') @@ -176,8 +175,7 @@ class Withlist: pass else: sys.ps1 = config.shell.ps1 + ' ' - interact(upframe=False, banner=config.shell.banner, - overrides=overrides) + interact(upframe=False, banner=banner, overrides=overrides) def _details(self): """Print detailed usage.""" diff --git a/src/mailman/config/schema.cfg b/src/mailman/config/schema.cfg index 22ad878c7..d0a8e9e20 100644 --- a/src/mailman/config/schema.cfg +++ b/src/mailman/config/schema.cfg @@ -66,9 +66,11 @@ layout: dev # customize the interpreter prompt ps1: << MM >> -# banner to show on startup -banner: welcome to the mailman shell -# if IPython is found use it as the shell + +# Banner to show on startup. +banner: welcome to the GNU Mailman shell + +# If IPython is found use it as the shell use_ipython: no diff --git a/src/mailman/interact.py b/src/mailman/interact.py index 613a85b0d..25dcfbc85 100644 --- a/src/mailman/interact.py +++ b/src/mailman/interact.py @@ -28,7 +28,7 @@ import os import sys import code -DEFAULT_BANNER = "" +DEFAULT_BANNER = '' -- cgit v1.2.3-70-g09d2