X-Git-Url: https://git.tld-linux.org/?a=blobdiff_plain;f=TLD_Builder%2Fwrap.py;fp=TLD_Builder%2Fwrap.py;h=0c9df39281cf6d9f724f9d308ba2b573a762e2ff;hb=b999f53d4bf5d44586ecf028876e8bc20b5fd2ce;hp=0000000000000000000000000000000000000000;hpb=37463eaa22f48f5fecbb90e69ef67a69e0bf9788;p=tld-builder.git diff --git a/TLD_Builder/wrap.py b/TLD_Builder/wrap.py new file mode 100644 index 0000000..0c9df39 --- /dev/null +++ b/TLD_Builder/wrap.py @@ -0,0 +1,56 @@ +# vi: encoding=utf-8 ts=8 sts=4 sw=4 et + +import sys +import log +import traceback +import StringIO +import os +import time + +# this module, as it deals with internal error handling shouldn't +# import anything beside status +import status + +try: + import mailer + def sendmail(trace): + m = mailer.Message() + m.set_headers(to = status.admin, cc = "%s, %s" % (status.email, status.builder_list), subject = "fatal python exception") + m.write("%s\n" % trace) + m.write("during: %s\n" % status.get()) + m.send() +except: + def sendmail(trace): + # don't use mailer.py; it safer this way + f = os.popen("/usr/sbin/sendmail -i -t", "w") + f.write("""Subject: builder failure +To: %s +Cc: %s, %s +Date: %s +X-TLD-Builder: fatal error report + +%s + +during: %s +""" % (status.admin, status.email, status.builder_list, + time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime()), + trace, status)) + f.close() + +def wrap(main): + try: + main() + except: + exctype, value = sys.exc_info()[:2] + if exctype == SystemExit: + sys.exit(value) + s = StringIO.StringIO() + traceback.print_exc(file = s, limit = 20) + + log.alert("fatal python exception") + log.alert(s.getvalue()) + log.alert("during: %s" % status.get()) + + sendmail(s.getvalue()) + + sys.exit(1)