diff options
| author | bwarsaw | 2001-05-20 02:43:23 +0000 |
|---|---|---|
| committer | bwarsaw | 2001-05-20 02:43:23 +0000 |
| commit | a92b60ee2107343bf12806415e886aa3308c3126 (patch) | |
| tree | 8c4365dc20f28c35732368a8353db0de85f0aa3c | |
| parent | 1c717be9f9e49427a7d24a95b859b1146aa898b6 (diff) | |
| download | mailman-a92b60ee2107343bf12806415e886aa3308c3126.tar.gz mailman-a92b60ee2107343bf12806415e886aa3308c3126.tar.zst mailman-a92b60ee2107343bf12806415e886aa3308c3126.zip | |
Renamed from `newlang'. Two reasons why I didn't like the old name:
it made command line completion difficult because of newlist, and I've
removed as obsolete rmlang (we're not really creating a newlang, we're
simply adding an existing language support to an existing list).
We lose the CVS history because of this move, but I didn't think it
was worth bothering with a SF admin request.
| -rw-r--r-- | bin/addlang | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/bin/addlang b/bin/addlang new file mode 100644 index 000000000..3a3308042 --- /dev/null +++ b/bin/addlang @@ -0,0 +1,120 @@ +#! /usr/bin/env python +# +# Copyright (C) 2000,2001 by the Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +"""Add language[s] support to a mailing list. + +Usage: + + newlang [options] [lang1 [lang2 ...]] + +Options: + + --help/-h + Print this message and exit. + + --listname=listname + -l listname + The name of the mailing list to add the language support to. This is + a required option. + +lang is the corresponding language directory and must exist in +mm_cfg.TEMPLATES. If no lang is given on the command line, the server's +default language is used. +""" + +import sys +import os +import getopt + +import paths # path hacking +from Mailman import mm_cfg +from Mailman import Utils +from Mailman import Errors +from Mailman import MailList +from Mailman import LockFile +from Mailman.i18n import _ + +COMMASPACE = ', ' + + + +def usage(code, msg=''): + print >> sys.stderr, _(__doc__) + if msg: + print >> sys.stderr, msg + sys.exit(code) + + + +def main(): + try: + opts, args = getopt.getopt(sys.argv[1:], 'l:h', ['listname=', 'help']) + except getopt.error, msg: + usage(1, msg) + + listname = None + for opt, arg in opts: + if opt in ('-h', '--help'): + usage(0) + elif opt in ('-l', '--listname'): + listname = arg + + languages = args + if listname is None: + usage(1, _('--listname/-l is required')) + if not languages: + languages = [mm_cfg.DEFAULT_SERVER_LANGUAGE] + + listname = listname.lower() + try: + mlist = MailList.MailList(listname, lock=0) + except Errors.MMListError, e: + usage(1, _('No such list "%(listname)s"\n%(e)s')) + + # We only need to create the language subdirectory in order to make the + # list support this language. Note that unless the list owner + # specifically wants to specialize their templates, the global defaults + # for the given language will work just fine. + ok_langs = [] + for lang in languages: + gtemplatesdir = os.path.join(mm_cfg.TEMPLATE_DIR, lang) + if not os.path.isdir(gtemplatesdir): + print >> sys.stderr, _( + 'No template directory for language: %(dir)s') + continue + ltemplatesdir = os.path.join(mlist.fullpath(), lang) + omask = os.umask(0) + try: + try: + os.mkdir(ltemplatesdir, 02775) + ok_langs.append(lang) + except OSError, e: + if e.errno <> errno.EEXIST: raise + print >> sys.stderr, _( + 'List already supports language: %(lang)s') + finally: + os.umask(omask) + + # All done + okmsg = COMMASPACE.join(ok_langs) + print _('Language support for %(okmsg)s added') + + + +if __name__ == '__main__': + main() |
