-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgit-post-update
executable file
·37 lines (33 loc) · 1.1 KB
/
git-post-update
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
#!/usr/bin/env python2
import sys
import subprocess
import telnetlib
GITW_HOST = "192.168.101.196"
GITW_PORT = 9988
# This is a post-update script for git to send a proper string
# to a gitw server. The server will then begin to checkout, build and
# test the newest commit of the project.
gitStdout = ""
cmd = 'git --no-pager log -1 --pretty=format:"%h|%an -- %s"'
try:
proc = subprocess.Popen(cmd, shell=True, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
return_code = proc.wait()
stderr = proc.stderr.read()
if len(stderr) > 1:
sys.stderr.write(stderr)
exit(-2)
gitStdout = proc.stdout.read()
except Exception,e:
sys.stderr.write("Error executing git log: " + str(e) + "\n")
exit(-4)
else:
project = "test"
print "Building gitw project '%s' ... '%s'" % (project,gitStdout)
try:
message = str(project + "|" + gitStdout + "\r\n")
client = telnetlib.Telnet(GITW_HOST, GITW_PORT)
client.write(message)
client.close()
except Exception, e:
sys.stderr.write("Error communicating with gitw server: " + str(e) + "\n")
exit(0)