Commit d964be9f authored by Barry Warsaw's avatar Barry Warsaw

Clean up the commands subdirectory.

parent 8cc7e77b
......@@ -17,11 +17,7 @@
"""Generate Mailman alias files for your MTA."""
__all__ = [
'Aliases',
]
from mailman import public
from mailman.config import config
from mailman.core.i18n import _
from mailman.interfaces.command import ICLISubCommand
......@@ -29,7 +25,7 @@ from mailman.utilities.modules import call_name
from zope.interface import implementer
@public
@implementer(ICLISubCommand)
class Aliases:
"""Regenerate the aliases appropriate for your MTA."""
......
......@@ -17,22 +17,18 @@
"""Print the mailman configuration."""
__all__ = [
'Conf'
]
import sys
from contextlib import closing
from lazr.config._config import Section
from mailman import public
from mailman.config import config
from mailman.core.i18n import _
from mailman.interfaces.command import ICLISubCommand
from zope.interface import implementer
@public
@implementer(ICLISubCommand)
class Conf:
"""Print the mailman configuration."""
......@@ -114,8 +110,7 @@ class Conf:
# We have to ensure that the current section actually exists
# and that it contains the given key.
if (self._section_exists(current_section) and
hasattr(getattr(config, current_section), key)):
# Then...
hasattr(getattr(config, current_section), key)):
self._print_full_syntax(
current_section, key,
self._get_value(current_section, key),
......
......@@ -17,20 +17,13 @@
"""Start/stop/reopen/restart commands."""
__all__ = [
'Reopen',
'Restart',
'Start',
'Stop',
]
import os
import sys
import errno
import signal
import logging
from mailman import public
from mailman.bin.master import WatcherState, master_state
from mailman.config import config
from mailman.core.i18n import _
......@@ -41,7 +34,7 @@ from zope.interface import implementer
qlog = logging.getLogger('mailman.runner')
@public
@implementer(ICLISubCommand)
class Start:
"""Start the Mailman master and runner processes."""
......@@ -100,7 +93,7 @@ class Start:
self.parser.error(
_('A previous run of GNU Mailman did not exit '
'cleanly. Try using --force.'))
def log(message):
def log(message): # flake8: noqa
if not args.quiet:
print(message)
# Try to find the path to a valid, existing configuration file, and
......@@ -149,7 +142,6 @@ Use -C/--config to specify a valid configuration file."""), file=sys.stderr)
raise RuntimeError('os.execl() failed')
def kill_watcher(sig):
try:
with open(config.PID_FILE) as fp:
......@@ -171,7 +163,6 @@ def kill_watcher(sig):
os.unlink(config.PID_FILE)
@implementer(ICLISubCommand)
class SignalCommand:
"""Common base class for simple, signal sending commands."""
......@@ -196,6 +187,7 @@ class SignalCommand:
kill_watcher(self.signal)
@public
class Stop(SignalCommand):
"""Stop the Mailman master and runner processes."""
......@@ -204,6 +196,7 @@ class Stop(SignalCommand):
signal = signal.SIGTERM
@public
class Reopen(SignalCommand):
"""Signal the Mailman processes to re-open their log files."""
......@@ -212,6 +205,7 @@ class Reopen(SignalCommand):
signal = signal.SIGHUP
@public
@implementer(ICLISubCommand)
class Restart(SignalCommand):
"""Stop and restart the Mailman runner subprocesses."""
......
......@@ -17,13 +17,9 @@
"""The `send_digests` subcommand."""
__all__ = [
'Digests',
]
import sys
from mailman import public
from mailman.app.digests import (
bump_digest_number_and_volume, maybe_send_digest_now)
from mailman.core.i18n import _
......@@ -33,7 +29,7 @@ from zope.component import getUtility
from zope.interface import implementer
@public
@implementer(ICLISubCommand)
class Digests:
"""Operate on digests."""
......@@ -78,7 +74,7 @@ class Digests:
else:
lists.append(mlist)
else:
lists = list(list_manager.mailing_lists)
lists = list(list_manager.mailing_lists)
if args.bump:
for mlist in lists:
bump_digest_number_and_volume(mlist)
......
......@@ -17,16 +17,12 @@
"""The 'help' subcommand."""
__all__ = [
'Help',
]
from mailman import public
from mailman.interfaces.command import ICLISubCommand
from zope.interface import implementer
@public
@implementer(ICLISubCommand)
class Help:
# Lowercase, to match argparse's default --help text.
......
......@@ -17,15 +17,11 @@
"""Importing list data into Mailman 3."""
__all__ = [
'Import21',
]
import sys
import pickle
from contextlib import ExitStack, contextmanager
from mailman import public
from mailman.core.i18n import _
from mailman.database.transaction import transactional
from mailman.interfaces.command import ICLISubCommand
......@@ -35,7 +31,6 @@ from zope.component import getUtility
from zope.interface import implementer
# A fake Bouncer class from Mailman 2.1, we don't use it but there are
# instances in the .pck files.
class Bouncer:
......@@ -53,8 +48,7 @@ def hacked_sys_modules():
del sys.modules['Mailman.Bouncer']
@public
@implementer(ICLISubCommand)
class Import21:
"""Import Mailman 2.1 list data."""
......
......@@ -17,14 +17,10 @@
"""Information about this Mailman instance."""
__all__ = [
'Info'
]
import sys
from lazr.config import as_boolean
from mailman import public
from mailman.config import config
from mailman.core.api import API30, API31
from mailman.core.i18n import _
......@@ -33,7 +29,7 @@ from mailman.version import MAILMAN_VERSION_FULL
from zope.interface import implementer
@public
@implementer(ICLISubCommand)
class Info:
"""Information about this Mailman instance."""
......@@ -70,7 +66,7 @@ class Info:
file=output)
api = (API30 if config.webservice.api_version == '3.0' else API31)
print('REST root url:', api.path_to('/'), file=output)
print('REST credentials: {0}:{1}'.format(
print('REST credentials: {}:{}'.format(
config.webservice.admin_user, config.webservice.admin_pass),
file=output)
if args.verbose:
......
......@@ -17,13 +17,9 @@
"""The `mailman inject` subcommand."""
__all__ = [
'Inject',
]
import sys
from mailman import public
from mailman.app.inject import inject_text
from mailman.config import config
from mailman.core.i18n import _
......@@ -33,7 +29,7 @@ from zope.component import getUtility
from zope.interface import implementer
@public
@implementer(ICLISubCommand)
class Inject:
"""Inject a message from a file into a mailing list's queue."""
......
......@@ -17,13 +17,7 @@
"""The 'lists' subcommand."""
__all__ = [
'Create',
'Lists',
'Remove',
]
from mailman import public
from mailman.app.lifecycle import create_list, remove_list
from mailman.core.constants import system_preferences
from mailman.core.i18n import _
......@@ -44,7 +38,7 @@ from zope.interface import implementer
COMMASPACE = ', '
@public
@implementer(ICLISubCommand)
class Lists:
"""List all mailing lists"""
......@@ -95,7 +89,7 @@ class Lists:
if not args.quiet:
print(_('No matching mailing lists found'))
return
count = len(mailing_lists)
count = len(mailing_lists) # flake8: noqa
if not args.quiet:
print(_('$count matching mailing lists found:'))
# Calculate the longest identifier.
......@@ -103,7 +97,7 @@ class Lists:
output = []
for mlist in mailing_lists:
if args.names:
identifier = '{0} [{1}]'.format(
identifier = '{} [{}]'.format(
mlist.fqdn_listname, mlist.display_name)
else:
identifier = mlist.fqdn_listname
......@@ -119,7 +113,7 @@ class Lists:
identifier, description, longest, 70 - longest))
@public
@implementer(ICLISubCommand)
class Create:
"""Create a mailing list."""
......@@ -204,7 +198,8 @@ class Create:
invalid_owners = [owner for owner in args.owners
if not validator.is_valid(owner)]
if invalid_owners:
invalid = COMMASPACE.join(sorted(invalid_owners))
invalid = COMMASPACE.join( # flake8: noqa
sorted(invalid_owners))
self.parser.error(_('Illegal owner addresses: $invalid'))
return
try:
......@@ -228,11 +223,11 @@ class Create:
print(_('Created mailing list: $mlist.fqdn_listname'))
if args.notify:
d = dict(
listname = mlist.fqdn_listname,
admin_url = mlist.script_url('admin'),
listinfo_url = mlist.script_url('listinfo'),
requestaddr = mlist.request_address,
siteowner = mlist.no_reply_address,
listname = mlist.fqdn_listname,
admin_url = mlist.script_url('admin'),
listinfo_url = mlist.script_url('listinfo'),
requestaddr = mlist.request_address,
siteowner = mlist.no_reply_address,
)
text = make('newlist.txt', mailing_list=mlist, **d)
# Set the I18N language to the list's preferred language so the
......@@ -246,7 +241,7 @@ class Create:
msg.send(mlist)
@public
@implementer(ICLISubCommand)
class Remove:
"""Remove a mailing list."""
......
......@@ -17,15 +17,11 @@
"""The 'members' subcommand."""
__all__ = [
'Members',
]
import sys
from contextlib import ExitStack
from email.utils import formataddr, parseaddr
from mailman import public
from mailman.app.membership import add_member
from mailman.core.i18n import _
from mailman.database.transaction import transactional
......@@ -39,7 +35,7 @@ from zope.component import getUtility
from zope.interface import implementer
@public
@implementer(ICLISubCommand)
class Members:
"""Manage list memberships. With no arguments, list all members."""
......@@ -132,9 +128,11 @@ class Members:
:type args: `argparse.Namespace`
"""
if args.digest == 'any':
digest_types = [DeliveryMode.plaintext_digests,
DeliveryMode.mime_digests,
DeliveryMode.summary_digests]
digest_types = [
DeliveryMode.plaintext_digests,
DeliveryMode.mime_digests,
DeliveryMode.summary_digests,
]
elif args.digest is not None:
digest_types = [DeliveryMode[args.digest + '_digests']]
else:
......@@ -153,13 +151,14 @@ class Members:
elif args.nomail == 'unknown':
status_types = [DeliveryStatus.unknown]
elif args.nomail == 'any':
status_types = [DeliveryStatus.by_user,
DeliveryStatus.by_bounces,
DeliveryStatus.by_moderator,
DeliveryStatus.unknown]
status_types = [
DeliveryStatus.by_user,
DeliveryStatus.by_bounces,
DeliveryStatus.by_moderator,
DeliveryStatus.unknown,
]
else:
status = args.nomail
self.parser.error(_('Unknown delivery status: $status'))
self.parser.error(_('Unknown delivery status: $args.nomail'))
if args.role is None:
# By default, filter on members.
......@@ -172,8 +171,7 @@ class Members:
try:
roster = mlist.get_roster(MemberRole[args.role])
except KeyError:
role = args.role
self.parser.error(_('Unknown member role: $role'))
self.parser.error(_('Unknown member role: $args.role'))
with ExitStack() as resources:
if args.output_filename == '-' or args.output_filename is None:
......
......@@ -17,13 +17,9 @@
"""Getting information out of a qfile."""
__all__ = [
'QFile',
]
import pickle
from mailman import public
from mailman.core.i18n import _
from mailman.interfaces.command import ICLISubCommand
from mailman.utilities.interact import interact
......@@ -35,7 +31,7 @@ from zope.interface import implementer
m = []
@public
@implementer(ICLISubCommand)
class QFile:
"""Get information out of a queue file."""
......@@ -84,7 +80,7 @@ class QFile:
else:
printer.pprint(obj)
print(_('[----- end pickle -----]'))
count = len(m)
count = len(m) # flake8: noqa
banner = _("The variable 'm' contains $count objects")
if args.interactive:
interact(banner=banner)
......@@ -17,20 +17,16 @@
"""The `mailman status` subcommand."""
__all__ = [
'Status',
]
import socket
from mailman import public
from mailman.bin.master import WatcherState, master_state
from mailman.core.i18n import _
from mailman.interfaces.command import ICLISubCommand
from zope.interface import implementer
@public
@implementer(ICLISubCommand)
class Status:
"""Status of the Mailman system."""
......@@ -51,10 +47,10 @@ class Status:
message = _('GNU Mailman is running (master pid: $pid)')
elif status is WatcherState.stale_lock:
hostname, pid, tempfile = lock.details
message =_('GNU Mailman is stopped (stale pid: $pid)')
message = _('GNU Mailman is stopped (stale pid: $pid)')
else:
hostname, pid, tempfile = lock.details
fqdn_name = socket.getfqdn()
fqdn_name = socket.getfqdn() # flake8: noqa
assert status is WatcherState.host_mismatch, (
'Invalid enum value: %s' % status)
message = _('GNU Mailman is in an unexpected state '
......
......@@ -17,20 +17,16 @@
"""The 'unshunt' command."""
__all__ = [
'Unshunt',
]
import sys
from mailman import public
from mailman.config import config
from mailman.core.i18n import _
from mailman.interfaces.command import ICLISubCommand
from zope.interface import implementer
@public
@implementer(ICLISubCommand)
class Unshunt:
"""Unshunt messages."""
......
......@@ -17,17 +17,13 @@
"""The Mailman version."""
__all__ = [
'Version',
]
from mailman import public
from mailman.interfaces.command import ICLISubCommand
from mailman.version import MAILMAN_VERSION_FULL
from zope.interface import implementer
@public
@implementer(ICLISubCommand)
class Version:
"""Mailman's version."""
......
......@@ -17,16 +17,11 @@
"""The `mailman shell` subcommand."""
__all__ = [
'Shell',
'Withlist',
]
import re
import sys
from lazr.config import as_boolean
from mailman import public
from mailman.config import config
from mailman.core.i18n import _
from mailman.interfaces.command import ICLISubCommand
......@@ -43,7 +38,7 @@ m = None
r = None
@public
@implementer(ICLISubCommand)
class Withlist:
"""Operate on a mailing list.
......@@ -164,7 +159,7 @@ class Withlist:
def _start_python(self, overrides, banner):
# Set the tab completion.
try:
import readline, rlcompleter
import readline, rlcompleter # flake8: noqa
readline.parse_and_bind('tab: complete')
except ImportError:
pass
......@@ -235,7 +230,7 @@ and run this from the command line:
% mailman withlist -r change mylist@example.com 'My List'"""))
@public
class Shell(Withlist):
"""An alias for `withlist`."""
......
......@@ -17,11 +17,7 @@
"""The 'confirm' email command."""
__all__ = [
'Confirm',
]
from mailman import public
from mailman.core.i18n import _
from mailman.interfaces.command import ContinueProcessing, IEmailCommand
from mailman.interfaces.registrar import IRegistrar
......@@ -29,7 +25,7 @@ from mailman.interfaces.subscriptions import TokenOwner
from zope.interface import implementer
@public
@implementer(IEmailCommand)
class Confirm:
"""The email 'confirm' command."""
......
......@@ -17,11 +17,7 @@
"""The email command 'echo'."""
__all__ = [
'Echo',
]
from mailman import public
from mailman.core.i18n import _
from mailman.interfaces.command import ContinueProcessing, IEmailCommand
from zope.interface import implementer
......@@ -30,7 +26,7 @@ from zope.interface import implementer
SPACE = ' '
@public
@implementer(IEmailCommand)
class Echo:
"""The email 'echo' command."""
......
......@@ -17,18 +17,13 @@
"""The email commands 'end' and 'stop'."""
__all__ = [
'End',
'Stop',
]
from mailman import public
from mailman.core.i18n import _
from mailman.interfaces.command import ContinueProcessing, IEmailCommand
from zope.interface import implementer
@public
@implementer(IEmailCommand)
class End:
"""The email 'end' command."""
......@@ -44,6 +39,7 @@ class End:
return ContinueProcessing.no
@public
class Stop(End):
"""The email 'stop' command (an alias for 'end')."""
......
......@@ -17,11 +17,7 @@
"""The email command 'help'."""
__all__ = [
'Help',
]
from mailman import public
from mailman.config import config
from mailman.core.i18n import _
from mailman.interfaces.command import ContinueProcessing, IEmailCommand
......@@ -32,7 +28,7 @@ from zope.interface import implementer
SPACE = ' '
@public
@implementer(IEmailCommand)
class Help:
"""The email 'help' command."""
......@@ -63,14 +59,14 @@ class Help:
print(_('$self.name: no such command: $command_name'),
file=results)
return ContinueProcessing.no
print('{0} {1}'.format(command.name, command.argument_description),
print('{} {}'.format(command.name, command.argument_description),
file=results)
print(command.short_description, file=results)
if command.short_description != command.description:
print(wrap(command.description), file=results)
return ContinueProcessing.yes
else:
printable_arguments = SPACE.join(arguments)
printable_arguments = SPACE.join(arguments) # flake8: noqa
print(_('$self.name: too many arguments: $printable_arguments'),
file=results)
return ContinueProcessing.no
......@@ -17,15 +17,8 @@
"""The email commands 'join' and 'subscribe'."""
__all__ = [
'Join',
'Subscribe',
'Leave',
'Unsubscribe',
]
from email.utils import formataddr, parseaddr
from mailman import public
from mailman.core.i18n import _
from mailman.interfaces.command import ContinueProcessing, IEmailCommand
from mailman.interfaces.member import DeliveryMode, MemberRole
......@@ -36,7 +29,6 @@ from zope.component import getUtility
from zope.interface import implementer
def match_subscriber(email, display_name):
# Return something matching the email which should be used as the
# subscriber by the IRegistrar interface.
......@@ -58,7 +50,7 @@ def match_subscriber(email, display_name):
return list(user.addresses)[0]
@public
@implementer(IEmailCommand)
class Join:
"""The email 'join' command."""
......@@ -100,7 +92,7 @@ used.
return ContinueProcessing.yes
joins.add(email)
results.joins = joins
person = formataddr((display_name, email))
person = formataddr((display_name, email)) # flake8: noqa
# Is this person already a member of the list? Search for all
# matching memberships.
members = getUtility(ISubscriptionService).find_members(
......@@ -140,7 +132,7 @@ used.