def openssl_rehash(self, certdir): """ Compatibly run c_rehash (on old openssl versions) or openssl rehash (on new ones). Prefers openssl rehash, because openssl on versions where the rehash command doesn't exist, also doesn't correctly set the return code. Instead, we parse the output of `openssl version` and try to figure out if we have a new enough version to unconditionally run rehash. """ try: openssl_version = check_output(['/usr/bin/openssl', 'version' ]).decode('utf-8').strip() except subprocess.CalledProcessError as e: raise ValueError(e.output.decode('utf-8').rstrip()) rehash_available = LegacyVersion( openssl_version.split(' ')[1]) >= LegacyVersion('1.1.0') if rehash_available: cmd = ['/usr/bin/openssl', 'rehash', certdir] else: cmd = ['/usr/bin/c_rehash', certdir] self.log.debug("nss cmd: %s", format_cmd_list(cmd)) try: check_output(cmd, stderr=subprocess.STDOUT) except subprocess.CalledProcessError as e: raise ValueError(e.output.decode('utf-8').rstrip())
def msvc14_gen_lib_options(*args, **kwargs): """ Patched "distutils._msvccompiler.gen_lib_options" for fix compatibility between "numpy.distutils" and "distutils._msvccompiler" (for Numpy < 1.11.2) """ if "numpy.distutils" in sys.modules: import numpy as np if LegacyVersion(np.__version__) < LegacyVersion('1.11.2'): return np.distutils.ccompiler.gen_lib_options(*args, **kwargs) return monkey.unpatched['msvc14_gen_lib_options'](*args, **kwargs)
def msvc14_gen_lib_options(*args, **kwargs): """ Patched "distutils._msvccompiler.gen_lib_options" for fix compatibility between "numpy.distutils" and "distutils._msvccompiler" (for Numpy < 1.11.2) """ if "numpy.distutils" in sys.modules: import numpy as np from pkg_resources.extern.packaging.version import LegacyVersion if LegacyVersion(np.__version__) < LegacyVersion('1.11.2'): return np.distutils.ccompiler.gen_lib_options(*args, **kwargs) return get_unpatched(msvc14_gen_lib_options)(*args, **kwargs)
def ds_is_related(relation, *ver, instance=None): """ Return a result of a comparison between the current version of ns-slapd and a provided version. """ ops = {'older': operator.lt, 'newer': operator.ge} if instance is None: ds_ver = get_ds_version() else: ds_ver = get_ds_version(instance.ds_paths) if len(ver) > 1: for cmp_ver in ver: if cmp_ver.startswith(ds_ver[:3]): return ops[relation](LegacyVersion(ds_ver), LegacyVersion(cmp_ver)) else: return ops[relation](LegacyVersion(ds_ver), LegacyVersion(ver[0]))