xref: /titanic_44/usr/src/tools/onbld/Scm/Version.py (revision 2b4a78020b9c38d1b95e2f3fefa6d6e4be382d1f)
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
21'''
22Minimal amount of code to check the version of Mercurial in use
23against our expectations.
24'''
25
26#
27# It is important that this rely on as little of Mercurial as is possible.
28#
29
30from mercurial import version
31
32
33class VersionMismatch(Exception):
34    "Exception used to indicate a mis-match between Scm tools and Mercurial"
35    pass
36
37#
38# List of versions that are explicitly acceptable to us
39#
40GOOD_VERSIONS = ['1.0', '1.0.1', '1.0.2']
41
42
43def check_version():
44    '''Check that we're running on a suitable version of Mercurial'''
45
46    def versionstring(versions):
47        '''return the list, versions, as a vaguely grammatical string'''
48        if len(versions) > 1:
49            return "%s or %s" % (', '.join(versions[0:-1]), versions[-1])
50        else:
51            return versions[0]
52
53    if version.get_version() not in GOOD_VERSIONS:
54        raise VersionMismatch("Scm expects Mercurial version %s, "
55                              "actual version is %s" %
56                              (versionstring(GOOD_VERSIONS),
57                               version.get_version()))
58