/master/contrib/svnpoller.py

https://gitlab.com/murder187ss/buildbot · Python · 99 lines · 60 code · 12 blank · 27 comment · 15 complexity · 0394b7e67c764b4dbcd20b05eba958e0 MD5 · raw file

  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.
  11. #
  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.
  16. #
  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
  21. import ConfigParser
  22. import commands
  23. import os.path
  24. import xml.dom.minidom
  25. # change these settings to match your project
  26. svnurl = "https://pse.cheme.cmu.edu/svn/ascend/code/trunk"
  27. statefilename = "~/changemonitor/config.ini"
  28. buildmaster = "buildbot.example.org:9989" # connects to a PBChangeSource
  29. xml1 = commands.getoutput(
  30. "svn log --non-interactive --verbose --xml --limit=1 " + svnurl)
  31. # print "XML\n-----------\n"+xml1+"\n\n"
  32. try:
  33. doc = xml.dom.minidom.parseString(xml1)
  34. el = doc.getElementsByTagName("logentry")[0]
  35. revision = el.getAttribute("revision")
  36. author = "".join([t.data for t in el.getElementsByTagName(
  37. "author")[0].childNodes])
  38. comments = "".join([t.data for t in el.getElementsByTagName(
  39. "msg")[0].childNodes])
  40. pathlist = el.getElementsByTagName("paths")[0]
  41. paths = []
  42. for p in pathlist.getElementsByTagName("path"):
  43. paths.append("".join([t.data for t in p.childNodes]))
  44. # print "PATHS"
  45. # print paths
  46. except xml.parsers.expat.ExpatError, e:
  47. print "FAILED TO PARSE 'svn log' XML:"
  48. print str(e)
  49. print "----"
  50. print "RECEIVED TEXT:"
  51. print xml1
  52. import sys
  53. sys.exit(1)
  54. fname = statefilename
  55. fname = os.path.expanduser(fname)
  56. ini = ConfigParser.SafeConfigParser()
  57. try:
  58. ini.read(fname)
  59. except Exception:
  60. print "Creating changemonitor config.ini:", fname
  61. ini.add_section("CurrentRevision")
  62. ini.set("CurrentRevision", -1)
  63. try:
  64. lastrevision = ini.get("CurrentRevision", "changeset")
  65. except ConfigParser.NoOptionError:
  66. print "NO OPTION FOUND"
  67. lastrevision = -1
  68. except ConfigParser.NoSectionError:
  69. print "NO SECTION FOUND"
  70. lastrevision = -1
  71. if lastrevision != revision:
  72. # comments = codecs.encodings.unicode_escape.encode(comments)
  73. cmd = "buildbot sendchange --master=" + buildmaster + " --branch=trunk \
  74. --revision=\"" + revision + "\" --username=\"" + author + "\" --vc=\"svn\" \
  75. --comments=\"" + comments + "\" " + " ".join(paths)
  76. # print cmd
  77. res = commands.getoutput(cmd)
  78. print "SUBMITTING NEW REVISION", revision
  79. if not ini.has_section("CurrentRevision"):
  80. ini.add_section("CurrentRevision")
  81. try:
  82. ini.set("CurrentRevision", "changeset", revision)
  83. f = open(fname, "w")
  84. ini.write(f)
  85. # print "WROTE CHANGES TO",fname
  86. except Exception:
  87. print "FAILED TO RECORD INI FILE"