in mysqlx-connector-python/cpydist/utils.py [0:0]
def mysql_c_api_info(mysql_config):
"""Get MySQL information using mysql_config tool.
Returns:
dict: Containing MySQL information about libraries.
"""
if os.name == "nt":
return _mysql_c_api_info_win(mysql_config)
if os.path.isdir(mysql_config):
mysql_config = os.path.join(mysql_config, "bin", "mysql_config")
LOGGER.info("Getting MySQL information from %s", mysql_config)
process = Popen([mysql_config], stdout=PIPE, stderr=PIPE)
stdout, stderr = process.communicate()
if not stdout:
raise ValueError(f"Error executing command: {mysql_config} ({stderr})")
# Parse the output. Try to be future safe in case new options
# are added. This might of course fail.
info = {}
for line in stdout.splitlines():
re_obj = re.search(r"^\s+(?:--)?(\w+)\s+\[\s*(.*?)\s*\]", line.decode("utf-8"))
if re_obj:
mc_key = re_obj.group(1)
mc_val = re_obj.group(2)
# We always add the raw output from the different "mysql_config"
# options. And in some cases, like "port", "socket", that is enough
# for use from Python.
info[mc_key] = mc_val
LOGGER.debug("%s: %s", mc_key, mc_val)
if not re.search(r"^-", mc_val) and "=" not in mc_val:
# Not a Unix command line
continue
# In addition form useful information parsed from the
# above command line
parsed_line = _parse_mysql_info_line(mc_val)
if mc_key == "include":
# Lets assume all arguments are paths with "-I", "--include",..
include_dirs = [val for _, val in parsed_line]
info["include_dirs"] = include_dirs
LOGGER.debug("include_dirs: %s", " ".join(include_dirs))
elif mc_key == "libs_r":
info["link_dirs"] = [
val
for key, val in parsed_line
if key
in (
"L",
"library-path",
)
]
info["libraries"] = [
val
for key, val in parsed_line
if key
in (
"l",
"library",
)
]
LOGGER.debug("link_dirs: %s", " ".join(info["link_dirs"]))
LOGGER.debug("libraries: %s", " ".join(info["libraries"]))
# Try to figure out the architecture
info["arch"] = "x86_64" if sys.maxsize > 2**32 else "i386"
# Return a tuple for version instead of a string
info["version"] = tuple(
[int(num) if num.isdigit() else num for num in info["version"].split(".")]
)
return info