diff options
| author | Zaran <zaran.krleza@gmail.com> | 2011-09-20 15:47:03 +0200 |
|---|---|---|
| committer | Zaran <zaran.krleza@gmail.com> | 2011-09-20 15:50:35 +0200 |
| commit | 0e314103b828bfa52d04d7c063353eba76ae7e9f (patch) | |
| tree | 46745baf964ce6a34b55d7b2051602c14f40b766 /misc/git-post-commit.py | |
| parent | 77fc54837df9f0d8067b677016d9fc96ad16c63e (diff) | |
| download | alias-0e314103b828bfa52d04d7c063353eba76ae7e9f.tar.gz | |
Add post-receive script
Depends on irclib (included).
The misc directory should be used for files related to project
maintenance or for configurations files (e.g. ejabberd.conf)
Diffstat (limited to 'misc/git-post-commit.py')
| -rwxr-xr-x | misc/git-post-commit.py | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/misc/git-post-commit.py b/misc/git-post-commit.py new file mode 100755 index 0000000..775fe3b --- /dev/null +++ b/misc/git-post-commit.py @@ -0,0 +1,57 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +""" +Simple script to send a message to an IRC channel +in Fire and Forget mode (non persistent connection) + +Usage: git-post-commit <server[:port]> <nickname> <channel> <message> +""" + +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): + self.connection.privmsg(self.target, sys.argv[4]) + self.connection.quit("Commit sent") + + def on_disconnect(self, connection, event): + sys.exit(0) + +def main(): + if len(sys.argv) != 5: + print "Usage: " + sys.argv[0] + " <server[:port]> <nickname> <channel> <message>" + 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() + + |
