File: filter-test.py

package info (click to toggle)
irker 2.18+dfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 528 kB
  • sloc: python: 3,229; xml: 1,357; makefile: 288; sh: 122
file content (35 lines) | stat: -rwxr-xr-x 1,229 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/env python
#
# Test hook to launch an irker instance (if it doesn't already exist)
# just before shipping the notification. We start it in in another terminal
# so you can watch the debug messages. Intended to be used in the root
# directory of the irker repo. Probably only of interest only to irker
# developers
#
# To use this, set up irkerhook.py to fire on each commit.  Creating a
# .git/hooks/post-commit file containing the line "irkerhook.py"; be
# sure to make the opos-commit file executable.  Then set the
# filtercmd variable in your repo config as follows:
# 
# [irker]
# 	filtercmd = filter-test.py

import os, sys, json, subprocess, time
metadata = json.loads(sys.argv[1])

ps = subprocess.Popen("ps -U %s uh" % os.getenv("LOGNAME"),
                      shell=True,
                      stdout=subprocess.PIPE)
data = ps.stdout.read()
irkerd_count = len([x for x in data.split("\n") if x.find("irkerd") != -1])

if irkerd_count:
    sys.stderr.write("Using a running irker instance...\n")
else:
    sys.stderr.write("Launching a new irker instance...\n")
    os.system("gnome-terminal --title 'irkerd' -e 'irkerd -d 2' &")

time.sleep(1.5)	# Avoid a race condition

print json.dumps(metadata)
# end