1*cdf0c1d5Smjnelson# 2*cdf0c1d5Smjnelson# This program is free software; you can redistribute it and/or modify 3*cdf0c1d5Smjnelson# it under the terms of the GNU General Public License version 2 4*cdf0c1d5Smjnelson# as published by the Free Software Foundation. 5*cdf0c1d5Smjnelson# 6*cdf0c1d5Smjnelson# This program is distributed in the hope that it will be useful, 7*cdf0c1d5Smjnelson# but WITHOUT ANY WARRANTY; without even the implied warranty of 8*cdf0c1d5Smjnelson# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 9*cdf0c1d5Smjnelson# GNU General Public License for more details. 10*cdf0c1d5Smjnelson# 11*cdf0c1d5Smjnelson# You should have received a copy of the GNU General Public License 12*cdf0c1d5Smjnelson# along with this program; if not, write to the Free Software 13*cdf0c1d5Smjnelson# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 14*cdf0c1d5Smjnelson# 15*cdf0c1d5Smjnelson 16*cdf0c1d5Smjnelson# 17*cdf0c1d5Smjnelson# Copyright 2008 Sun Microsystems, Inc. All rights reserved. 18*cdf0c1d5Smjnelson# Use is subject to license terms. 19*cdf0c1d5Smjnelson# 20*cdf0c1d5Smjnelson# ident "%Z%%M% %I% %E% SMI" 21*cdf0c1d5Smjnelson 22*cdf0c1d5Smjnelson''' 23*cdf0c1d5SmjnelsonMinimal amount of code to check the version of Mercurial in use 24*cdf0c1d5Smjnelsonagainst our expectations. 25*cdf0c1d5Smjnelson''' 26*cdf0c1d5Smjnelson 27*cdf0c1d5Smjnelson# 28*cdf0c1d5Smjnelson# It is important that this rely on as little of Mercurial as is possible. 29*cdf0c1d5Smjnelson# 30*cdf0c1d5Smjnelson 31*cdf0c1d5Smjnelsonfrom mercurial import version 32*cdf0c1d5Smjnelson 33*cdf0c1d5Smjnelson 34*cdf0c1d5Smjnelsonclass VersionMismatch(Exception): 35*cdf0c1d5Smjnelson "Exception used to indicate a mis-match between Scm tools and Mercurial" 36*cdf0c1d5Smjnelson pass 37*cdf0c1d5Smjnelson 38*cdf0c1d5Smjnelson# 39*cdf0c1d5Smjnelson# List of versions that are explicitly acceptable to us 40*cdf0c1d5Smjnelson# 41*cdf0c1d5SmjnelsonGOOD_VERSIONS = ['1.0'] 42*cdf0c1d5Smjnelson 43*cdf0c1d5Smjnelson 44*cdf0c1d5Smjnelsondef check_version(): 45*cdf0c1d5Smjnelson '''Check that we're running on a suitable version of Mercurial''' 46*cdf0c1d5Smjnelson 47*cdf0c1d5Smjnelson def versionstring(versions): 48*cdf0c1d5Smjnelson '''return the list, versions, as a vaguely grammatical string''' 49*cdf0c1d5Smjnelson if len(versions) > 1: 50*cdf0c1d5Smjnelson return "%s or %s" % (', '.join(versions[0:-1]), versions[-1]) 51*cdf0c1d5Smjnelson else: 52*cdf0c1d5Smjnelson return versions[0] 53*cdf0c1d5Smjnelson 54*cdf0c1d5Smjnelson if version.get_version() not in GOOD_VERSIONS: 55*cdf0c1d5Smjnelson raise VersionMismatch("Scm expects Mercurial version %s, " 56*cdf0c1d5Smjnelson "actual version is %s" % 57*cdf0c1d5Smjnelson (versionstring(GOOD_VERSIONS), 58*cdf0c1d5Smjnelson version.get_version())) 59