Browse Source

Email notification for failed URL fetches.

pull/25/head
shypike 13 years ago
parent
commit
05ab19b5a6
  1. 22
      email/badfetch-en.tmpl
  2. 9
      sabnzbd/emailer.py
  3. 7
      sabnzbd/misc.py
  4. 33
      tools/extract_pot.py
  5. 37
      tools/make_mo.py

22
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

9
sabnzbd/emailer.py

@ -1,5 +1,5 @@
#!/usr/bin/python -OO #!/usr/bin/python -OO
# Copyright 2008-2011 The SABnzbd-Team <team@sabnzbd.org> # Copyright 2008-2012 The SABnzbd-Team <team@sabnzbd.org>
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # 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) 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 # EMAIL_DISKFULL
# #

7
sabnzbd/misc.py

@ -1,5 +1,5 @@
#!/usr/bin/python -OO #!/usr/bin/python -OO
# Copyright 2008-2011 The SABnzbd-Team <team@sabnzbd.org> # Copyright 2008-2012 The SABnzbd-Team <team@sabnzbd.org>
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # 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: else:
nzo.fail_msg = msg 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') 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 from sabnzbd.nzbqueue import NzbQueue
assert isinstance(NzbQueue.do, NzbQueue) assert isinstance(NzbQueue.do, NzbQueue)
NzbQueue.do.remove(nzo.nzo_id, add_to_history=True) NzbQueue.do.remove(nzo.nzo_id, add_to_history=True)

33
tools/extract_pot.py

@ -1,5 +1,5 @@
#!/usr/bin/python -OO #!/usr/bin/python -OO
# Copyright 2011 The SABnzbd-Team <team@sabnzbd.org> # Copyright 2011-2012 The SABnzbd-Team <team@sabnzbd.org>
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
@ -105,6 +105,17 @@ def get_context(line):
return '#: ' + ' # '.join(newlines) + '\n' 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): if not os.path.exists(PO_DIR):
os.makedirs(PO_DIR) os.makedirs(PO_DIR)
@ -153,23 +164,9 @@ if not os.path.exists(POE_DIR):
os.makedirs(POE_DIR) os.makedirs(POE_DIR)
dst = open(os.path.join(POE_DIR, DOMAIN_EMAIL+'.pot'), 'wb') dst = open(os.path.join(POE_DIR, DOMAIN_EMAIL+'.pot'), 'wb')
dst.write(HEADER.replace('__TYPE__', 'EMAIL')) dst.write(HEADER.replace('__TYPE__', 'EMAIL'))
add_tmpl_to_pot('email', dst)
src = open(EMAIL_DIR+'/email-en.tmpl', 'r') add_tmpl_to_pot('rss', dst)
dst.write('\n#: email/email.tmpl:1\n') add_tmpl_to_pot('badfetch', dst)
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()
dst.close() dst.close()

37
tools/make_mo.py

@ -1,6 +1,6 @@
#!/usr/bin/python -OO #!/usr/bin/python -OO
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright 2010-2011 The SABnzbd-Team <team@sabnzbd.org> # Copyright 2010-2012 The SABnzbd-Team <team@sabnzbd.org>
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
@ -158,6 +158,18 @@ def remove_mo_files():
if not f.startswith(DOMAIN): if not f.startswith(DOMAIN):
os.remove(os.path.join(root, f)) 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(): def make_templates():
""" Create email templates """ Create email templates
@ -172,25 +184,10 @@ def make_templates():
# The unicode flag will make _() return Unicode # The unicode flag will make _() return Unicode
trans.install(unicode=True, names=['lgettext']) trans.install(unicode=True, names=['lgettext'])
src = open(EMAIL_DIR + '/email-en.tmpl', 'r') translate_tmpl('email', lng)
data = src.read().decode('utf-8') translate_tmpl('rss', lng)
src.close() translate_tmpl('badfetch', lng)
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()
mo_path = os.path.normpath('%s/%s%s/%s.mo' % (MO_DIR, path, MO_LOCALE, DOMAIN_E)) mo_path = os.path.normpath('%s/%s%s/%s.mo' % (MO_DIR, path, MO_LOCALE, DOMAIN_E))
if os.path.exists(mo_path): if os.path.exists(mo_path):
os.remove(mo_path) os.remove(mo_path)

Loading…
Cancel
Save