Mercurial > moin > 1.9
changeset 3079:75f431e6d632
adapt i18n maintainer mailings script to script framework (ported from 1.6)
author | Thomas Waldmann <tw AT waldmann-edv DOT de> |
---|---|
date | Fri, 22 Feb 2008 22:40:52 +0100 |
parents | be729248d9f5 |
children | 7dcd8b937fd0 |
files | MoinMoin/i18n/tools/mail_i18n-maintainers.py MoinMoin/script/maint/mailtranslators.py |
diffstat | 2 files changed, 55 insertions(+), 98 deletions(-) [+] |
line wrap: on
line diff
--- a/MoinMoin/i18n/tools/mail_i18n-maintainers.py Fri Feb 22 22:38:35 2008 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,98 +0,0 @@ -#!/usr/bin/env python -""" - read mail text from standard input and - send an email to all i18n maintainers - %(lang)s will be replaced by language - - TODO: - * needs update to 1.6, doesn't work anymore "as is" - * use MoinMoin.script framework - * check that sendmail stuff, we also have it in MoinMoin.mail - - @copyright: 2004 Thomas Waldmann - @license: GNU GPL, see COPYING for details -""" - -mail_from = 'tw-public@gmx.de' -mail_subject = 'MoinMoin i18n notification' - -mail_smarthost = 'localhost' -mail_login = None -charset = 'iso-8859-1' - -from MoinMoin.i18n.meta import languages - -def sendmail(mfrom, mto, subject, text): - """ - Send a mail to the address(es) in 'to', with the given subject and - mail body 'text'. - - Return a tuple of success or error indicator and message. - - TODO: code duplicated from MoinMoin/util/mail.py - - @param mfrom: source email address - @param to: target email address - @param subject: subject of email - @param text: email body text - @rtype: tuple - @return: (is_ok, msg) - """ - import smtplib, socket, os - from email.MIMEText import MIMEText - from email.Header import Header - from email.Utils import formatdate - global charset, mail_smarthost, mail_login - - # Create a text/plain message - msg = MIMEText(text, 'plain', charset) - msg['From'] = mfrom - msg['To'] = ', '.join(mto) - msg['Subject'] = Header(subject, charset) - msg['Date'] = formatdate() - - try: - server = smtplib.SMTP(mail_smarthost) - try: - #server.set_debuglevel(1) - if mail_login: - user, pwd = mail_login.split() - server.login(user, pwd) - server.sendmail(mail_from, mto, msg.as_string()) - finally: - try: - server.quit() - except AttributeError: - # in case the connection failed, SMTP has no "sock" attribute - pass - except smtplib.SMTPException, e: - return (0, str(e)) - except (os.error, socket.error), e: - return (0, "Connection to mailserver '%(server)s' failed: %(reason)s" % { - 'server': mail_smarthost, - 'reason': str(e) - }) - - return (1, "Mail sent OK") - -def notify_maintainer(lang, mail_text): - mailaddr = languages[lang][4] - rc = None - if mailaddr and '***vacant***' not in mailaddr: - text = mail_text % locals() - rc = sendmail(mail_from, [mailaddr], mail_subject, text) - return rc - -if __name__ == '__main__': - langs = languages.keys() - langs.remove('en') # nothing to do for english, so remove it - - #langs = ['de', ] # for testing - - import sys - mail_text = sys.stdin.read() - - if len(mail_text) > 10: # do not send mails w/o real content - for lang in langs: - notify_maintainer(lang, mail_text) -
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MoinMoin/script/maint/mailtranslators.py Fri Feb 22 22:40:52 2008 +0100 @@ -0,0 +1,55 @@ +# -*- coding: iso-8859-1 -*- +""" + MoinMoin - mailtranslators script + + read mail text from standard input and send an email to all translators - + %(lang)s will be replaced by language. + + Usage: moin ... maint mailtranslators + + @copyright: 2004-2007 MoinMoin:ThomasWaldmann + @license: GPL, see COPYING for details +""" + +import sys, os + +from MoinMoin import config, i18n +from MoinMoin.mail.sendmail import sendmail +from MoinMoin.script import MoinScript + +class PluginScript(MoinScript): + def __init__(self, argv, def_values): + MoinScript.__init__(self, argv, def_values) + self.parser.add_option( + "-f", "--from-address", dest="from_address", + help="use as from: for email." + ) + self.parser.add_option( + "-s", "--subject", dest="subject", + help="use as subject: for email." + ) + + def mainloop(self): + self.init_request() + request = self.request + request.form = request.args = request.setup_args() + + from_address = unicode(self.options.from_address or "tw-public@gmx.de") + subject = unicode(self.options.subject or "MoinMoin i18n notification") + text_template = unicode(sys.stdin.read()) + + languages = i18n.wikiLanguages() + langs = languages.keys() + langs.remove('en') # nothing to do for english, so remove it + #langs = ['de', ] # for testing + + if len(text_template) > 10: # do not send mails w/o real content + for lang in langs: + to_address = languages[lang]['last-translator'] + rc = None + if to_address and '***vacant***' not in to_address: + text = text_template % locals() + print lang, from_address, to_address, subject, text + rc = sendmail(request, [to_address], subject, text, mail_from=from_address) + +