summaryrefslogtreecommitdiff
path: root/src/mailman/commands
diff options
context:
space:
mode:
Diffstat (limited to 'src/mailman/commands')
-rw-r--r--src/mailman/commands/cli_qfile.py2
-rw-r--r--src/mailman/commands/cli_withlist.py33
-rw-r--r--src/mailman/commands/docs/inject.rst53
-rw-r--r--src/mailman/commands/docs/withlist.rst19
4 files changed, 72 insertions, 35 deletions
diff --git a/src/mailman/commands/cli_qfile.py b/src/mailman/commands/cli_qfile.py
index 5851388de..78156f08c 100644
--- a/src/mailman/commands/cli_qfile.py
+++ b/src/mailman/commands/cli_qfile.py
@@ -31,8 +31,8 @@ from pprint import PrettyPrinter
from zope.interface import implements
from mailman.core.i18n import _
-from mailman.interact import interact
from mailman.interfaces.command import ICLISubCommand
+from mailman.utilities.interact import interact
m = []
diff --git a/src/mailman/commands/cli_withlist.py b/src/mailman/commands/cli_withlist.py
index 61e1bec7c..3b1b36b1a 100644
--- a/src/mailman/commands/cli_withlist.py
+++ b/src/mailman/commands/cli_withlist.py
@@ -27,15 +27,17 @@ __all__ = [
import re
+import sys
+from lazr.config import as_boolean
from zope.component import getUtility
from zope.interface import implements
from mailman.config import config
from mailman.core.i18n import _
-from mailman.interact import DEFAULT_BANNER, interact
from mailman.interfaces.command import ICLISubCommand
from mailman.interfaces.listmanager import IListManager
+from mailman.utilities.interact import DEFAULT_BANNER, interact
from mailman.utilities.modules import call_name
# Global holding onto the open mailing list.
@@ -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/inject.rst b/src/mailman/commands/docs/inject.rst
index e8fc088c0..7150beac7 100644
--- a/src/mailman/commands/docs/inject.rst
+++ b/src/mailman/commands/docs/inject.rst
@@ -54,6 +54,7 @@ Usually, the text of the message to inject is in a file.
... From: aperson@example.com
... To: test@example.com
... Subject: testing
+ ... Message-ID: <aardvark>
...
... This is a test message.
... """
@@ -69,22 +70,20 @@ Let's provide a list name and try again.
>>> mlist = create_list('test@example.com')
>>> transaction.commit()
+ >>> from mailman.testing.helpers import get_queue_messages
- >>> in_queue = config.switchboards['in']
- >>> len(in_queue.files)
- 0
+ >>> get_queue_messages('in')
+ []
>>> args.listname = ['test@example.com']
>>> command.process(args)
By default, the incoming queue is used.
::
- >>> len(in_queue.files)
+ >>> items = get_queue_messages('in')
+ >>> len(items)
1
-
- >>> from mailman.testing.helpers import get_queue_messages
- >>> item = get_queue_messages('in')[0]
- >>> print item.msg.as_string()
+ >>> print items[0].msg.as_string()
From: aperson@example.com
To: test@example.com
Subject: testing
@@ -95,10 +94,10 @@ By default, the incoming queue is used.
<BLANKLINE>
<BLANKLINE>
- >>> dump_msgdata(item.msgdata)
+ >>> dump_msgdata(items[0].msgdata)
_parsemsg : False
listname : test@example.com
- original_size: 90
+ original_size: 203
version : 3
But a different queue can be specified on the command line.
@@ -107,13 +106,12 @@ But a different queue can be specified on the command line.
>>> args.queue = 'virgin'
>>> command.process(args)
- >>> len(in_queue.files)
- 0
- >>> virgin_queue = config.switchboards['virgin']
- >>> len(virgin_queue.files)
+ >>> get_queue_messages('in')
+ []
+ >>> items = get_queue_messages('virgin')
+ >>> len(items)
1
- >>> item = get_queue_messages('virgin')[0]
- >>> print item.msg.as_string()
+ >>> print items[0].msg.as_string()
From: aperson@example.com
To: test@example.com
Subject: testing
@@ -124,10 +122,10 @@ But a different queue can be specified on the command line.
<BLANKLINE>
<BLANKLINE>
- >>> dump_msgdata(item.msgdata)
+ >>> dump_msgdata(items[0].msgdata)
_parsemsg : False
listname : test@example.com
- original_size: 90
+ original_size: 203
version : 3
@@ -144,6 +142,7 @@ The message text can also be provided on standard input.
... From: bperson@example.com
... To: test@example.com
... Subject: another test
+ ... Message-ID: <badger>
...
... This is another test message.
... """))
@@ -154,10 +153,10 @@ The message text can also be provided on standard input.
>>> args.queue = None
>>> command.process(args)
- >>> len(in_queue.files)
+ >>> items = get_queue_messages('in')
+ >>> len(items)
1
- >>> item = get_queue_messages('in')[0]
- >>> print item.msg.as_string()
+ >>> print items[0].msg.as_string()
From: bperson@example.com
To: test@example.com
Subject: another test
@@ -168,15 +167,15 @@ The message text can also be provided on standard input.
<BLANKLINE>
<BLANKLINE>
- >>> dump_msgdata(item.msgdata)
+ >>> dump_msgdata(items[0].msgdata)
_parsemsg : False
listname : test@example.com
- original_size: 100
+ original_size: 211
version : 3
- # Clean up.
- >>> sys.stdin = sys.__stdin__
- >>> args.filename = filename
+.. Clean up.
+ >>> sys.stdin = sys.__stdin__
+ >>> args.filename = filename
Metadata
@@ -199,7 +198,7 @@ injected.
bar : two
foo : one
listname : test@example.com
- original_size: 90
+ original_size: 203
version : 3
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/