12
12
import sys
13
13
import tempfile
14
14
15
+
15
16
def parse_args ():
16
17
17
18
parser = argparse .ArgumentParser (
18
19
description = '''sciSQL deployment tool. Install sciSQL plugin in a
19
20
MariaDB/MySQL running instance :\n
20
21
- install shared library in MariaDB/MySQL plugin directory\n
21
- - install UDF in MariaDB/MySQL database''' ,
22
- )
22
+ - install UDF in MariaDB/MySQL database'''
23
+ )
23
24
24
25
# Defining option of each configuration step
25
26
for step_name in configure .STEP_LIST :
@@ -34,56 +35,59 @@ def parse_args():
34
35
35
36
# Logging management
36
37
verbose_dict = {
37
- 'DEBUG' : logging .DEBUG ,
38
- 'INFO' : logging .INFO ,
39
- 'WARNING' : logging .WARNING ,
40
- 'ERROR' : logging .ERROR ,
41
- 'FATAL' : logging .FATAL ,
38
+ 'DEBUG' : logging .DEBUG ,
39
+ 'INFO' : logging .INFO ,
40
+ 'WARNING' : logging .WARNING ,
41
+ 'ERROR' : logging .ERROR ,
42
+ 'FATAL' : logging .FATAL ,
42
43
}
43
44
verbose_arg_values = verbose_dict .keys ()
44
- parser .add_argument ("-v" , "--verbose-level" , dest = "verbose_str" ,
45
- choices = verbose_arg_values ,
46
- default = 'INFO' ,
47
- help = "verbosity level (default: %( default)s)"
48
- )
45
+ parser .add_argument ("-v" , "--verbose-level" ,
46
+ dest = "verbose_str" ,
47
+ choices = verbose_arg_values ,
48
+ default = 'INFO' ,
49
+ help = "verbosity level (default: %(default)s)" )
49
50
50
51
# forcing options which may ask user confirmation
51
- parser .add_argument ("-f" , "--force" , dest = "force" , action = 'store_true' ,
52
- default = False ,
53
- help = "forcing removal of existing execution data (default: %(default)s)"
54
- )
55
-
56
- parser .add_argument ("-T" , "--tmp-dir" , dest = "tmp_dir" ,
57
- default = "/tmp" ,
58
- help = """Path to directory where deployment temporary data will be stored."""
59
- )
60
-
61
- parser .add_argument ("-m" , "--mysql-dir" , dest = "mysql_dir" ,
62
- default = os .getenv ("MARIADB_DIR" ),
63
- help = """Path to the MariaDB/MySQL install directory.
64
- Default to MARIADB_DIR environement variable value if not empty (default: %(default)s)"""
65
- )
66
-
67
- parser .add_argument ("-b" , "--mysql-bin" , dest = "mysql_bin" ,
68
- default = "{mysql_dir}/bin/mysql" ,
69
- help = """Path to the mysql command line client (e.g. /usr/local/bin/mysql).
70
- Used to CREATE and DROP the scisql UDFs after installation. (default: %(default)s)"""
71
- )
72
-
73
- parser .add_argument ("-P" , "--mysql-plugin-dir" , dest = "mysql_plugin_dir" ,
74
- default = "{mysql_dir}/lib/plugin" ,
75
- help = "full path to MariaDB/MySQL plugin directory (default: %(default)s)"
76
- )
77
-
78
- parser .add_argument ("-S" , "--mysql-socket" , dest = "mysql_socket" ,
79
- default = None ,
80
- help = "UNIX socket file for connecting to MySQL"
81
- )
82
-
83
- parser .add_argument ("-U" , "--mysql-user" , dest = "mysql_user" ,
84
- default = 'root' ,
85
- help = "MySQL user name with admin privileges (default: %(default)s)"
86
- )
52
+ parser .add_argument ("-f" , "--force" ,
53
+ dest = "force" ,
54
+ action = 'store_true' ,
55
+ default = False ,
56
+ help = "forcing removal of existing execution data (default: %(default)s)" )
57
+
58
+ parser .add_argument ("-T" , "--tmp-dir" ,
59
+ dest = "tmp_dir" ,
60
+ default = "/tmp" ,
61
+ help = "Path to directory where deployment temporary data will be stored." )
62
+
63
+ parser .add_argument ("-m" , "--mysql-dir" ,
64
+ dest = "mysql_dir" ,
65
+ default = os .getenv ("MARIADB_DIR" ),
66
+ help = """\
67
+ Path to the MariaDB/MySQL install directory.
68
+ Default to MARIADB_DIR environement variable value if not empty (default: %(default)s)""" )
69
+
70
+ parser .add_argument ("-b" , "--mysql-bin" ,
71
+ dest = "mysql_bin" ,
72
+ default = "{mysql_dir}/bin/mysql" ,
73
+ help = """\
74
+ Path to the mysql command line client (e.g. /usr/local/bin/mysql).
75
+ Used to CREATE and DROP the scisql UDFs after installation. (default: %(default)s)""" )
76
+
77
+ parser .add_argument ("-P" , "--mysql-plugin-dir" ,
78
+ dest = "mysql_plugin_dir" ,
79
+ default = "{mysql_dir}/lib/plugin" ,
80
+ help = "full path to MariaDB/MySQL plugin directory (default: %(default)s)" )
81
+
82
+ parser .add_argument ("-S" , "--mysql-socket" ,
83
+ dest = "mysql_socket" ,
84
+ default = None ,
85
+ help = "UNIX socket file for connecting to MySQL" )
86
+
87
+ parser .add_argument ("-U" , "--mysql-user" ,
88
+ dest = "mysql_user" ,
89
+ default = 'root' ,
90
+ help = "MySQL user name with admin privileges (default: %(default)s)" )
87
91
88
92
args = parser .parse_args ()
89
93
@@ -100,6 +104,7 @@ def parse_args():
100
104
args .verbose_level = verbose_dict [args .verbose_str ]
101
105
return args
102
106
107
+
103
108
def check_global_args (args ):
104
109
# replace default values if needed
105
110
args .mysql_bin = args .mysql_bin .format (mysql_dir = args .mysql_dir )
@@ -108,8 +113,7 @@ def check_global_args(args):
108
113
logging .info ('Checking for mysql command line client' )
109
114
if not os .path .isfile (args .mysql_bin ) or not os .access (args .mysql_bin , os .X_OK ):
110
115
logging .fatal ('{0} does not identify an executable. Use --mysql-dir or --mysql options.'
111
- .format (args .mysql_bin )
112
- )
116
+ .format (args .mysql_bin ))
113
117
sys .exit (1 )
114
118
115
119
logging .info ('Checking for mysql socket' )
@@ -120,11 +124,12 @@ def check_global_args(args):
120
124
mode = os .stat (args .mysql_socket ).st_mode
121
125
is_socket = stat .S_ISSOCK (mode )
122
126
if not is_socket :
123
- logging .fatal ('Invalid MySQL socket. Use --mysql-socket options.'
124
- .format (args .mysql_socket )
127
+ logging .fatal (
128
+ 'Invalid MySQL socket: {0}. Use --mysql-socket options.' .format (args .mysql_socket )
125
129
)
126
130
sys .exit (1 )
127
131
132
+
128
133
def main ():
129
134
130
135
scisql_dir = os .path .abspath (
@@ -136,9 +141,8 @@ def main():
136
141
args = parse_args ()
137
142
138
143
logging .basicConfig (format = '%(levelname)s: %(message)s' , level = args .verbose_level )
139
- logging .info ("sciSQL deployment tool\n " +
140
- "============================"
141
- )
144
+ logging .info ("sciSQL deployment tool\n " +
145
+ "============================" )
142
146
143
147
check_global_args (args )
144
148
@@ -159,44 +163,46 @@ def main():
159
163
try :
160
164
tmp_dir = tempfile .mkdtemp (suffix = '-scisql' , dir = args .tmp_dir )
161
165
162
- scisql_template_dir = os .path .join (scisql_dir , "templates" )
166
+ scisql_template_dir = os .path .join (scisql_dir , "templates" )
163
167
configure .apply_templates (scisql_template_dir , tmp_dir )
164
168
165
169
if configure .DEPLOY in args .step_list :
166
170
167
171
logging .info ("Deploying sciSQL" )
168
172
169
173
logging .info ('Checking for mysql version' )
170
- script = os .path .join (tmp_dir , "check_mysql_version.sh" )
174
+ script = os .path .join (tmp_dir , "check_mysql_version.sh" )
171
175
utils .run_command ([script ])
172
176
173
177
logging .info ('Checking for mysql plugins directory' )
174
178
if not args .mysql_plugin_dir or not os .path .isdir (args .mysql_plugin_dir ):
175
- logging .fatal ('Invalid/missing MySQL plugin directory. Use --mysql-dir or --mysql-plugin-dir options.' )
179
+ logging .fatal (
180
+ 'Invalid/missing MySQL plugin directory. Use --mysql-dir or --mysql-plugin-dir options.'
181
+ )
176
182
sys .exit (1 )
177
183
178
- logging .info ("Deploying sciSQL shared library in {0}"
179
- .format (args .mysql_plugin_dir )
180
- )
184
+ logging .info ("Deploying sciSQL shared library in {0}" .format (args .mysql_plugin_dir ))
181
185
scisql_libname = const .SCISQL_LIBNAME
182
186
# check for existing shared library file of the same version
183
187
scisql_plugin_lib = os .path .join (
184
188
args .mysql_plugin_dir ,
185
189
scisql_libname
186
190
)
187
191
if os .path .isfile (scisql_plugin_lib ):
188
- logging .warn ("Previous sciSQL library of the same version found in MySQL plugin directory ({0})"
189
- .format (scisql_plugin_lib ) +
190
- ". sciSQL plugin (version: {0}) is certainly already deployed." .format (const .SCISQL_VERSION )
191
- )
192
+ err_msg = """Previous sciSQL library of the same version found in MySQL plugin directory \
193
+ ({0}). sciSQL plugin (version: {1}) is certainly already deployed."""
194
+ logging .warning (err_msg .format (scisql_plugin_lib , const .SCISQL_VERSION ))
192
195
if args .force or utils .user_yes_no_query (
193
196
"WARNING: Do you want to replace this shared library"
194
197
+ " by current one and continue ? Answer 'yes' only if you know what you are doing."
195
198
):
196
- logging .warn ("Forcing sciSQL deployment over an existing sciSQL plugin of the same version." )
199
+ logging .warning (
200
+ "Forcing sciSQL deployment over an existing sciSQL plugin of the same version."
201
+ )
197
202
else :
198
- logging .info ("Stopping sciSQL deployment,"
199
- + "please remove previous sciSQL plugin from MySQL" )
203
+ logging .info (
204
+ "Stopping sciSQL deployment, please remove previous sciSQL plugin from MySQL"
205
+ )
200
206
sys .exit (1 )
201
207
202
208
scisql_lib = os .path .join (
@@ -211,24 +217,24 @@ def main():
211
217
212
218
shutil .copy (scisql_lib , args .mysql_plugin_dir )
213
219
214
- script = os .path .join (tmp_dir , configure .DEPLOY + ".sh" )
220
+ script = os .path .join (tmp_dir , configure .DEPLOY + ".sh" )
215
221
utils .run_command ([script ])
216
222
217
223
if configure .TEST in args .step_list :
218
- script = os .path .join (tmp_dir , configure .TEST + ".sh" )
224
+ script = os .path .join (tmp_dir , configure .TEST + ".sh" )
219
225
utils .run_command ([script ])
220
226
221
227
if configure .UNDEPLOY in args .step_list :
222
- script = os .path .join (tmp_dir , configure .UNDEPLOY + ".sh" )
228
+ script = os .path .join (tmp_dir , configure .UNDEPLOY + ".sh" )
223
229
utils .run_command ([script ])
224
230
225
231
finally :
226
232
if logging .getLogger ().getEffectiveLevel () > logging .DEBUG :
227
233
shutil .rmtree (tmp_dir )
228
234
else :
229
235
logging .debug ("Temporary directory {0} " .format (tmp_dir ) +
230
- "not removed in order to enable post-mortem analysis. " +
231
- "Remove it manually." )
236
+ "not removed in order to enable post-mortem analysis. " +
237
+ "Remove it manually." )
232
238
233
239
if __name__ == '__main__' :
234
240
main ()
0 commit comments