-
Notifications
You must be signed in to change notification settings - Fork 37
/
mariadb_posix.py
87 lines (72 loc) · 2.75 KB
/
mariadb_posix.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env python
import subprocess
from packaging import version
import sys
import os
class MariaDBConfiguration():
lib_dirs = []
libs = []
version = []
includes = []
extra_objects = []
extra_compile_args = []
extra_link_args = []
def mariadb_config(config, option):
from os import popen
file = popen("%s --%s" % (config, option))
data = file.read().strip().split()
rc = file.close()
if rc:
if rc / 256:
data = []
if rc / 256 > 1:
raise EnvironmentError(
"""mariadb_config not found.
This error typically indicates that MariaDB Connector/C, a dependency which
must be preinstalled, is not found.
If MariaDB Connector/C is not installed, see installation instructions
If MariaDB Connector/C is installed, either set the environment variable
MARIADB_CONFIG or edit the configuration file 'site.cfg' to set the
'mariadb_config' option to the file location of the mariadb_config utility.
""")
return data
def dequote(s):
if s[0] in "\"'" and s[0] == s[-1]:
s = s[1:-1]
return s
def get_config(options):
required_version = "3.3.1"
static = options["link_static"]
try:
try:
config_prg = os.environ["MARIADB_CONFIG"]
except KeyError:
config_prg = options["mariadb_config"]
subprocess.call([config_prg, "--cc_version"])
except FileNotFoundError:
# using default from path
config_prg = "mariadb_config"
cc_version = mariadb_config(config_prg, "cc_version")
if version.Version(cc_version[0]) < version.Version(required_version):
print('MariaDB Connector/Python requires MariaDB Connector/C '
'>= %s, found version %s' % (required_version, cc_version[0]))
sys.exit(2)
cfg = MariaDBConfiguration()
cfg.version = cc_version[0]
plugindir = mariadb_config(config_prg, "plugindir")
libs = mariadb_config(config_prg, "libs")
extra_libs = mariadb_config(config_prg, "libs_sys")
cfg.lib_dirs = [dequote(i[2:]) for i in libs if i.startswith("-L")]
cfg.libs = [dequote(i[2:]) for i in libs if i.startswith("-l")]
includes = mariadb_config(config_prg, "include")
mariadb_includes = [dequote(i[2:]) for i in includes if i.startswith("-I")]
mariadb_includes.extend(["./include"])
if static.lower() == "on":
cfg.extra_link_args = ["-u mysql_ps_fetch_functions"]
cfg.extra_objects = ['{}/lib{}.a'.format(cfg.lib_dirs[0], lib)
for lib in ["mariadbclient"]]
cfg.libs = [dequote(i[2:])
for i in extra_libs if i.startswith("-l")]
cfg.includes = mariadb_includes
cfg.extra_compile_args = ["-DDEFAULT_PLUGINS_SUBDIR=\"%s\"" % plugindir[0]]
return cfg