wait-for-SVN-server.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/usr/bin/env python
  2. #
  3. # Copyright (C) 2006 John Pye
  4. # Copyright (C) 2012 University of Szeged
  5. #
  6. # This script is free software; you can redistribute it and/or
  7. # modify it under the terms of the GNU Lesser General Public
  8. # License as published by the Free Software Foundation; either
  9. # version 2.1 of the License, or (at your option) any later version.
  10. #
  11. # This library is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. # Lesser General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU Lesser General Public
  17. # License along with this library; if not, write to the Free Software
  18. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  19. # USA
  20. from optparse import OptionParser
  21. import exceptions
  22. import sys
  23. import time
  24. import xml.dom.minidom
  25. import os
  26. import subprocess
  27. def getLatestSVNRevision(SVNServer):
  28. try:
  29. p = subprocess.Popen(["svn", "log", "--non-interactive", "--verbose", "--xml", "--limit=1", SVNServer], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
  30. response = p.communicate()[0]
  31. doc = xml.dom.minidom.parseString(response)
  32. el = doc.getElementsByTagName("logentry")[0]
  33. return el.getAttribute("revision")
  34. except xml.parsers.expat.ExpatError, e:
  35. print "FAILED TO PARSE 'svn log' XML:"
  36. print str(e)
  37. print "----"
  38. print "RECEIVED TEXT:"
  39. print response
  40. sys.exit(1)
  41. def waitForSVNRevision(SVNServer, revision):
  42. if not revision or not revision.isdigit():
  43. latestRevision = int(getLatestSVNRevision(SVNServer))
  44. print "Latest SVN revision on %s is r%d. Don't wait, because revision argument isn't a valid SVN revision." % (SVNServer, latestRevision)
  45. return
  46. revision = int(revision)
  47. while True:
  48. latestRevision = int(getLatestSVNRevision(SVNServer))
  49. if latestRevision < revision:
  50. print "Latest SVN revision on %s is r%d, but we are waiting for r%d. Sleeping for 5 seconds." % (SVNServer, latestRevision, revision)
  51. time.sleep(5)
  52. else:
  53. print "Latest SVN revision on %s is r%d, which is newer or equal than r%d." % (SVNServer, latestRevision, revision)
  54. break
  55. if __name__ == '__main__':
  56. parser = OptionParser()
  57. parser.add_option("-r", "--revision", dest="revision", help="SVN revision number")
  58. parser.add_option("-s", "--svn-server", dest="SVNServer", help="SVN server")
  59. options, args = parser.parse_args()
  60. waitForSVNRevision(options.SVNServer, options.revision)