# Path: devmason_server/models.py
# class Build(models.Model):
#     project = models.ForeignKey(Project, related_name='builds')
#     success = models.BooleanField()
#     started = models.DateTimeField()
#     finished = models.DateTimeField()
#     host = models.CharField(max_length=250)
#     arch = models.CharField(max_length=250)
#     user = models.ForeignKey(User, blank=True, null=True, related_name='builds')
#     extra_info = JSONField()
# 
#     class Meta:
#         ordering = ['-finished']
# 
#     def __unicode__(self):
#         return u"Build %s for %s" % (self.pk, self.project)
# 
#     @models.permalink
#     def get_absolute_url(self):
#         return ('build_detail', [self.project.slug, self.pk])


import telnetlib
import sys
from django.db.models.signals import post_save
from devmason_server.models import Build


pw = "devmason_roxx"
srv = "irc.freenode.net"
chan = "#devmason"

def send_irc_msg(msg):
    try:
        t = telnetlib.Telnet()
        t.open('10.177.22.217', port=13337)
        t.write('%s %s&%s&%s\n' % (pw, srv, chan, msg))
    except:
        pass

def irc_handler(sender, **kwargs):
    build = kwargs['instance']
    send_irc_msg('%s: http://devmason.com%s | Passed: %s' % (build, build.get_absolute_url(), build.success))


# Path: devmason_server/models.py
# class Build(models.Model):
#     project = models.ForeignKey(Project, related_name='builds')
#     success = models.BooleanField()
#     started = models.DateTimeField()
#     finished = models.DateTimeField()
#     host = models.CharField(max_length=250)
#     arch = models.CharField(max_length=250)
#     user = models.ForeignKey(User, blank=True, null=True, related_name='builds')
#     extra_info = JSONField()
# 
#     class Meta:
#         ordering = ['-finished']
# 
#     def __unicode__(self):
#         return u"Build %s for %s" % (self.pk, self.project)
# 
#     @models.permalink
#     def get_absolute_url(self):
#         return ('build_detail', [self.project.slug, self.pk])


# Path: devmason_server/signals.py
import telnetlib
import sys
from django.db.models.signals import post_save
from devmason_server.models import Build



pw = "devmason_roxx"
srv = "irc.freenode.net"
chan = "#devmason"

def send_irc_msg(msg):
    try:
        t = telnetlib.Telnet()
        t.open('10.177.22.217', port=13337)
        t.write('%s %s&%s&%s\n' % (pw, srv, chan, msg))
    except:
        pass

def irc_handler(sender, **kwargs):
    build = kwargs['instance']
    send_irc_msg('%s: http://devmason.com%s | Passed: %s' % (build, build.get_absolute_url(), build.success))


post_save.connect(irc_handler, sender=Build)