diff options
| author | Barry Warsaw | 2017-07-22 03:02:06 +0000 |
|---|---|---|
| committer | Barry Warsaw | 2017-07-22 03:02:06 +0000 |
| commit | 02826321d0430d7ffc1f674eeff4221941689ef7 (patch) | |
| tree | 1a8e56dff0eab71e58e5fc9ecc5f3c614d7edca7 /src/mailman/commands/cli_digests.py | |
| parent | f54c045519300f6f70947d1114f46c2b8ae0d368 (diff) | |
| parent | f00b94f18e1d82d1488cbcee6053f03423bc2f49 (diff) | |
| download | mailman-02826321d0430d7ffc1f674eeff4221941689ef7.tar.gz mailman-02826321d0430d7ffc1f674eeff4221941689ef7.tar.zst mailman-02826321d0430d7ffc1f674eeff4221941689ef7.zip | |
Diffstat (limited to 'src/mailman/commands/cli_digests.py')
| -rw-r--r-- | src/mailman/commands/cli_digests.py | 141 |
1 files changed, 72 insertions, 69 deletions
diff --git a/src/mailman/commands/cli_digests.py b/src/mailman/commands/cli_digests.py index 8f556beb4..57431000a 100644 --- a/src/mailman/commands/cli_digests.py +++ b/src/mailman/commands/cli_digests.py @@ -18,88 +18,91 @@ """The `send_digests` subcommand.""" import sys +import click from mailman.app.digests import ( bump_digest_number_and_volume, maybe_send_digest_now) from mailman.core.i18n import _ from mailman.interfaces.command import ICLISubCommand from mailman.interfaces.listmanager import IListManager +from mailman.utilities.options import I18nCommand from public import public from zope.component import getUtility from zope.interface import implementer -@public -@implementer(ICLISubCommand) -class Digests: - """Operate on digests.""" - - name = 'digests' - - def add(self, parser, command_parser): - """See `ICLISubCommand`.""" - - command_parser.add_argument( - '-l', '--list', - default=[], dest='lists', metavar='list', action='append', - help=_("""Operate on this mailing list. Multiple --list - options can be given. The argument can either be a List-ID - or a fully qualified list name. Without this option, - operate on the digests for all mailing lists.""")) - command_parser.add_argument( - '-s', '--send', - default=False, action='store_true', - help=_("""Send any collected digests right now, even if the size - threshold has not yet been met.""")) - command_parser.add_argument( - '-b', '--bump', - default=False, action='store_true', - help=_("""Increment the digest volume number and reset the digest - number to one. If given with --send, the volume number is - incremented before any current digests are sent.""")) - command_parser.add_argument( - '-n', '--dry-run', - default=False, action='store_true', - help=_("""Don't actually do anything, but in conjunction with - --verbose, show what would happen.""")) - command_parser.add_argument( - '-v', '--verbose', - default=False, action='store_true', - help=_("""Print some additional status.""")) - - def process(self, args): - """See `ICLISubCommand`.""" - list_manager = getUtility(IListManager) - if args.lists: - lists = [] - for spec in args.lists: - # We'll accept list-ids or fqdn list names. - if '@' in spec: - mlist = list_manager.get(spec) - else: - mlist = list_manager.get_by_list_id(spec) - if mlist is None: - print(_('No such list found: $spec'), file=sys.stderr) - else: - lists.append(mlist) - else: - lists = list(list_manager.mailing_lists) - if args.bump: - for mlist in lists: - if args.verbose: - print(_('\ +@click.command( + cls=I18nCommand, + help=_('Operate on digests.')) +@click.option( + '--list', '-l', 'list_ids', metavar='list', + multiple=True, help=_("""\ + Operate on this mailing list. Multiple --list options can be given. The + argument can either be a List-ID or a fully qualified list name. Without + this option, operate on the digests for all mailing lists.""")) +@click.option( + '--send', '-s', + is_flag=True, default=False, + help=_("""\ + Send any collected digests right now, even if the size threshold has not + yet been met.""")) +@click.option( + '--bump', '-b', + is_flag=True, default=False, + help=_("""\ + Increment the digest volume number and reset the digest number to one. If + given with --send, the volume number is incremented before any current + digests are sent.""")) +@click.option( + '--dry-run', '-n', + is_flag=True, default=False, + help=_("""\ + Don't actually do anything, but in conjunction with --verbose, show what + would happen.""")) +@click.option( + '--verbose', '-v', + is_flag=True, default=False, + help=_('Print some additional status.')) +@click.pass_context +def digests(ctx, list_ids, send, bump, dry_run, verbose): + list_manager = getUtility(IListManager) + if list_ids: + lists = [] + for spec in list_ids: + # We'll accept list-ids or fqdn list names. + if '@' in spec: + mlist = list_manager.get(spec) + else: + mlist = list_manager.get_by_list_id(spec) + if mlist is None: + print(_('No such list found: $spec'), file=sys.stderr) + else: + lists.append(mlist) + else: + lists = list(list_manager.mailing_lists) + if bump: + for mlist in lists: + if verbose: + print(_('\ $mlist.list_id is at volume $mlist.volume, number \ ${mlist.next_digest_number}')) - if not args.dry_run: - bump_digest_number_and_volume(mlist) - if args.verbose: - print(_('\ + if not dry_run: + bump_digest_number_and_volume(mlist) + if verbose: + print(_('\ $mlist.list_id bumped to volume $mlist.volume, number \ ${mlist.next_digest_number}')) - if args.send: - for mlist in lists: - if args.verbose: - print(_('\ + if send: + for mlist in lists: + if verbose: + print(_('\ $mlist.list_id sent volume $mlist.volume, number ${mlist.next_digest_number}')) - if not args.dry_run: - maybe_send_digest_now(mlist, force=True) + if not dry_run: + maybe_send_digest_now(mlist, force=True) + + +@public +@implementer(ICLISubCommand) +class Digests: + name = 'digests' + command = digests |
