def check_tool_version(tool, required_version, blacklisted_versions=None, binary=False):
    """
    This will ensure that the required_version of `tool` is at least `required_version`.
    :param str tool: The tool under review
    :param str required_version: The version of the tool required by ProTECT
    :param list blacklisted_versions: Version of the tool blacklisted by ProTECT
    :param bool binary: Is the tool a binary
    :return: None
    """
    if binary:
        try:
            installed_version = subprocess.check_output([tool, '--version'],
                                                        stderr=subprocess.STDOUT)
        except OSError as err:
            if err.errno == errno.ENOENT:
                raise RuntimeError('Is %s installed as a binary and present on your $PATH?' % tool)
            else:
                raise
        installed_version = installed_version.rstrip()
    else:
        try:
            module = __import__(tool + '.version')
        except ImportError:
            raise RuntimeError('Is %s installed as a library, and is it accessible in the same '
                               'environment as ProTECT?' % tool)
        try:
            installed_version = getattr(module, 'version').version
        except AttributeError:
            raise RuntimeError('Does %s have a version.py?' % tool)

    if type(parse_version(installed_version)) == _LegacyVersion:
        print('Detecting that the installed version of "%s"(%s) is probably based off a git commit '
              'and assuming this build is for testing purposes.  If this is not the case, please '
              'try again with a valid version of "%s".' % (tool, installed_version, tool))
    elif parse_version(installed_version) < parse_version(required_version):
        raise RuntimeError('%s was detected to be version (%s) but ProTECT requires (%s)' %
                           (tool, installed_version, required_version))
    if blacklisted_versions is not None:
        if parse_version(installed_version) in [parse_version(v) for v in blacklisted_versions]:
            raise RuntimeError('The version of %s was detected to be on the a blacklist (%s).' %
                               (tool, installed_version))
def check_tool_version ( tool , required_version , blacklisted_versions = None , binary = False ) : if binary : try : installed_version = subprocess . check_output ( [ tool , '--version' ] , stderr = subprocess . STDOUT ) except OSError as err : if err . errno == errno . ENOENT : raise RuntimeError ( 'Is %s installed as a binary and present on your $PATH?' % tool ) else : raise installed_version = installed_version . rstrip ( ) else : try : module = __import__ ( tool + '.version' ) except ImportError : raise RuntimeError ( 'Is %s installed as a library, and is it accessible in the same ' 'environment as ProTECT?' % tool ) try : installed_version = getattr ( module , 'version' ) . version except AttributeError : raise RuntimeError ( 'Does %s have a version.py?' % tool ) if type ( parse_version ( installed_version ) ) == _LegacyVersion : print ( 'Detecting that the installed version of "%s"(%s) is probably based off a git commit ' 'and assuming this build is for testing purposes.  If this is not the case, please ' 'try again with a valid version of "%s".' % ( tool , installed_version , tool ) ) elif parse_version ( installed_version ) < parse_version ( required_version ) : raise RuntimeError ( '%s was detected to be version (%s) but ProTECT requires (%s)' % ( tool , installed_version , required_version ) ) if blacklisted_versions is not None : if parse_version ( installed_version ) in [ parse_version ( v ) for v in blacklisted_versions ] : raise RuntimeError ( 'The version of %s was detected to be on the a blacklist (%s).' % ( tool , installed_version ) )
This will ensure that the required_version of `tool` is at least `required_version`.
    :param str tool: The tool under review
    :param str required_version: The version of the tool required by ProTECT
    :param list blacklisted_versions: Version of the tool blacklisted by ProTECT
    :param bool binary: Is the tool a binary
    :return: None