Bug 1286799 - mozboot: Abstract version checking. r=gps

Move version parsing to a helper method so it can be used
for more than one executable.

MozReview-Commit-ID: 4gOgdgYFbFx

--HG--
extra : rebase_source : 944f562c0d5a6a105a0c27af6f4d7dfc214f3c01
This commit is contained in:
Ralph Giles 2016-11-15 14:31:59 -08:00
Родитель b00d62db25
Коммит 9416a38fd9
1 изменённых файлов: 25 добавлений и 7 удалений

Просмотреть файл

@ -321,6 +321,29 @@ class BaseBootstrapper(object):
This should be defined in child classes.
"""
def _parse_version(self, path, name=None):
'''Execute the given path, returning the version.
Invokes the path argument with the --version switch
and returns a LooseVersion representing the output
if successful. If not, returns None.
An optional name argument gives the expected program
name returned as part of the version string, if it's
different from the basename of the executable.
'''
if not name:
name = os.path.basename(path)
info = self.check_output([path, '--version'],
stderr=subprocess.STDOUT)
match = re.search(name + ' ([a-z0-9\.]+)', info)
if not match:
print('ERROR! Unable to identify %s version.' % name)
return None
return LooseVersion(match.group(1))
def _hgplain_env(self):
""" Returns a copy of the current environment updated with the HGPLAIN
environment variable.
@ -399,15 +422,10 @@ class BaseBootstrapper(object):
assert python
info = self.check_output([python, '--version'],
stderr=subprocess.STDOUT)
match = re.search('Python ([a-z0-9\.]+)', info)
if not match:
print('ERROR Unable to identify Python version.')
our = self._parse_version(python, 'Python')
if not our:
return False, None
our = LooseVersion(match.group(1))
return our >= MODERN_PYTHON_VERSION, our
def ensure_python_modern(self):