Back to index

moin  1.9.0~rc2
mailtranslators.py
Go to the documentation of this file.
00001 # -*- coding: iso-8859-1 -*-
00002 """
00003 MoinMoin - mailtranslators script
00004 
00005 @copyright: 2004-2007 MoinMoin:ThomasWaldmann
00006 @license: GPL, see COPYING for details
00007 """
00008 
00009 import sys
00010 
00011 from MoinMoin import i18n
00012 from MoinMoin.mail.sendmail import sendmail
00013 from MoinMoin.script import MoinScript
00014 
00015 class PluginScript(MoinScript):
00016     """\
00017 Purpose:
00018 ========
00019 This tool allows you to have a message read in from standard input, and
00020 then sent to all translators via email. If you use %(lang)s in the message
00021 it will be replaced with the appropriate language code for the translator.
00022 
00023 Detailed Instructions:
00024 ======================
00025 General syntax: moin [options] maint mailtranslators [mailtranslators-options]
00026 
00027 [options] usually should be:
00028     --config-dir=/path/to/my/cfg/ --wiki-url=wiki.example.org/
00029 
00030 [mailtranslators-options] see below:
00031     0. To send an email to all translaters, from john@smith.com, and with a subject
00032        of 'Please update your translations!' and a body of 'Please update your language,
00033        %(lang)s'
00034        moin ... maint mailtranslators --from-address john@smith.com --subject 'Please update your translations!'
00035        Please update your language, %(lang)s
00036        ^D
00037 """
00038 
00039     def __init__(self, argv, def_values):
00040         MoinScript.__init__(self, argv, def_values)
00041         self.parser.add_option(
00042             "-f", "--from-address", dest="from_address",
00043             help="use as from: for email."
00044         )
00045         self.parser.add_option(
00046             "-s", "--subject", dest="subject",
00047             help="use as subject: for email."
00048         )
00049 
00050     def mainloop(self):
00051         self.init_request()
00052         request = self.request
00053 
00054         from_address = unicode(self.options.from_address or "tw-public@gmx.de")
00055         subject = unicode(self.options.subject or "MoinMoin i18n notification")
00056         text_template = unicode(sys.stdin.read())
00057 
00058         languages = i18n.wikiLanguages()
00059         langs = languages.keys()
00060         langs.remove('en') # nothing to do for english, so remove it
00061         #langs = ['de', ] # for testing
00062 
00063         if len(text_template) > 10: # do not send mails w/o real content
00064             for lang in langs:
00065                 to_address = languages[lang]['last-translator']
00066                 rc = None
00067                 if to_address and '***vacant***' not in to_address:
00068                     text = text_template % locals()
00069                     rc = sendmail(request, [to_address], subject, text, mail_from=from_address)
00070                     print lang, repr(from_address), repr(to_address), subject, repr(rc)
00071