'''
Created on Jun 3, 2013

__author__ = "Elizabeth 'pidge' Flanagan"
__copyright__ = "Copyright 2013, Intel Corp."
__credits__ = ["Elizabeth Flanagan"]
__license__ = "GPL"
__version__ = "2.0"
__maintainer__ = "Elizabeth Flanagan"
__email__ = "elizabeth.flanagan@intel.com"
'''
#!/usr/bin/python
from twisted.python import log
from buildbot.status.builder import Results

def message_formatter(mode, name, build, results, master_status):
    result = Results[results]
    limit_lines = 60
    text = list()
    text.append('<h4>Build status: %s</h4>' % result.upper())
    text.append("Buildslave for this Build: <b>%s</b>" % build.getSlavename())
    text.append('<br>')
    if master_status.getURLForThing(build):
        text.append('Complete logs for all build steps: <a href="%s">%s</a>'
                 % (master_status.getURLForThing(build),
                    master_status.getURLForThing(build))
                 )
    text.append('<br>')
    text.append("Build Reason: %s" % build.getReason())
    text.append('<br>')

    try:
        build_properties = build.getProperties().asList()
    except:
        pass
    if build_properties:
        text.append("Build Properties:<br>")
        text.append("<ul>")
        for prop in build_properties:
            if str(prop[1]) != '':
                text.append('<li>' + prop[0] + " : " + str(prop[1])+"</li>")
        text.append('</ul>')
    url = ""
    for log in build.getLogs():
         log_name = "%s.%s" % (log.getStep().getName(), log.getName())
         log_status, dummy = log.getStep().getResults()
         log_body = []
         for line in log.getText().splitlines(): # Note: can be VERY LARGE
            print line
            if "ERROR" in line or "|" in line:
               log_body.append(line)

         log_url = '%s/steps/%s/logs/%s' % (master_status.getURLForThing(build),
                                            log.getStep().getName(),
                                            log.getName())

         if log_status == 2 and log_body:
            text.append('<i>Detailed log of last build step:</i> <a href="%s">%s</a>'
                        % (log_url, log_url))
            text.append('<br>')
            text.append('<h4>Last %d lines of "%s" Error log:</h4>' % (limit_lines, log_name))
            text.append('<p>')
            text.append('<br>'.join([line for line in
                                     log_body[len(log_body)-limit_lines:]]))
            text.append('</p>')
    text.append('<br><br>')
    text.append('<b>-The Yocto BuildBot</b>')
    return {'body': "\n".join(text), 'type': 'html'}


@@ -1287,16 +1287,605 @@
  != '':%0A
+                if prop%5B0%5D == %22BBLAYERS%22 or prop%5B0%5D == %22LOCALCONF%22:%0A                    if prop%5B0%5D == 'BBLAYERS':%0A                        text.append('%3Cli%3EContents of bblayers.conf (Note. LCONF_VERSION will not show up correctly)%3Cbr%3E%3Ccode%3E')%0A                    else:%0A                        text.append('%3Cli%3EContents of auto.conf (local.conf for autobuilders)%3Cbr%3E%3Ccode%3E')%0A                    lines=prop%5B1%5D.splitlines()%0A                    for line in lines:%0A                        text.append(line + %22%3Cbr%3E%22)%0A                    text.append('%3Cbr%3E%3C/code%3E%3C/li%3E') %0A                else:%0A    
         

Fix auto/bblayers lines