| 1 | from buildbot.status import builder, mail |
|---|
| 2 | |
|---|
| 3 | class InformativeMailNotifier(mail.MailNotifier): |
|---|
| 4 | """MailNotifier subclass which provides additional information about the |
|---|
| 5 | build failure inside the email.""" |
|---|
| 6 | |
|---|
| 7 | # FIXME: The customMessage interface is fairly inefficient, switch to |
|---|
| 8 | # something new when it becomes available. |
|---|
| 9 | |
|---|
| 10 | def __init__(self, |
|---|
| 11 | numLines = 10, onlyFailureLogs = True, |
|---|
| 12 | *attrs, **kwargs): |
|---|
| 13 | mail.MailNotifier.__init__(self, customMesg=self.customMessage, |
|---|
| 14 | *attrs, **kwargs) |
|---|
| 15 | self.numLines = numLines |
|---|
| 16 | self.onlyFailureLogs = onlyFailureLogs |
|---|
| 17 | |
|---|
| 18 | def customMessage(self, attrs): |
|---|
| 19 | # Get the standard message. |
|---|
| 20 | data = mail.message(attrs)[0] |
|---|
| 21 | |
|---|
| 22 | data += '\n' + '='*80 + '\n\n' |
|---|
| 23 | |
|---|
| 24 | # Append addition information on the changes. |
|---|
| 25 | data += 'CHANGES:\n' |
|---|
| 26 | data += '\n\n'.join([c.asText() for c in attrs['changes']]) |
|---|
| 27 | data += '\n\n' |
|---|
| 28 | |
|---|
| 29 | # Append log files. |
|---|
| 30 | if self.numLines: |
|---|
| 31 | data += 'LOGS:\n' |
|---|
| 32 | for name, url, lines, logstatus in attrs['logs']: |
|---|
| 33 | if (self.onlyFailureLogs and logstatus != builder.FAILURE): |
|---|
| 34 | continue |
|---|
| 35 | |
|---|
| 36 | data += "Last %d lines of '%s':\n" % (self.numLines, name) |
|---|
| 37 | data += '\t' + '\n\t'.join(lines[-self.numLines:]) |
|---|
| 38 | data += '\n\n' |
|---|
| 39 | |
|---|
| 40 | return (data, 'plain') |
|---|