Source

fabric_factory / src / factory / signals.py

from django.db.models.signals import pre_save
from django.core.mail import send_mail
from django.conf import settings

def send_build_email(instance, **kwargs):
    if not getattr(settings, 'FF_EMAIL_BUILD_RESULTS', False):
        return

    if not instance.executed:
        return

    if not instance.fabfile_recipe.notify:
        return

    subject = '%s Build Results (%s)' % (instance, "success" if instance.success else "failure")
    msg = """
    Tasks: %(task)s
    Recipe: %(recipe)s
    ------------------------------------------------
    Output
    ------------------------------------------------
    %(output)s


    ------------------------------------------------
    Errors
    ------------------------------------------------
    %(error)s
    """ % dict(task=instance.task,
               recipe=instance.fabfile_recipe,
               output=instance.output,
               error=instance.error)

    send_mail(subject, msg, settings.SERVER_EMAIL,
              [instance.fabfile_recipe.notify], fail_silently=False)




def connect(build_model):
    pre_save.connect(send_build_email, sender=build_model)