PageRenderTime 21ms CodeModel.GetById 13ms app.highlight 5ms RepoModel.GetById 2ms app.codeStats 0ms

/tortoisehg/util/hgversion.py

https://bitbucket.org/tortoisehg/hgtk/
Python | 35 lines | 22 code | 3 blank | 10 comment | 7 complexity | e1fbc5cba2feb194ba7e2a74565e888c MD5 | raw file
 1# hgversion.py - Version information for Mercurial
 2#
 3# Copyright 2009 Steve Borho <steve@borho.org>
 4#
 5# This software may be used and distributed according to the terms of the
 6# GNU General Public License version 2, incorporated herein by reference.
 7
 8import re
 9
10try:
11    # post 1.1.2
12    from mercurial import util
13    hgversion = util.version()
14except AttributeError:
15    # <= 1.1.2
16    from mercurial import version
17    hgversion = version.get_version()
18
19def checkhgversion(v):
20    """range check the Mercurial version"""
21    reqver = ['1', '7']
22    v = v.split('+')[0]
23    if not v or v == 'unknown' or len(v) >= 12:
24        # can't make any intelligent decisions about unknown or hashes
25        return
26    vers = re.split(r'\.|-', v)[:2]
27    if vers == reqver or len(vers) < 2:
28        return
29    nextver = list(reqver)
30    nextver[1] = chr(ord(reqver[1])+1)
31    if vers == nextver:
32        return
33    return (('This version of TortoiseHg requires Mercurial '
34                       'version %s.n to %s.n, but finds %s') %
35                       ('.'.join(reqver), '.'.join(nextver), v))