From 283f83e3bcb7840129dfe6770e6561d2fda26844 Mon Sep 17 00:00:00 2001 From: bwarsaw Date: Wed, 28 Feb 2001 05:52:21 +0000 Subject: Next round of big i18n patches. main(): Do two step creation and locking of mailing list so we can have a better error message when we couldn't acquire the list lock. Also, make sure that once we have the lock, all work is wrapped in a try/finally so that the list won't be left in a locked state on error. --- bin/newlang | 67 ++++++++++++++++++++++++++++++++++++------------------------- bin/rmlang | 44 ++++++++++++++++++++++++---------------- 2 files changed, 67 insertions(+), 44 deletions(-) (limited to 'bin') diff --git a/bin/newlang b/bin/newlang index 83058b74a..f50eae8d3 100644 --- a/bin/newlang +++ b/bin/newlang @@ -1,6 +1,6 @@ #! /usr/bin/env python # -# Copyright (C) 2000 by the Free Software Foundation, Inc. +# 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 @@ -44,6 +44,7 @@ from Mailman import mm_cfg from Mailman import Utils from Mailman import Errors from Mailman import MailList +from Mailman import LockFile from Mailman.HTMLFormatter import HTMLFormatter from Mailman.i18n import _ @@ -78,33 +79,45 @@ def main(): listname = listname.lower() try: - mlist = MailList.MailList(listname) + mlist = MailList.MailList(listname, lock=0) except Errors.MMListError, e: - usage(1, _('Could not open mailing list: %(listname)s\n%(e)s')) - - # BAW: this seems questionable - HTMLFormatter.InitVars(list) - - ok_langs = [] - for lang in languages: - dir = os.path.join(mm_cfg.TEMPLATE_DIR, lang) - if not os.path.exists(dir): - print >> sys.stderr, _('Language not supported: %(lang)s') - continue - if os.path.exists(os.path.join(mlist._template_dir, lang)): - print >> sys.stderr, _('List already supports language: %(lang)s') - continue - ok_langs.append(lang) - - # VGG, moved this out of the loop, as list.InitTemplates walks a list - # - # BAW: I want to look at this in more detail. - os.umask(002) - mlist.InitTemplates(ok_langs) - print _('Language support for'), - for lang in ok_langs: - print '%s,' % lang, - print _('added') + usage(1, _('No such list "%(listname)s"\n%(e)s')) + + try: + mlist.Lock(timeout=0.5) + except LockFile.TimeOutError: + usage(1, _("Could't acquire list lock, try again later: %(listname)s")) + + try: + HTMLFormatter.InitVars(mlist) + ok_langs = [] + for lang in languages: + dir = os.path.join(mm_cfg.TEMPLATE_DIR, lang) + if not os.path.exists(dir): + print >> sys.stderr, _( + 'No template directory for language: %(dir)s') + continue + if os.path.exists(os.path.join(mlist._template_dir, lang)): + print >> sys.stderr, _( + 'List already supports language: %(lang)s') + continue + ok_langs.append(lang) + + # VGG, moved this out of the loop, as list.InitTemplates walks a list + if not ok_langs: + print _('No languages added to list: %(listname)s') + return + + # Copy all the templates from the generic language template directory + # to a directory living under lists/. + mlist.InitTemplates(ok_langs) + print _('Language support for'), + for lang in ok_langs: + print '%s,' % lang, + print _('added') + finally: + mlist.Save() + mlist.Unlock() diff --git a/bin/rmlang b/bin/rmlang index 1dbef1902..89d591bdc 100644 --- a/bin/rmlang +++ b/bin/rmlang @@ -90,24 +90,34 @@ def main(): listname = listname.lower() try: - mlist = MailList.MailList(listname) + mlist = MailList.MailList(listname, lock=0) except Errors.MMListError, e: - usage(1, _('Could not open mailing list: %(listname)s\n%(e)s')) - - # BAW: hmm... same question as with newlist - HTMLFormatter.InitVars(list) - - for lang in languages: - dir = os.path.join(list._template_dir, lang) - if lang == mm_cfg.DEFAULT_SERVER_LANGUAGE: - print >> sys.stderr, _('%(lang)s is the server default language ' - 'and cannot be removed') - continue - if not os.path.exists(dir): - print >> sys.stderr, _('Language %(lang)s not supported by list') - continue - - remove_it(listname, directory, _('language support for %(lang)s')) + usage(1, _('No such list "%(listname)s"\n%(e)s')) + + try: + mlist.Lock(timeout=0.5) + except LockFile.TimeOutError: + usage(1, _("Could't acquire list lock, try again later: %(listname)s")) + + try: + # BAW: hmm... same question as with newlist + HTMLFormatter.InitVars(mlist) + + for lang in languages: + dir = os.path.join(mlist._template_dir, lang) + if lang == mm_cfg.DEFAULT_SERVER_LANGUAGE: + print >> sys.stderr, _('''\ +%(lang)s is the server default language and cannot be removed''') + continue + if not os.path.exists(dir): + print >> sys.stderr, _( + 'Language %(lang)s not supported by list: %(listname)s') + continue + + remove_it(listname, dir, _('language support for %(lang)s')) + finally: + mlist.Save() + mlist.Unlock() -- cgit v1.3.1