mail: ajout context manager "bugreport"
This commit is contained in:
parent
be3f3507cc
commit
83283fc2cb
7 changed files with 36 additions and 0 deletions
|
@ -7,6 +7,8 @@ import json
|
||||||
import inspect
|
import inspect
|
||||||
import locale
|
import locale
|
||||||
import smtplib
|
import smtplib
|
||||||
|
import traceback
|
||||||
|
from contextlib import contextmanager
|
||||||
|
|
||||||
from email.header import Header
|
from email.header import Header
|
||||||
from email.message import Message
|
from email.message import Message
|
||||||
|
@ -189,6 +191,27 @@ def format_sender(sender, header_charset='utf-8'):
|
||||||
|
|
||||||
return formataddr((sender_name, sender_addr))
|
return formataddr((sender_name, sender_addr))
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def bugreport():
|
||||||
|
try:
|
||||||
|
yield
|
||||||
|
except Exception as exc:
|
||||||
|
From = 'roots@crans.org'
|
||||||
|
to = From
|
||||||
|
tb = sys.exc_info()[2].tb_next
|
||||||
|
|
||||||
|
data = {
|
||||||
|
'from': From,
|
||||||
|
'to': to,
|
||||||
|
'exc': exc,
|
||||||
|
'lineno': tb.tb_frame.f_lineno,
|
||||||
|
'filename': os.path.basename(tb.tb_frame.f_code.co_filename),
|
||||||
|
'traceback': traceback.format_exc(),
|
||||||
|
}
|
||||||
|
mail = generate('bugreport', data)
|
||||||
|
with ServerConnection() as conn:
|
||||||
|
conn.sendmail(From, [to], mail.as_string())
|
||||||
|
raise
|
||||||
|
|
||||||
class ServerConnection(object):
|
class ServerConnection(object):
|
||||||
"""Connexion au serveur smtp"""
|
"""Connexion au serveur smtp"""
|
||||||
|
|
1
gestion/mail/template/bugreport/From/fr
Normal file
1
gestion/mail/template/bugreport/From/fr
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{{from}}
|
2
gestion/mail/template/bugreport/README
Normal file
2
gestion/mail/template/bugreport/README
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
Envoyé lorsqu'une exception a été jetée. Le mail contient le nom de l'exception
|
||||||
|
et un traceback.
|
1
gestion/mail/template/bugreport/Subject/fr
Normal file
1
gestion/mail/template/bugreport/Subject/fr
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Bugreport: "{{ exc }}"{% if filename %} (in {{ filename }}+{{ lineno }} ){% endif %}
|
1
gestion/mail/template/bugreport/To/fr
Normal file
1
gestion/mail/template/bugreport/To/fr
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{{to}}
|
1
gestion/mail/template/bugreport/X-Mailer/fr
Normal file
1
gestion/mail/template/bugreport/X-Mailer/fr
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{{ mailer }}
|
7
gestion/mail/template/bugreport/body/fr
Normal file
7
gestion/mail/template/bugreport/body/fr
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
Une erreur est survenue {% if filename %} dans le fichier {{ filename }} (ligne {{ lineno }}){% endif %}.
|
||||||
|
|
||||||
|
Traceback:
|
||||||
|
{{ traceback }}
|
||||||
|
|
||||||
|
--
|
||||||
|
bug-reporter
|
Loading…
Add table
Add a link
Reference in a new issue