summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBarry Warsaw2012-03-12 22:01:58 -0700
committerBarry Warsaw2012-03-12 22:01:58 -0700
commitb725360062b08a422f337b272bdbb56b7a41f51d (patch)
tree32774958effa98f2b52e13bae84e814639f49ec8 /src
parent5f69c4e7c9ee532065e4c19a862f915b2178d482 (diff)
parentf66b5879531dc37509402cc17c1e7bfe817d964c (diff)
downloadmailman-b725360062b08a422f337b272bdbb56b7a41f51d.tar.gz
mailman-b725360062b08a422f337b272bdbb56b7a41f51d.tar.zst
mailman-b725360062b08a422f337b272bdbb56b7a41f51d.zip
Diffstat (limited to 'src')
-rw-r--r--src/mailman/commands/cli_withlist.py31
-rw-r--r--src/mailman/commands/docs/withlist.rst19
-rw-r--r--src/mailman/config/schema.cfg15
-rw-r--r--src/mailman/docs/NEWS.rst2
-rw-r--r--src/mailman/interact.py5
5 files changed, 64 insertions, 8 deletions
diff --git a/src/mailman/commands/cli_withlist.py b/src/mailman/commands/cli_withlist.py
index 61e1bec7c..7bf7c4384 100644
--- a/src/mailman/commands/cli_withlist.py
+++ b/src/mailman/commands/cli_withlist.py
@@ -27,7 +27,9 @@ __all__ = [
import re
+import sys
+from lazr.config import as_boolean
from zope.component import getUtility
from zope.interface import implements
@@ -149,7 +151,30 @@ class Withlist:
abort=config.db.abort,
config=config,
)
- interact(upframe=False, banner=banner, overrides=overrides)
+ banner = config.shell.banner + '\n' + banner
+ if as_boolean(config.shell.use_ipython):
+ self._start_ipython(overrides, banner)
+ else:
+ 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()
+ except ImportError:
+ print _('ipython is not available, set use_ipython to no')
+
+ def _start_python(self, overrides, banner):
+ # Set the tab completion.
+ try:
+ import readline, rlcompleter
+ readline.parse_and_bind('tab: complete')
+ except ImportError:
+ pass
+ else:
+ sys.ps1 = config.shell.prompt + ' '
+ interact(upframe=False, banner=banner, overrides=overrides)
def _details(self):
"""Print detailed usage."""
@@ -214,9 +239,9 @@ and run this from the command line:
% bin/mailman withlist -r change mylist@example.com 'My List'""")
-
+
class Shell(Withlist):
"""An alias for `withlist`."""
-
+
name = 'shell'
diff --git a/src/mailman/commands/docs/withlist.rst b/src/mailman/commands/docs/withlist.rst
index 7632c726a..f00208490 100644
--- a/src/mailman/commands/docs/withlist.rst
+++ b/src/mailman/commands/docs/withlist.rst
@@ -119,7 +119,20 @@ You also get an error if no mailing list is named.
--run requires a mailing list name
-Clean up
-========
+IPython
+=======
- >>> sys.path = old_path
+You can use `IPython`_ as the interactive shell by changing certain
+configuration variables in the `[shell]` section of your `mailman.cfg` file.
+Set `use_ipython` to "yes" to switch to IPython, which must be installed on
+your system.
+
+Other configuration variables in the `[shell]` section can be used to
+configure other aspects of the interactive shell. You can change both the
+prompt and the banner.
+
+
+.. Clean up
+ >>> sys.path = old_path
+
+.. _`IPython`: http://ipython.org/
diff --git a/src/mailman/config/schema.cfg b/src/mailman/config/schema.cfg
index cde01cbd7..e662633e6 100644
--- a/src/mailman/config/schema.cfg
+++ b/src/mailman/config/schema.cfg
@@ -62,6 +62,21 @@ post_hook:
# Which paths.* file system layout to use.
layout: dev
+[shell]
+# `bin/mailman shell` (also `withlist`) gives you an interactive prompt that
+# you can use to interact with an initialized and configured Mailman system.
+# Use --help for more information. This section allows you to configure
+# certain aspects of this interactive shell.
+
+# Customize the interpreter prompt.
+prompt: >>>
+
+# Banner to show on startup.
+banner: Welcome to the GNU Mailman shell
+
+# Use IPython as the shell, which must be found on the system.
+use_ipython: no
+
[paths.master]
# Important directories for Mailman operation. These are defined here so that
diff --git a/src/mailman/docs/NEWS.rst b/src/mailman/docs/NEWS.rst
index 80b17f30b..a7e4a49ea 100644
--- a/src/mailman/docs/NEWS.rst
+++ b/src/mailman/docs/NEWS.rst
@@ -78,6 +78,8 @@ Interfaces
Commands
--------
+ * IPython support in `bin/mailman shell` contributed by Andrea Crotti.
+ (LP: #949926).
* The `mailman.cfg` configuration file will now automatically be detected if
it exists in an `etc` directory which is a sibling of argv0.
* `bin/mailman shell` is an alias for `withlist`.
diff --git a/src/mailman/interact.py b/src/mailman/interact.py
index 3e7715c00..dd6bac9f0 100644
--- a/src/mailman/interact.py
+++ b/src/mailman/interact.py
@@ -24,11 +24,12 @@ __all__ = [
'interact',
]
+
import os
import sys
import code
-DEFAULT_BANNER = object()
+DEFAULT_BANNER = ''
@@ -69,7 +70,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.''' % (