diff options
Diffstat (limited to 'src/mailman/commands')
| -rw-r--r-- | src/mailman/commands/cli_inject.py | 13 | ||||
| -rw-r--r-- | src/mailman/commands/cli_members.py | 21 | ||||
| -rw-r--r-- | src/mailman/commands/docs/members.txt | 37 |
3 files changed, 61 insertions, 10 deletions
diff --git a/src/mailman/commands/cli_inject.py b/src/mailman/commands/cli_inject.py index 025dcb036..8b7570e0a 100644 --- a/src/mailman/commands/cli_inject.py +++ b/src/mailman/commands/cli_inject.py @@ -60,13 +60,12 @@ class Inject: help=_('Show a list of all available queue names and exit.')) command_parser.add_argument( '-f', '--filename', - type='string', help=_(""" + type=unicode, help=_(""" Name of file containing the message to inject. If not given, or - '-' (without the quotes) standard input is used. - """)) + '-' (without the quotes) standard input is used.""")) # Required positional argument. command_parser.add_argument( - 'listname', metavar='LISTNAME', nargs='?', + 'listname', metavar='LISTNAME', nargs=1, help=_("""\ The 'fully qualified list name', i.e. the posting address of the mailing list to inject the message into.""")) @@ -97,7 +96,11 @@ class Inject: self.parser.error(_('No such queue: $queue')) return if args.filename in (None, '-'): - message_text = sys.stdin.read() + try: + message_text = sys.stdin.read() + except KeyboardInterrupt: + print 'Interrupted' + sys.exit(1) else: with open(args.filename) as fp: message_text = fp.read() diff --git a/src/mailman/commands/cli_members.py b/src/mailman/commands/cli_members.py index b26216785..213bb7a2c 100644 --- a/src/mailman/commands/cli_members.py +++ b/src/mailman/commands/cli_members.py @@ -37,7 +37,7 @@ from mailman.config import config from mailman.core.i18n import _ from mailman.interfaces.command import ICLISubCommand from mailman.interfaces.listmanager import IListManager -from mailman.interfaces.member import DeliveryMode +from mailman.interfaces.member import AlreadySubscribedError, DeliveryMode @@ -53,8 +53,10 @@ class Members: command_parser.add_argument( '-a', '--add', dest='filename', - help=_('Add all member addresses in FILENAME. FILENAME can be ' - "'-' to indicate standard input.")) + help=_("""\ + Add all member addresses in FILENAME. FILENAME can be '-' to + indicate standard input. Blank lines and lines That start with a + '#' are ignored.""")) # Required positional argument. command_parser.add_argument( 'listname', metavar='LISTNAME', nargs=1, @@ -78,14 +80,23 @@ class Members: fp = codecs.open(args.filename, 'r', 'utf-8') try: for line in fp: + # Ignore blank lines and lines that start with a '#'. + if line.startswith('#') or len(line.strip()) == 0: + continue real_name, email = parseaddr(line) # If not given in the input data, parseaddr() will return the # empty string, as opposed to the empty unicode. We need a # unicode real name here. if real_name == '': real_name = u'' - add_member(mlist, email, real_name, None, - DeliveryMode.regular, mlist.preferred_language.code) + try: + add_member(mlist, email, real_name, None, + DeliveryMode.regular, + mlist.preferred_language.code) + except AlreadySubscribedError: + # It's okay if the address is already subscribed, just + # print a warning and continue. + print 'Already subscribed (skipping):', email, real_name finally: if fp is not sys.stdin: fp.close() diff --git a/src/mailman/commands/docs/members.txt b/src/mailman/commands/docs/members.txt index 9872b9ff0..aea76dad8 100644 --- a/src/mailman/commands/docs/members.txt +++ b/src/mailman/commands/docs/members.txt @@ -57,3 +57,40 @@ taken from standard input. >>> sorted(address.address for address in mlist.members.addresses) [u'aperson@example.com', u'bperson@example.com', u'cperson@example.com', u'dperson@example.com', u'eperson@example.com', u'fperson@example.com'] + +Blank lines and lines that begin with '#' are ignored. + + >>> with open(path, 'w') as fp: + ... for address in ('gperson@example.com', + ... '# hperson@example.com', + ... ' ', + ... '', + ... 'iperson@example.com', + ... ): + ... print >> fp, address + + >>> args.filename = path + >>> command.process(args) + >>> sorted(address.address for address in mlist.members.addresses) + [u'aperson@example.com', u'bperson@example.com', u'cperson@example.com', + u'dperson@example.com', u'eperson@example.com', u'fperson@example.com', + u'gperson@example.com', u'iperson@example.com'] + +Addresses which are already subscribed are ignored, although a warning is +printed. + + >>> with open(path, 'w') as fp: + ... for address in ('gperson@example.com', + ... 'aperson@example.com', + ... 'jperson@example.com', + ... ): + ... print >> fp, address + + >>> command.process(args) + Already subscribed (skipping): gperson@example.com + Already subscribed (skipping): aperson@example.com + + >>> sorted(address.address for address in mlist.members.addresses) + [u'aperson@example.com', u'bperson@example.com', u'cperson@example.com', + u'dperson@example.com', u'eperson@example.com', u'fperson@example.com', + u'gperson@example.com', u'iperson@example.com', u'jperson@example.com'] |
