def check_c_extension(exc=None): """Check whether we can load the C Extension This function needs the location of the mysql_config tool to figure out the location of the MySQL Connector/C libraries. On Windows it would be the installation location of Connector/C. :param mysql_config: Location of the mysql_config tool :param exc: An ImportError exception """ if not MYSQL_CAPI: return if platform.system() == "Darwin": libpath_var = 'DYLD_LIBRARY_PATH' elif platform.system() == "Windows": libpath_var = 'PATH' else: libpath_var = 'LD_LIBRARY_PATH' if not os.path.exists(MYSQL_CAPI): LOGGER.error("MySQL Connector/C not available using '%s'", MYSQL_CAPI) if os.name == 'posix': if os.path.isdir(MYSQL_CAPI): mysql_config = os.path.join(MYSQL_CAPI, 'bin', 'mysql_config') else: mysql_config = MYSQL_CAPI lib_dir = get_mysql_config_info(mysql_config)['lib_dir'] elif os.path.isdir(MYSQL_CAPI): lib_dir = os.path.join(MYSQL_CAPI, 'lib') else: LOGGER.error("C Extension not supported on %s", os.name) sys.exit(1) error_msg = '' if not exc: try: import _mysql_connector except ImportError as exc: error_msg = str(exc).strip() else: assert (isinstance(exc, ImportError)) error_msg = str(exc).strip() if not error_msg: # Nothing to do return match = re.match('.*Library not loaded:\s(.+)\n.*', error_msg) if match: lib_name = match.group(1) LOGGER.error( "MySQL Client library not loaded. Make sure the shared library " "'%s' can be loaded by Python. Tip: Add folder '%s' to " "environment variable '%s'.", lib_name, lib_dir, libpath_var) sys.exit(1) else: LOGGER.error("C Extension not available: %s", error_msg) sys.exit(1)
def check_c_extension(exc=None): """Check whether we can load the C Extension This function needs the location of the mysql_config tool to figure out the location of the MySQL Connector/C libraries. On Windows it would be the installation location of Connector/C. :param mysql_config: Location of the mysql_config tool :param exc: An ImportError exception """ if not MYSQL_CAPI: return if platform.system() == "Darwin": libpath_var = 'DYLD_LIBRARY_PATH' elif platform.system() == "Windows": libpath_var = 'PATH' else: libpath_var = 'LD_LIBRARY_PATH' if not os.path.exists(MYSQL_CAPI): LOGGER.error("MySQL Connector/C not available using '%s'", MYSQL_CAPI) if os.name == 'posix': if os.path.isdir(MYSQL_CAPI): mysql_config = os.path.join(MYSQL_CAPI, 'bin', 'mysql_config') else: mysql_config = MYSQL_CAPI lib_dir = get_mysql_config_info(mysql_config)['lib_dir'] elif os.path.isdir(MYSQL_CAPI): lib_dir = os.path.join(MYSQL_CAPI, 'lib') else: LOGGER.error("C Extension not supported on %s", os.name) sys.exit(1) error_msg = '' if not exc: try: import _mysql_connector except ImportError as exc: error_msg = str(exc).strip() else: assert(isinstance(exc, ImportError)) error_msg = str(exc).strip() if not error_msg: # Nothing to do return match = re.match('.*Library not loaded:\s(.+)\n.*', error_msg) if match: lib_name = match.group(1) LOGGER.error( "MySQL Client library not loaded. Make sure the shared library " "'%s' can be loaded by Python. Tip: Add folder '%s' to " "environment variable '%s'.", lib_name, lib_dir, libpath_var) sys.exit(1) else: LOGGER.error("C Extension not available: %s", error_msg) sys.exit(1)