3 # Copyright (C) 2006 John Pye
4 # Copyright (C) 2012 University of Szeged
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.
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.
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
21 from optparse import OptionParser
25 import xml.dom.minidom
30 def getLatestSVNRevision(SVNServer):
31 p = subprocess.Popen(["svn", "log", "--non-interactive", "--verbose", "--xml", "--limit=1", SVNServer], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
32 response = p.communicate()[0]
34 print "Can't connect to host: %s, return code %s " % (SVNServer, p.returncode)
39 doc = xml.dom.minidom.parseString(response)
40 el = doc.getElementsByTagName("logentry")[0]
41 return el.getAttribute("revision")
42 except xml.parsers.expat.ExpatError, e:
43 print "FAILED TO PARSE 'svn log' XML:"
46 print "RECEIVED TEXT:"
51 def waitForSVNRevision(SVNServer, revision):
52 if not revision or not revision.isdigit():
53 latestRevision = int(getLatestSVNRevision(SVNServer))
54 print "Latest SVN revision on %s is r%d. Don't wait, because revision argument isn't a valid SVN revision." % (SVNServer, latestRevision)
57 revision = int(revision)
59 latestRevision = int(getLatestSVNRevision(SVNServer))
60 if latestRevision == -1:
61 print "%s SVN server is unreachable. Sleeping for 60 seconds." % (SVNServer)
63 elif latestRevision < revision:
64 print "Latest SVN revision on %s is r%d, but we are waiting for r%d. Sleeping for 5 seconds." % (SVNServer, latestRevision, revision)
67 print "Latest SVN revision on %s is r%d, which is newer or equal than r%d." % (SVNServer, latestRevision, revision)
71 if __name__ == '__main__':
72 parser = OptionParser()
73 parser.add_option("-r", "--revision", dest="revision", help="SVN revision number")
74 parser.add_option("-s", "--svn-server", dest="SVNServer", help="SVN server")
75 options, args = parser.parse_args()
76 waitForSVNRevision(options.SVNServer, options.revision)