Blame progit/hooks/irc.py

Pierre-Yves Chibon 009d48
#-*- coding: utf-8 -*-
Pierre-Yves Chibon 009d48
Pierre-Yves Chibon 009d48
"""
Pierre-Yves Chibon 009d48
 (c) 2014 - Copyright Red Hat Inc
Pierre-Yves Chibon 009d48
Pierre-Yves Chibon 009d48
 Authors:
Pierre-Yves Chibon 009d48
   Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
Pierre-Yves Chibon 009d48
Pierre-Yves Chibon 009d48
"""
Pierre-Yves Chibon 009d48
Pierre-Yves Chibon 009d48
from flask.ext import wtf
Pierre-Yves Chibon 5808d7
import sqlalchemy as sa
Pierre-Yves Chibon 009d48
import wtforms
Pierre-Yves Chibon 009d48
Pierre-Yves Chibon 5808d7
from progit.hooks import BaseHook
Pierre-Yves Chibon 5808d7
from progit.model import BASE
Pierre-Yves Chibon 5808d7
from progit import SESSION
Pierre-Yves Chibon 5808d7
Pierre-Yves Chibon 5808d7
Pierre-Yves Chibon 5808d7
class IrcTable(BASE):
Pierre-Yves Chibon 5808d7
    """ Stores information about the irc hook deployed on a project.
Pierre-Yves Chibon 5808d7
Pierre-Yves Chibon 5808d7
    Table -- hook_irc
Pierre-Yves Chibon 5808d7
    """
Pierre-Yves Chibon 5808d7
Pierre-Yves Chibon 5808d7
    __tablename__ = 'hook_irc'
Pierre-Yves Chibon 5808d7
Pierre-Yves Chibon 5808d7
    id = sa.Column(sa.Integer, primary_key=True)
Pierre-Yves Chibon 5808d7
    project_id = sa.Column(
Pierre-Yves Chibon 5808d7
        sa.Integer,
Pierre-Yves Chibon 5808d7
        sa.ForeignKey('projects.id', onupdate='CASCADE'),
Pierre-Yves Chibon 5808d7
        nullable=False,
Pierre-Yves Chibon 5808d7
        index=True)
Pierre-Yves Chibon 5808d7
Pierre-Yves Chibon 5808d7
    server = sa.Column(sa.Text, nullable=False)
Pierre-Yves Chibon 5808d7
    port = sa.Column(sa.Text, nullable=False)
Pierre-Yves Chibon 5808d7
    room = sa.Column(sa.Text, nullable=False)
Pierre-Yves Chibon 5808d7
    nick = sa.Column(sa.Text, nullable=True, default=None)
Pierre-Yves Chibon 5808d7
    nick_pass = sa.Column(sa.Text, nullable=True, default=None)
Pierre-Yves Chibon 5808d7
    active = sa.Column(sa.Boolean, nullable=False, default=False)
Pierre-Yves Chibon 5808d7
    join = sa.Column(sa.Boolean, nullable=False, default=True)
Pierre-Yves Chibon 5808d7
    ssl = sa.Column(sa.Boolean, nullable=False, default=True)
Pierre-Yves Chibon 5808d7
Pierre-Yves Chibon 009d48
Pierre-Yves Chibon 009d48
class IrcForm(wtf.Form):
Pierre-Yves Chibon 009d48
    ''' Form to configure the irc hook. '''
Pierre-Yves Chibon 009d48
    server = wtforms.TextField(
Pierre-Yves Chibon 009d48
        'Server *',
Pierre-Yves Chibon 009d48
        [wtforms.validators.Required()]
Pierre-Yves Chibon 009d48
    )
Pierre-Yves Chibon 009d48
    port = wtforms.TextField(
Pierre-Yves Chibon 009d48
        'Port *',
Pierre-Yves Chibon 009d48
        [wtforms.validators.Required()]
Pierre-Yves Chibon 009d48
    )
Pierre-Yves Chibon 009d48
    room = wtforms.TextField(
Pierre-Yves Chibon 009d48
        'Room *',
Pierre-Yves Chibon 009d48
        [wtforms.validators.Required()]
Pierre-Yves Chibon 009d48
    )
Pierre-Yves Chibon 009d48
    nick = wtforms.TextField(
Pierre-Yves Chibon 009d48
        'Nick *',
Pierre-Yves Chibon 009d48
        [wtforms.validators.Required()]
Pierre-Yves Chibon 009d48
    )
Pierre-Yves Chibon 009d48
    nick_pass = wtforms.TextField(
Pierre-Yves Chibon 009d48
        'Nickserv Password *',
Pierre-Yves Chibon 009d48
        [wtforms.validators.Required()]
Pierre-Yves Chibon 009d48
    )
Pierre-Yves Chibon 009d48
Pierre-Yves Chibon 009d48
    active = wtforms.BooleanField(
Pierre-Yves Chibon 009d48
        'Acive',
Pierre-Yves Chibon 009d48
        [wtforms.validators.Required()]
Pierre-Yves Chibon 009d48
    )
Pierre-Yves Chibon 009d48
    join = wtforms.BooleanField(
Pierre-Yves Chibon 009d48
        'Message Without Join',
Pierre-Yves Chibon 009d48
        [wtforms.validators.Required()]
Pierre-Yves Chibon 009d48
    )
Pierre-Yves Chibon 009d48
    ssl = wtforms.BooleanField(
Pierre-Yves Chibon 009d48
        'Use SSL',
Pierre-Yves Chibon 009d48
        [wtforms.validators.Required()]
Pierre-Yves Chibon 009d48
    )
Pierre-Yves Chibon 009d48
Pierre-Yves Chibon 009d48
Pierre-Yves Chibon 009d48
class Hook(BaseHook):
Pierre-Yves Chibon 009d48
    ''' IRC hooks. '''
Pierre-Yves Chibon 009d48
Pierre-Yves Chibon 009d48
    name = 'IRC'
Pierre-Yves Chibon d66f9b
    form = IrcForm
Pierre-Yves Chibon 009d48
    form_fields = [
Pierre-Yves Chibon 009d48
        'server', 'port', 'room', 'nick', 'nick_pass', 'active', 'join',
Pierre-Yves Chibon 009d48
        'ssl'
Pierre-Yves Chibon 009d48
    ]