Changelog update.
[debian_buildbot.git] / master / contrib / svnpoller.py
blobdeec346ac44272f8d23b3aa02f2308ea09d23084
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
27 # change these settings to match your project
28 svnurl = "https://pse.cheme.cmu.edu/svn/ascend/code/trunk"
29 statefilename = "~/changemonitor/config.ini"
30 buildmaster = "buildbot.example.org:9989" # connects to a PBChangeSource
32 xml1 = commands.getoutput(
33 "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(
41 "author")[0].childNodes])
42 comments = "".join([t.data for t in el.getElementsByTagName(
43 "msg")[0].childNodes])
45 pathlist = el.getElementsByTagName("paths")[0]
46 paths = []
47 for p in pathlist.getElementsByTagName("path"):
48 paths.append("".join([t.data for t in p.childNodes]))
49 #print "PATHS"
50 #print paths
51 except xml.parsers.expat.ExpatError, e:
52 print "FAILED TO PARSE 'svn log' XML:"
53 print str(e)
54 print "----"
55 print "RECEIVED TEXT:"
56 print xml1
57 import sys
58 sys.exit(1)
60 fname = statefilename
61 fname = os.path.expanduser(fname)
62 ini = ConfigParser.SafeConfigParser()
64 try:
65 ini.read(fname)
66 except:
67 print "Creating changemonitor config.ini:", fname
68 ini.add_section("CurrentRevision")
69 ini.set("CurrentRevision", -1)
71 try:
72 lastrevision = ini.get("CurrentRevision", "changeset")
73 except ConfigParser.NoOptionError:
74 print "NO OPTION FOUND"
75 lastrevision = -1
76 except ConfigParser.NoSectionError:
77 print "NO SECTION FOUND"
78 lastrevision = -1
80 if lastrevision != revision:
82 #comments = codecs.encodings.unicode_escape.encode(comments)
83 cmd = "buildbot sendchange --master="+buildmaster+" --branch=trunk \
84 --revision=\""+revision+"\" --username=\""+author+"\" --comments=\""+\
85 comments+"\" "+" ".join(paths)
87 #print cmd
88 res = commands.getoutput(cmd)
90 print "SUBMITTING NEW REVISION", revision
91 if not ini.has_section("CurrentRevision"):
92 ini.add_section("CurrentRevision")
93 try:
94 ini.set("CurrentRevision", "changeset", revision)
95 f = open(fname, "w")
96 ini.write(f)
97 #print "WROTE CHANGES TO",fname
98 except:
99 print "FAILED TO RECORD INI FILE"