aboutsummaryrefslogtreecommitdiffstats
path: root/misc/git-post-commit.py
blob: 07eeb607de4191dd48dd2d33a5e54d441efa8e0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Simple script to send messages to an IRC channel
in Fire and Forget mode (non persistent connection)

Usage: git-post-commit <server[:port]> <nickname> <channel>

Read lines one by one on the standard input and print them in
in the channel
"""

import irclib
import sys

class IRCFire(irclib.SimpleIRCClient):
    def __init__(self, target):
        irclib.SimpleIRCClient.__init__(self)
        self.target = target

    def on_welcome(self, connection, event):
        connection.join(self.target)

    def on_join(self, connection, event):
        for line in sys.stdin: 
            self.connection.privmsg(self.target, line)
	self.connection.quit("Commit sent")

    def on_disconnect(self, connection, event):
        sys.exit(0)

def main():
    if len(sys.argv) != 4:
        print "Usage: " + sys.argv[0] + " <server[:port]> <nickname> <channel>"
        sys.exit(1)

    s = sys.argv[1].split(":", 1)
    server = s[0]
    if len(s) == 2:
        try:
            port = int(s[1])
        except ValueError:
            print "Error: Erroneous port."
            sys.exit(1)
    else:
        port = 6667
    nickname = sys.argv[2]
    channel = sys.argv[3]

    c = IRCFire(channel)
    try:
        c.connect(server, port, nickname)
    except irclib.ServerConnectionError, x:
        print x
        sys.exit(1)
    c.start()

if __name__ == "__main__":
    main()