summaryrefslogtreecommitdiff
path: root/src/mailman/commands
diff options
context:
space:
mode:
authorBarry Warsaw2017-08-29 14:07:54 +0000
committerBarry Warsaw2017-08-29 14:07:54 +0000
commitae0042a90220119414f61aeb20c6b58bfacb8af2 (patch)
tree6fd2038427fbb36d8173fe338d277351cd19727b /src/mailman/commands
parentf847e15407bfbf824236547bdf728a1ae00bd405 (diff)
downloadmailman-ae0042a90220119414f61aeb20c6b58bfacb8af2.tar.gz
mailman-ae0042a90220119414f61aeb20c6b58bfacb8af2.tar.zst
mailman-ae0042a90220119414f61aeb20c6b58bfacb8af2.zip
Diffstat (limited to 'src/mailman/commands')
-rw-r--r--src/mailman/commands/cli_withlist.py27
-rw-r--r--src/mailman/commands/docs/conf.rst1
-rw-r--r--src/mailman/commands/docs/info.rst1
-rw-r--r--src/mailman/commands/tests/test_cli_shell.py14
4 files changed, 26 insertions, 17 deletions
diff --git a/src/mailman/commands/cli_withlist.py b/src/mailman/commands/cli_withlist.py
index d2b706e34..202b61584 100644
--- a/src/mailman/commands/cli_withlist.py
+++ b/src/mailman/commands/cli_withlist.py
@@ -178,9 +178,12 @@ def listaddr(mlist):
def requestaddr(mlist):
print(mlist.request_address)
-All run methods take at least one argument, the mailing list object to operate
+Run methods take at least one argument, the mailing list object to operate
on. Any additional arguments given on the command line are passed as
-positional arguments to the callable."""))
+positional arguments to the callable.
+
+If -l is not given then you can run a function that takes no arguments.
+"""))
print()
print(_("""\
You can print the list's posting address by running the following from the
@@ -232,11 +235,16 @@ Mailman will do this for you (assuming no errors occured)."""))
@click.option(
'--run', '-r',
help=_("""\
- Run a script on a mailing list. The argument is the module path to a
- callable. This callable will be imported and then called with the mailing
- list as the first argument. If additional arguments are given at the end
- of the command line, they are passed as subsequent positional arguments to
- the callable. For additional help, see --details.
+
+ Run a script. The argument is the module path to a callable. This
+ callable will be imported and then, if --listspec/-l is also given, is
+ called with the mailing list as the first argument. If additional
+ arguments are given at the end of the command line, they are passed as
+ subsequent positional arguments to the callable. For additional help, see
+ --details.
+
+ If no --listspec/-l argument is given, the script function being called is
+ called with no arguments.
"""))
@click.option(
'--details',
@@ -270,9 +278,8 @@ def shell(ctx, interactive, run, listspec, run_args):
# without the dot is allowed.
dotted_name = (run if '.' in run else '{0}.{0}'.format(run))
if listspec is None:
- ctx.fail(_('--run requires a mailing list'))
- # Parse the run arguments so we can pass them into the run method.
- if listspec.startswith('^'):
+ r = call_name(dotted_name, *run_args)
+ elif listspec.startswith('^'):
r = {}
cre = re.compile(listspec, re.IGNORECASE)
for mlist in list_manager.mailing_lists:
diff --git a/src/mailman/commands/docs/conf.rst b/src/mailman/commands/docs/conf.rst
index 1a6a4679d..5e548ec0b 100644
--- a/src/mailman/commands/docs/conf.rst
+++ b/src/mailman/commands/docs/conf.rst
@@ -45,6 +45,7 @@ key, along with the names of the corresponding sections.
[logging.http] path: mailman.log
[logging.locks] path: mailman.log
[logging.mischief] path: mailman.log
+ [logging.plugins] path: plugins.log
[logging.root] path: mailman.log
[logging.runner] path: mailman.log
[logging.smtp] path: smtp.log
diff --git a/src/mailman/commands/docs/info.rst b/src/mailman/commands/docs/info.rst
index 219143cab..40784a98b 100644
--- a/src/mailman/commands/docs/info.rst
+++ b/src/mailman/commands/docs/info.rst
@@ -59,7 +59,6 @@ definition.
CFG_FILE = .../test.cfg
DATA_DIR = /var/lib/mailman/data
ETC_DIR = /etc
- EXT_DIR = /etc/mailman.d
LIST_DATA_DIR = /var/lib/mailman/lists
LOCK_DIR = /var/lock/mailman
LOCK_FILE = /var/lock/mailman/master.lck
diff --git a/src/mailman/commands/tests/test_cli_shell.py b/src/mailman/commands/tests/test_cli_shell.py
index ffcf43803..74abd64a3 100644
--- a/src/mailman/commands/tests/test_cli_shell.py
+++ b/src/mailman/commands/tests/test_cli_shell.py
@@ -29,6 +29,7 @@ from mailman.interfaces.usermanager import IUserManager
from mailman.testing.helpers import configuration
from mailman.testing.layers import ConfigLayer
from mailman.utilities.modules import hacked_sys_modules
+from types import ModuleType
from unittest.mock import MagicMock, patch
try:
@@ -40,6 +41,7 @@ except ImportError:
class TestShell(unittest.TestCase):
layer = ConfigLayer
+ maxDiff = None
def setUp(self):
self._command = CliRunner()
@@ -156,12 +158,12 @@ class TestShell(unittest.TestCase):
'Error: No such list: ant.example.com\n')
def test_run_without_listspec(self):
- results = self._command.invoke(shell, ('--run', 'something'))
- self.assertEqual(results.exit_code, 2)
- self.assertEqual(
- results.output,
- 'Usage: shell [OPTIONS] [RUN_ARGS]...\n\n'
- 'Error: --run requires a mailing list\n')
+ something = ModuleType('something')
+ something.something = lambda: print('I am a something!')
+ with hacked_sys_modules('something', something):
+ results = self._command.invoke(shell, ('--run', 'something'))
+ self.assertEqual(results.exit_code, 0)
+ self.assertEqual(results.output, 'I am a something!\n')
def test_run_bogus_listspec(self):
results = self._command.invoke(