Files
tubestation/python/mozversioncontrol/mozversioncontrol/__init__.py
Gregory Szorc c0668016dd Bug 1128586 - Properly look for Mercurial version; r=RyanVM
`mercurial version` doesn't always print the version number. `mercurial
--version` does. Use the latter.
2015-04-27 10:43:25 -07:00

25 lines
697 B
Python

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this,
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from __future__ import unicode_literals
import os
import re
import subprocess
from distutils.version import LooseVersion
def get_hg_version(hg):
"""Obtain the version of the Mercurial client."""
env = os.environ.copy()
env[b'HGPLAIN'] = b'1'
info = subprocess.check_output([hg, '--version'], env=env)
match = re.search('version ([^\+\)]+)', info)
if not match:
raise Exception('Unable to identify Mercurial version.')
return LooseVersion(match.group(1))