An attempt at making irk clean up after itself.
[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. Intended to be used in the root
6 # directory of the irker repo. Probably only of interest only to irker
7 # developers
8 #
9 # To use this, set up irkerhook.py to fire on each commit.  Creating a
10 # .git/hooks/post-commit file containing the line "irkerhook.py"; be
11 # sure to make the opos-commit file executable.  Then set the
12 # filtercmd variable in your repo config as follows:
13
14 # [irker]
15 #       filtercmd = filter-test.py
16
17 import os, sys, json, subprocess, time
18 metadata = json.loads(sys.argv[1])
19
20 ps = subprocess.Popen("ps -U %s uh" % os.getenv("LOGNAME"),
21                       shell=True,
22                       stdout=subprocess.PIPE)
23 data = ps.stdout.read()
24 irkerd_count = len([x for x in data.split("\n") if x.find("irkerd") != -1])
25
26 if irkerd_count:
27     sys.stderr.write("Using a running irker instance...\n")
28 else:
29     sys.stderr.write("Launching a new irker instance...\n")
30     os.system("gnome-terminal --title 'irkerd' -e 'irkerd -d 2' &")
31
32 time.sleep(1.5) # Avoid a race condition
33
34 print json.dumps(metadata)
35 # end