Barry Warsaw pushed to branch click-cli at mailman / Mailman
Commits: 2005cb13 by Barry Warsaw at 2017-06-23T21:29:45-04:00 Make `mailman version` the same as `mailman --version`. Convert status, version. - - - - - 3 changed files: - src/mailman/bin/mailman.py - src/mailman/commands/cli_status.py - src/mailman/commands/cli_version.py Changes: ===================================== src/mailman/bin/mailman.py ===================================== --- a/src/mailman/bin/mailman.py +++ b/src/mailman/bin/mailman.py @@ -64,7 +64,7 @@ class Subcommands(click.MultiCommand): Configuration file to use. If not given, the environment variable MAILMAN_CONFIG_FILE is consulted and used if set. If neither are given, a default configuration file is loaded.""")) -@click.version_option(MAILMAN_VERSION_FULL) +@click.version_option(MAILMAN_VERSION_FULL, message='%(version)s') @public def main(ctx, config_file): # XXX https://github.com/pallets/click/issues/303 ===================================== src/mailman/commands/cli_status.py ===================================== --- a/src/mailman/commands/cli_status.py +++ b/src/mailman/commands/cli_status.py @@ -17,6 +17,8 @@ """The `mailman status` subcommand.""" +import sys +import click import socket from mailman.bin.master import WatcherState, master_state @@ -26,34 +28,30 @@ from public import public from zope.interface import implementer +@click.command(help=_('Status of the Mailman system')) +def status(): + status, lock = master_state() + if status is WatcherState.none: + message = _('GNU Mailman is not running') + elif status is WatcherState.conflict: + hostname, pid, tempfile = lock.details + 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)') + else: + hostname, pid, tempfile = lock.details + fqdn_name = socket.getfqdn() # noqa: F841 + assert status is WatcherState.host_mismatch, ( + 'Invalid enum value: %s' % status) + message = _('GNU Mailman is in an unexpected state ' + '($hostname != $fqdn_name)') + print(message) + sys.exit(status.value) + + @public @implementer(ICLISubCommand) class Status: - """Status of the Mailman system.""" - name = 'status' - - def add(self, parser, command_parser): - """See `ICLISubCommand`.""" - pass - - def process(self, args): - """See `ICLISubCommand`.""" - status, lock = master_state() - if status is WatcherState.none: - message = _('GNU Mailman is not running') - elif status is WatcherState.conflict: - hostname, pid, tempfile = lock.details - 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)') - else: - hostname, pid, tempfile = lock.details - fqdn_name = socket.getfqdn() # noqa: F841 - assert status is WatcherState.host_mismatch, ( - 'Invalid enum value: %s' % status) - message = _('GNU Mailman is in an unexpected state ' - '($hostname != $fqdn_name)') - print(message) - return status.value + command = status ===================================== src/mailman/commands/cli_version.py ===================================== --- a/src/mailman/commands/cli_version.py +++ b/src/mailman/commands/cli_version.py @@ -17,24 +17,22 @@ """The Mailman version.""" +import click + +from mailman.core.i18n import _ from mailman.interfaces.command import ICLISubCommand from mailman.version import MAILMAN_VERSION_FULL from public import public from zope.interface import implementer +@click.command(help=_("Mailman's version")) +def version(): + print(MAILMAN_VERSION_FULL) + + @public @implementer(ICLISubCommand) class Version: - """Mailman's version.""" - name = 'version' - - def add(self, parser, command_parser): - """See `ICLISubCommand`.""" - # No extra options. - pass - - def process(self, args): - """See `ICLISubCommand`.""" - print(MAILMAN_VERSION_FULL) + command = version View it on GitLab: https://gitlab.com/mailman/mailman/commit/2005cb13f95fd83910a864610c9aacbed97e0b21 --- View it on GitLab: https://gitlab.com/mailman/mailman/commit/2005cb13f95fd83910a864610c9aacbed97e0b21 You're receiving this email because of your account on gitlab.com.
_______________________________________________ Mailman-checkins mailing list Mailman-checkins@python.org Unsubscribe: https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org