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 locale
|
||||
import smtplib
|
||||
import traceback
|
||||
from contextlib import contextmanager
|
||||
|
||||
from email.header import Header
|
||||
from email.message import Message
|
||||
|
@ -189,6 +191,27 @@ def format_sender(sender, header_charset='utf-8'):
|
|||
|
||||
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):
|
||||
"""Connexion au serveur smtp"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue