diff options
| author | bwarsaw | 2000-12-07 19:24:51 +0000 |
|---|---|---|
| committer | bwarsaw | 2000-12-07 19:24:51 +0000 |
| commit | f80f72d57ce4e6ef145502ef71bcc8f7bed592a1 (patch) | |
| tree | 08a602db2bfaa1f0670c3c48d8ad0982c271bfaa | |
| parent | a405e7481d9d5b60ac0101b067c9fefff2b796f6 (diff) | |
| download | mailman-f80f72d57ce4e6ef145502ef71bcc8f7bed592a1.tar.gz mailman-f80f72d57ce4e6ef145502ef71bcc8f7bed592a1.tar.zst mailman-f80f72d57ce4e6ef145502ef71bcc8f7bed592a1.zip | |
Start of support for i18n; marking of translatable strings.
Use extended print statement and other Python 2.0 features.
| -rwxr-xr-x | bin/sync_members | 90 | ||||
| -rw-r--r-- | bin/withlist | 44 | ||||
| -rw-r--r-- | cron/bumpdigests | 11 |
3 files changed, 69 insertions, 76 deletions
diff --git a/bin/sync_members b/bin/sync_members index 1a6e1988a..f104d96f1 100755 --- a/bin/sync_members +++ b/bin/sync_members @@ -25,7 +25,7 @@ added. For every address in the mailing list that does not appear in the file, the address is removed. Other options control what happens when an address is added or removed. -Usage: %(program)s [options] -f file listname +Usage: %(PROGRAM)s [options] -f file listname Where `options' are: @@ -70,42 +70,34 @@ Where `options' are: """ import sys -import string import paths from Mailman import MailList from Mailman import Errors from Mailman import Utils +from Mailman.i18n import _ -program = sys.argv[0] +PROGRAM = sys.argv[0] -def usage(status, msg=''): - print __doc__ % globals() +def usage(code, msg=''): + print >> sys.stderr, _(__doc__) if msg: - print msg - sys.exit(status) - - - -def startswith(s, prefix): - return s[:len(prefix)] == prefix - -def endswith(s, suffix): - return s[-len(suffix):] == suffix + print >> sys.stderr, msg + sys.exit(code) def yesno(opt): - i = string.find(opt, '=') - yesno = string.lower(opt[i+1:]) + i = opt.find('=') + yesno = opt[i+1:].lower() if yesno in ('y', 'yes'): return 1 elif yesno in ('n', 'no'): return 0 else: - usage(1, 'Bad choice: ' + yesno) + usage(1, _('Bad choice: %(yesno)s')) # no return @@ -117,6 +109,8 @@ def main(): listname = None notifyadmin = None + # TBD: can't use getopt with this command line syntax, which is broken and + # should be changed to be getopt compatible. i = 1 while i < len(sys.argv): opt = sys.argv[i] @@ -124,46 +118,46 @@ def main(): usage(0) elif opt in ('-n', '--no-change'): dryrun = 1 - i = i + 1 - print 'Dry run mode' + i += 1 + print _('Dry run mode') elif opt in ('-d', '--digest'): digest = 1 - i = i + 1 - elif startswith(opt, '-d=') or startswith(opt, '--digest='): + i += 1 + elif opt.startswith('-d=') or opt.startswith('--digest='): digest = yesno(opt) - i = i + 1 + i += 1 elif opt in ('-w', '--welcome-msg'): welcome = 1 - i = i + 1 - elif startswith(opt, '-w=') or startswith(opt, '--welcome-msg='): + i += 1 + elif opt.startswith('-w=') or opt.startswith('--welcome-msg='): welcome = yesno(opt) - i = i + 1 + i += 1 elif opt in ('-f', '--file'): if filename is not None: - usage(1, 'Only one -f switch allowed') + usage(1, _('Only one -f switch allowed')) try: filename = sys.argv[i+1] except IndexError: - usage(1, 'No argument to -f given') - i = i + 2 + usage(1, _('No argument to -f given')) + i += 2 elif opt in ('-a', '--notifyadmin'): notifyadmin = 1 - i = i + 1 - elif startswith(opt, '-a=') or startswith(opt, '--notifyadmin='): + i += 1 + elif opt.startswith('-a=') or opt.startswith('--notifyadmin='): notifyadmin = yesno(opt) - i = i + 1 + i += 1 elif opt[0] == '-': - usage(1, 'Illegal option: ' + opt) + usage(1, _('Illegal option: %(opt)s')) else: try: - listname = string.lower(sys.argv[i]) - i = i + 1 + listname = sys.argv[i].lower() + i += 1 except IndexError: - usage(1, 'No listname given') + usage(1, _('No listname given')) break if listname is None or filename is None: - usage(1, 'Must have a listname and a filename') + usage(1, _('Must have a listname and a filename')) # read the list of addresses to sync to from the file if filename == '-': @@ -172,7 +166,7 @@ def main(): try: fp = open(filename) except IOError, (code, msg): - usage(1, 'Cannot read address file: %s: %s' % (filename, msg)) + usage(1, _('Cannot read address file: %(filename)s: %(msg)s')) try: filemembers = fp.readlines() finally: @@ -181,10 +175,10 @@ def main(): # strip out lines we don't care about, they are comments (# in first # non-whitespace) or are blank for i in range(len(filemembers)-1, -1, -1): - addr = string.strip(filemembers[i]) + addr = filemembers[i].strip() if addr == '' or addr[:1] == '#': del filemembers[i] - print 'Ignore : %30s' % addr + print _('Ignore : %30(addr)s') # first filter out any invalid addresses filemembers = Utils.ParseAddrs(filemembers) @@ -193,17 +187,17 @@ def main(): try: Utils.ValidateEmail(addr) except Errors.EmailAddressError: - print 'Invalid : %30s' % addr + print _('Invalid : %30(addr)s') invalid = 1 if invalid: - print 'You must fix the preceding invalid addresses first.' + print _('You must fix the preceding invalid addresses first.') sys.exit(1) # get the locked list object try: mlist = MailList.MailList(listname) except Errors.MMListError, e: - print 'No such list "%s"\n%s' % (listname, e) + print _('No such list: %(listname)s') sys.exit(1) try: @@ -212,19 +206,19 @@ def main(): needsadding = {} for addr in (mlist.GetDeliveryMembers() + mlist.GetDigestDeliveryMembers()): - addrs[string.lower(addr)] = addr + addrs[addr.lower()] = addr for addr in filemembers: # any address found in the file that is also in the list can be # ignored. if not found in the list, it must be added later - laddr = string.lower(addr) + laddr = addr.lower() if addrs.has_key(laddr): del addrs[laddr] else: needsadding[laddr] = addr if not needsadding and not addrs: - print 'Nothing to do.' + print _('Nothing to do.') sys.exit(0) # addrs contains now all the addresses that need removing @@ -238,7 +232,7 @@ def main(): if not dryrun: mlist.ApprovedAddMember(addr, pw, digest, welcome, notifyadmin) - print 'Added : %30s (%30s)' % (laddr, addr) + print _('Added : %30(laddr)s (%30(addr)s)') except Errors.MMAlreadyAMember: pass @@ -246,7 +240,7 @@ def main(): # should be a member, otherwise our test above is broken if not dryrun: mlist.DeleteMember(addr, admin_notif=notifyadmin) - print 'Removed: %30s (%30s)' % (laddr, addr) + print _('Removed: %30(laddr)s (%30(addr)s)') mlist.Save() finally: diff --git a/bin/withlist b/bin/withlist index 28c131f58..9a16127d0 100644 --- a/bin/withlist +++ b/bin/withlist @@ -114,21 +114,20 @@ and run this from the command line: import sys import getopt -import string import paths -from Mailman.Utils import write -from Mailman.MailList import MailList +from Mailman import MailList +from Mailman.i18n import _ m = None r = None -def usage(msg='', code=1): - write(__doc__ % globals(), file=sys.stderr) +def usage(code, msg=''): + print >> sys.stderr, _(__doc__) if msg: - write(msg, file=sys.stdout) + print >> sys.stderr, msg sys.exit(code) @@ -142,10 +141,10 @@ def atexit(): if not m: return if m.Locked(): - write('Unlocking (but not saving) list:', m.internal_name(), - file=sys.stderr) + print >> sys.stderr, _('Unlocking (but not saving) list:'), \ + m.internal_name() m.Unlock() - write('Finalizing', file=sys.stderr) + print >> sys.stderr, _('Finalizing') del m @@ -156,47 +155,46 @@ def main(): try: opts, args = getopt.getopt(sys.argv[1:], 'hlr:', ['help', 'lock', 'run=']) - except getopt.error, m: - usage(m) + except getopt.error, msg: + usage(1, msg) for opt, arg in opts: if opt in ('-h', '--help'): - usage(code=0) + usage(0) elif opt in ('-l', '--lock'): lock = 1 elif opt in ('-r', '--run'): run = arg if len(args) < 1: - usage('No list name supplied.') + usage(1, _('No list name supplied.')) - listname = string.lower(args.pop(0)) + listname = args.pop(0).lower().strip() lock = 0 run = None # first try to open mailing list - write('Loading list:', listname, file=sys.stderr, nl=0) + print >> sys.stderr, _('Loading list %(listname)s'), if lock: - write('(locked)', file=sys.stderr) + print >> sys.stderr, _('(locked)') else: - write('(unlocked)', file=sys.stderr) + print >> sys.stderr, _('(unlocked)') - m = MailList(listname, lock=lock) + m = MailList.MailList(listname, lock=lock) # try to import the module and run the callable if run: - i = string.find(run, '.') + i = run.find('.') if i < 0: module = run callable = run else: module = run[:i] callable = run[i+1:] - write('Importing', module, '...', file=sys.stderr) + print >> sys.stderr, _('Importing %(module)s...') mod = __import__(module) - write('Running %s.%s()' % (module, callable), '...', file=sys.stderr) - # getattr(mode, callable)(m, *args) - r = apply(getattr(mod, callable), (m,) + tuple(args)) + print >> sys.stderr, _('Running %(module)s.%(callable)s()...') + r = getattr(mod, callable)(m, *args) diff --git a/cron/bumpdigests b/cron/bumpdigests index 7c6642fb4..891c68b9e 100644 --- a/cron/bumpdigests +++ b/cron/bumpdigests @@ -36,6 +36,7 @@ import paths from Mailman import MailList from Mailman import Utils from Mailman import Errors +from Mailman.i18n import _ # Work around known problems with some RedHat cron daemons import signal @@ -46,9 +47,9 @@ PROGRAM = sys.argv[0] def usage(code, msg=''): - print __doc__ % globals() + print >> sys.stderr, _(__doc__) if msg: - print msg + print >> sys.stderr, msg sys.exit(code) @@ -69,7 +70,7 @@ def main(): listnames = Utils.list_names() if not listnames: - print 'Nothing to do.' + print _('Nothing to do.') sys.exit(0) for listname in listnames: @@ -77,9 +78,9 @@ def main(): # be sure the list is locked mlist = MailList.MailList(listname) except Errors.MMListError, e: - usage(1, 'No such list: %s' % listname) + usage(1, _('No such list: %(listname)s')) try: - mlist.volume = mlist.volume + 1 + mlist.volume += 1 mlist.next_digest_number = 1 finally: mlist.Save() |
