diff --git a/email/badfetch-en.tmpl b/email/badfetch-en.tmpl new file mode 100644 index 0000000..515f34a --- /dev/null +++ b/email/badfetch-en.tmpl @@ -0,0 +1,22 @@ +## +## Bad URL Fetch Email template for SABnzbd +## This a Cheetah template +## Documentation: http://sabnzbd.wikidot.com/email-templates +## +## Newlines and whitespace are significant! +## +## These are the email headers +To: $to +From: $from +Date: $date +Subject: SABnzbd failed to fetch an NZB +X-priority: 5 +X-MS-priority: 5 +## After this comes the body, the empty line is required! + +Hi, + +SABnzbd has failed to retrieve the NZB from $url. +The error message was: $msg + +Bye diff --git a/sabnzbd/emailer.py b/sabnzbd/emailer.py index ac88481..fc1d63b 100644 --- a/sabnzbd/emailer.py +++ b/sabnzbd/emailer.py @@ -1,5 +1,5 @@ #!/usr/bin/python -OO -# Copyright 2008-2011 The SABnzbd-Team +# Copyright 2008-2012 The SABnzbd-Team # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -218,6 +218,13 @@ def rss_mail(feed, jobs): return send_with_template('rss', parm) +def badfetch_mail(msg, url): + """ Send notification email about failed NZB fetch """ + + parm = {'url' : url, 'msg' : msg} + return send_with_template('badfetch', parm) + + ################################################################################ # EMAIL_DISKFULL # diff --git a/sabnzbd/misc.py b/sabnzbd/misc.py index 0500dc8..be752fb 100644 --- a/sabnzbd/misc.py +++ b/sabnzbd/misc.py @@ -1,5 +1,5 @@ #!/usr/bin/python -OO -# Copyright 2008-2011 The SABnzbd-Team +# Copyright 2008-2012 The SABnzbd-Team # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -922,7 +922,12 @@ def bad_fetch(nzo, url, msg='', retry=False, content=False): else: nzo.fail_msg = msg + if isinstance(url, int) or url.isdigit(): + url = 'Newzbin #%s' % url growler.send_notification(T('URL Fetching failed; %s') % '', '%s\n%s' % (msg, url), 'other') + #import sabnzbd.emailer + sabnzbd.emailer.badfetch_mail(msg, url) + from sabnzbd.nzbqueue import NzbQueue assert isinstance(NzbQueue.do, NzbQueue) NzbQueue.do.remove(nzo.nzo_id, add_to_history=True) diff --git a/tools/extract_pot.py b/tools/extract_pot.py index 9862df3..6883ecd 100755 --- a/tools/extract_pot.py +++ b/tools/extract_pot.py @@ -1,5 +1,5 @@ #!/usr/bin/python -OO -# Copyright 2011 The SABnzbd-Team +# Copyright 2011-2012 The SABnzbd-Team # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -105,6 +105,17 @@ def get_context(line): return '#: ' + ' # '.join(newlines) + '\n' +def add_tmpl_to_pot(prefix, dst): + """ Append english template to open POT file 'dst'""" + src = open(EMAIL_DIR+'/%s-en.tmpl' % prefix, 'r') + dst.write('#: email/%s.tmpl:1\n' % prefix) + dst.write('msgid ""\n') + for line in src: + dst.write('"%s"\n' % line.replace('\n', '\\n').replace('"', '\\"')) + dst.write('msgstr ""\n\n') + src.close() + + if not os.path.exists(PO_DIR): os.makedirs(PO_DIR) @@ -153,23 +164,9 @@ if not os.path.exists(POE_DIR): os.makedirs(POE_DIR) dst = open(os.path.join(POE_DIR, DOMAIN_EMAIL+'.pot'), 'wb') dst.write(HEADER.replace('__TYPE__', 'EMAIL')) - -src = open(EMAIL_DIR+'/email-en.tmpl', 'r') -dst.write('\n#: email/email.tmpl:1\n') -dst.write('msgid ""\n') -for line in src: - dst.write('"%s"\n' % line.replace('\n', '\\n').replace('"', '\\"')) -dst.write('msgstr ""\n\n') -src.close() - -src = open(EMAIL_DIR+'/rss-en.tmpl', 'r') -dst.write('#: email/rss.tmpl:1\n') -dst.write('msgid ""\n') -for line in src: - dst.write('"%s"\n' % line.replace('\n', '\\n').replace('"', '\\"')) -dst.write('msgstr ""\n\n') -src.close() - +add_tmpl_to_pot('email', dst) +add_tmpl_to_pot('rss', dst) +add_tmpl_to_pot('badfetch', dst) dst.close() diff --git a/tools/make_mo.py b/tools/make_mo.py index 8b1e736..a9cba55 100755 --- a/tools/make_mo.py +++ b/tools/make_mo.py @@ -1,6 +1,6 @@ #!/usr/bin/python -OO # -*- coding: utf-8 -*- -# Copyright 2010-2011 The SABnzbd-Team +# Copyright 2010-2012 The SABnzbd-Team # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -158,6 +158,18 @@ def remove_mo_files(): if not f.startswith(DOMAIN): os.remove(os.path.join(root, f)) +def translate_tmpl(prefix, lng): + """ Translate template 'prefix' into language 'lng' """ + src = open(EMAIL_DIR + '/%s-en.tmpl' % prefix, 'r') + data = src.read().decode('utf-8') + src.close() + data = _(data).encode('utf-8') + fp = open('email/%s-%s.tmpl' % (prefix, lng), 'wb') + if not (-1 < data.find('UTF-8') < 30): + fp.write('#encoding UTF-8\n') + fp.write(data) + fp.close() + def make_templates(): """ Create email templates @@ -172,25 +184,10 @@ def make_templates(): # The unicode flag will make _() return Unicode trans.install(unicode=True, names=['lgettext']) - src = open(EMAIL_DIR + '/email-en.tmpl', 'r') - data = src.read().decode('utf-8') - src.close() - data = _(data).encode('utf-8') - fp = open('email/email-%s.tmpl' % lng, 'wb') - if not (-1 < data.find('UTF-8') < 30): - fp.write('#encoding UTF-8\n') - fp.write(data) - fp.close() - - src = open(EMAIL_DIR + '/rss-en.tmpl', 'r') - data = src.read().decode('utf-8') - src.close() - data = _(data).encode('utf-8') - fp = open('email/rss-%s.tmpl' % lng, 'wb') - if not (-1 < data.find('UTF-8') < 30): - fp.write('#encoding UTF-8\n') - fp.write(data) - fp.close() + translate_tmpl('email', lng) + translate_tmpl('rss', lng) + translate_tmpl('badfetch', lng) + mo_path = os.path.normpath('%s/%s%s/%s.mo' % (MO_DIR, path, MO_LOCALE, DOMAIN_E)) if os.path.exists(mo_path): os.remove(mo_path)