#!/usr/bin/python
#
# Used to extract the revision number of a file by processing the output of the svn info command
# This script is meant to be called from other python scripts
#
# Example usage:
#
# ./GetSvnRevision.py <filename>
# return the revision number
import sys, os, subprocess
def get_svn_revision(file_name):
# run the svn command
svnVersion = subprocess.check_output(['svn', 'info', file_name], shell=False)
# Look for the string Last Changed Rev:
position = svnVersion.find('Last Changed Rev: ');
if position != -1:
# get the number string between position + len(Last Changed Rev: )
# and the next return character
position += len('Last Changed Rev: ')
endOfLinePos = svnVersion.find('\r', position)
if endOfLinePos != -1:
# extract the string and return it
revNumber = svnVersion[position:endOfLinePos]
return int(revNumber)
else:
endOfLinePos = svnVersion.find('\n', position)
if endOfLinePos != -1:
# extract the string and return it
revNumber = svnVersion[position:endOfLinePos]
return int(revNumber)
return -1
if __name__ == "__main__":
testVal = get_svn_revision(sys.argv[1])
print testVal