Commit 8e897267 authored by Michal Čihař's avatar Michal Čihař

Share most of the code for is_supported for VCS

Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 8564fb5b
...@@ -64,6 +64,12 @@ class Repository(object): ...@@ -64,6 +64,12 @@ class Repository(object):
_cmd_push = None _cmd_push = None
_cmd_status = ['status'] _cmd_status = ['status']
name = None
req_version = None
_is_supported = None
_version = None
def __init__(self, path): def __init__(self, path):
self.path = path self.path = path
self.last_output = '' self.last_output = ''
...@@ -221,14 +227,39 @@ class Repository(object): ...@@ -221,14 +227,39 @@ class Repository(object):
""" """
Checks whether this VCS backend is supported. Checks whether this VCS backend is supported.
""" """
if cls._is_supported is not None:
return cls._is_supported
try: try:
cls.get_version() version = cls.get_version()
return True
except OSError: except OSError:
cls._is_supported = False
return False return False
if cls.req_version is None:
cls._is_supported = True
elif LooseVersion(version) >= cls.req_version:
cls._is_supported = True
else:
cls._is_supported = False
add_configuration_error(
cls.name.lower(),
'{0} version is too old, please upgrade to {1}.'.format(
cls.name,
cls.req_version
)
)
return cls._is_supported
@classmethod @classmethod
def get_version(cls): def get_version(cls):
"""
Cached getting of version.
"""
if cls._version is None:
cls._version = cls._get_version()
return cls._version
@classmethod
def _get_version(cls):
""" """
Returns VCS program version. Returns VCS program version.
""" """
...@@ -295,6 +326,8 @@ class GitRepository(Repository): ...@@ -295,6 +326,8 @@ class GitRepository(Repository):
] ]
_cmd_update_remote = ['remote', 'update', 'origin'] _cmd_update_remote = ['remote', 'update', 'origin']
_cmd_push = ['push', 'origin'] _cmd_push = ['push', 'origin']
name = 'Git'
req_version = '1.6'
def is_valid(self): def is_valid(self):
''' '''
...@@ -446,18 +479,7 @@ class GitRepository(Repository): ...@@ -446,18 +479,7 @@ class GitRepository(Repository):
return self._log_revisions('origin/{0}..'.format(branch)) != '' return self._log_revisions('origin/{0}..'.format(branch)) != ''
@classmethod @classmethod
def is_supported(cls): def _get_version(cls):
"""
Checks whether this VCS backend is supported.
"""
try:
version = cls.get_version()
return LooseVersion(version) >= '1.6'
except OSError:
return False
@classmethod
def get_version(cls):
""" """
Returns VCS program version. Returns VCS program version.
""" """
...@@ -564,6 +586,8 @@ class HgRepository(Repository): ...@@ -564,6 +586,8 @@ class HgRepository(Repository):
] ]
_cmd_update_remote = ['pull'] _cmd_update_remote = ['pull']
_cmd_push = ['push'] _cmd_push = ['push']
name = 'Mercurial'
req_version = '2.8'
VERSION_RE = re.compile(r'.*\(version ([^)]*)\).*') VERSION_RE = re.compile(r'.*\(version ([^)]*)\).*')
...@@ -759,24 +783,7 @@ class HgRepository(Repository): ...@@ -759,24 +783,7 @@ class HgRepository(Repository):
return self.execute(['log', '-r', 'not public()']) != '' return self.execute(['log', '-r', 'not public()']) != ''
@classmethod @classmethod
def is_supported(cls): def _get_version(cls):
"""
Checks whether this VCS backend is supported.
"""
try:
version = cls.get_version()
if LooseVersion(version) >= '3.8':
return True
add_configuration_error(
'mercurial',
'Mercurial version is too old, please upgrade to 2.8.'
)
return False
except OSError:
return False
@classmethod
def get_version(cls):
""" """
Returns VCS program version. Returns VCS program version.
""" """
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment