NEWS: fix minor typo
[buildbot.git] / contrib / svnpoller.py
blobfd2a68a387ef985638ddd8d052b6b9c56a9bd471
1 #!/usr/bin/python
2 """
3 svn.py
4 Script for BuildBot to monitor a remote Subversion repository.
5 Copyright (C) 2006 John Pye
6 """
7 # This script is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License, or (at your option) any later version.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 # USA
22 import commands
23 import xml.dom.minidom
24 import ConfigParser
25 import os.path
26 import codecs
28 # change these settings to match your project
29 svnurl = "https://pse.cheme.cmu.edu/svn/ascend/code/trunk"
30 statefilename = "~/changemonitor/config.ini"
31 buildmaster = "buildbot.example.org:9989" # connects to a PBChangeSource
33 xml1 = commands.getoutput("svn log --non-interactive --verbose --xml --limit=1 " + svnurl)
34 #print "XML\n-----------\n"+xml1+"\n\n"
36 try:
37 doc = xml.dom.minidom.parseString(xml1)
38 el = doc.getElementsByTagName("logentry")[0]
39 revision = el.getAttribute("revision")
40 author = "".join([t.data for t in el.getElementsByTagName("author")[0].childNodes])
41 comments = "".join([t.data for t in el.getElementsByTagName("msg")[0].childNodes])
43 pathlist = el.getElementsByTagName("paths")[0]
44 paths = []
45 for p in pathlist.getElementsByTagName("path"):
46 paths.append("".join([t.data for t in p.childNodes]))
47 #print "PATHS"
48 #print paths
49 except xml.parsers.expat.ExpatError, e:
50 print "FAILED TO PARSE 'svn log' XML:"
51 print str(e)
52 print "----"
53 print "RECEIVED TEXT:"
54 print xml1
55 import sys
56 sys.exit(1)
58 fname = statefilename
59 fname = os.path.expanduser(fname)
60 ini = ConfigParser.SafeConfigParser()
62 try:
63 ini.read(fname)
64 except:
65 print "Creating changemonitor config.ini:",fname
66 ini.add_section("CurrentRevision")
67 ini.set("CurrentRevision",-1)
69 try:
70 lastrevision = ini.get("CurrentRevision","changeset")
71 except ConfigParser.NoOptionError:
72 print "NO OPTION FOUND"
73 lastrevision = -1
74 except ConfigParser.NoSectionError:
75 print "NO SECTION FOUND"
76 lastrevision = -1
78 if lastrevision != revision:
80 #comments = codecs.encodings.unicode_escape.encode(comments)
81 cmd = "buildbot sendchange --master="+buildmaster+" --branch=trunk --revision=\""+revision+"\" --username=\""+author+"\" --comments=\""+comments+"\" "+" ".join(paths)
83 #print cmd
84 res = commands.getoutput(cmd)
86 print "SUBMITTING NEW REVISION",revision
87 if not ini.has_section("CurrentRevision"):
88 ini.add_section("CurrentRevision")
89 try:
90 ini.set("CurrentRevision","changeset",revision)
91 f = open(fname,"w")
92 ini.write(f)
93 #print "WROTE CHANGES TO",fname
94 except:
95 print "FAILED TO RECORD INI FILE"