-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsubversion-post-commit.example
executable file
·61 lines (52 loc) · 1.71 KB
/
subversion-post-commit.example
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python
import sys
import subprocess
import telnetlib
from xml.dom.minidom import parseString
#if sys.argv[1] != "TEST":
# exit(0)
GITW_HOST = "192.168.101.196"
GITW_PORT = 9988
# This is a post-commit script for subversion 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.
# Command line arguments for post-commit script:
# argv[1] - repository name
# argv[2] - revision number
svnStdout = ""
cmd = 'svn log -v -r "%s" file:///data/svn/ --xml' % sys.argv[2]
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)
svnStdout = proc.stdout.read()
except Exception,e:
sys.stderr.write("Error executing svn log: " + str(e) + "\n")
exit(-4)
else:
dom = parseString(svnStdout)
tags = dom.getElementsByTagName('paths')
msg = dom.getElementsByTagName('msg')[0].childNodes[0].nodeValue
project = ""
if len(tags) < 1:
print "No tags found"
exit(0)
for child in tags[0].childNodes:
if child.nodeName != 'path':
continue
project = child.childNodes[0].nodeValue
# remove filename
idx = project.rindex("/")
project = project[:idx]
print "Building gitw project '%s'" % project
try:
message = str(project + "|" + sys.argv[2] + "|" + msg + "\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)