Another hook test.
[irker.git] / filter-test.py
1 #!/usr/bin/env python
2 #
3 # Test hook to launch an irker instance (if it doesn't already exist)
4 # just before shipping the notification. We start it in in another terminal
5 # so you can watch the debug messages. Probably only of interest only to
6 # developers
7 #
8 # To use it, set up irkerhook.py to file on each commit.
9 # Then set the filtercmd variable in your repo config as follows:
10
11 # [irker]
12 #       filtercmd = filter-test.py
13 #
14 # This is rather antisocial - imagine thousands of irkerds holding open
15 # connections to IRCDs.  It's better to go through an instance running
16 # at your forge or set up for shared use by your intranet administrator.
17
18 import os, sys, json, subprocess, time
19 metadata = json.loads(sys.argv[1])
20
21 ps = subprocess.Popen("ps -U %s uh" % os.getenv("LOGNAME"),
22                       shell=True,
23                       stdout=subprocess.PIPE)
24 data = ps.stdout.read()
25 irkerd_count = len([x for x in data.split("\n") if x.find("irkerd") != -1])
26
27 if irkerd_count:
28     print "Using running irkerd..."
29 else:
30     print "Launching new irkerd..."
31     os.system("gnome-terminal --title 'irkerd' -e 'irkerd -d 2' &")
32
33 time.sleep(0.1) # Avoid a race condition
34
35 print json.dumps(metadata)
36 # end