1# -*- coding: iso-8859-1 -*- 2""" 3MoinMoin - mailtranslators script 4 5@copyright: 2004-2007 MoinMoin:ThomasWaldmann 6@license: GPL, see COPYING for details 7""" 8 9import sys 10 11from MoinMoin import i18n 12from MoinMoin.mail.sendmail import sendmail 13from MoinMoin.script import MoinScript 14 15class PluginScript(MoinScript): 16 """\ 17Purpose: 18======== 19This tool allows you to have a message read in from standard input, and 20then sent to all translators via email. If you use %(lang)s in the message 21it will be replaced with the appropriate language code for the translator. 22 23Detailed Instructions: 24====================== 25General syntax: moin [options] maint mailtranslators [mailtranslators-options] 26 27[options] usually should be: 28 --config-dir=/path/to/my/cfg/ --wiki-url=http://wiki.example.org/ 29 30[mailtranslators-options] see below: 31 0. To send an email to all translaters, from john@smith.com, and with a subject 32 of 'Please update your translations!' and a body of 'Please update your language, 33 %(lang)s' 34 moin ... maint mailtranslators --from-address john@smith.com --subject 'Please update your translations!' 35 Please update your language, %(lang)s 36 ^D 37""" 38 39 def __init__(self, argv, def_values): 40 MoinScript.__init__(self, argv, def_values) 41 self.parser.add_option( 42 "-f", "--from-address", dest="from_address", 43 help="use as from: for email." 44 ) 45 self.parser.add_option( 46 "-s", "--subject", dest="subject", 47 help="use as subject: for email." 48 ) 49 50 def mainloop(self): 51 self.init_request() 52 request = self.request 53 54 from_address = unicode(self.options.from_address or "tw@waldmann-edv.de") 55 subject = unicode(self.options.subject or "MoinMoin i18n notification") 56 text_template = unicode(sys.stdin.read()) 57 58 languages = i18n.wikiLanguages() 59 langs = languages.keys() 60 langs.remove('en') # nothing to do for english, so remove it 61 #langs = ['de', ] # for testing 62 63 if len(text_template) > 10: # do not send mails w/o real content 64 for lang in langs: 65 to_address = languages[lang]['last-translator'] 66 rc = None 67 if to_address and '***vacant***' not in to_address: 68 text = text_template % locals() 69 rc = sendmail(request, [to_address], subject, text, mail_from=from_address) 70 print lang, repr(from_address), repr(to_address), subject, repr(rc) 71 72