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