Skip to content

Commit f41bd21

Browse files
committed
Python 2.7 and 3 support
PEP8 fixes misc potential bug fixes
1 parent e68631f commit f41bd21

15 files changed

+357
-323
lines changed

bin/scisql-deploy.py

+79-73
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
import sys
1313
import tempfile
1414

15+
1516
def parse_args():
1617

1718
parser = argparse.ArgumentParser(
1819
description='''sciSQL deployment tool. Install sciSQL plugin in a
1920
MariaDB/MySQL running instance :\n
2021
- 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+
)
2324

2425
# Defining option of each configuration step
2526
for step_name in configure.STEP_LIST:
@@ -34,56 +35,59 @@ def parse_args():
3435

3536
# Logging management
3637
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,
4243
}
4344
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)")
4950

5051
# 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)")
8791

8892
args = parser.parse_args()
8993

@@ -100,6 +104,7 @@ def parse_args():
100104
args.verbose_level = verbose_dict[args.verbose_str]
101105
return args
102106

107+
103108
def check_global_args(args):
104109
# replace default values if needed
105110
args.mysql_bin = args.mysql_bin.format(mysql_dir=args.mysql_dir)
@@ -108,8 +113,7 @@ def check_global_args(args):
108113
logging.info('Checking for mysql command line client')
109114
if not os.path.isfile(args.mysql_bin) or not os.access(args.mysql_bin, os.X_OK):
110115
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))
113117
sys.exit(1)
114118

115119
logging.info('Checking for mysql socket')
@@ -120,11 +124,12 @@ def check_global_args(args):
120124
mode = os.stat(args.mysql_socket).st_mode
121125
is_socket = stat.S_ISSOCK(mode)
122126
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. Use --mysql-socket options.'.format(args.mysql_socket)
125129
)
126130
sys.exit(1)
127131

132+
128133
def main():
129134

130135
scisql_dir = os.path.abspath(
@@ -136,9 +141,8 @@ def main():
136141
args = parse_args()
137142

138143
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+
"============================")
142146

143147
check_global_args(args)
144148

@@ -159,44 +163,46 @@ def main():
159163
try:
160164
tmp_dir = tempfile.mkdtemp(suffix='-scisql', dir=args.tmp_dir)
161165

162-
scisql_template_dir=os.path.join(scisql_dir, "templates")
166+
scisql_template_dir = os.path.join(scisql_dir, "templates")
163167
configure.apply_templates(scisql_template_dir, tmp_dir)
164168

165169
if configure.DEPLOY in args.step_list:
166170

167171
logging.info("Deploying sciSQL")
168172

169173
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")
171175
utils.run_command([script])
172176

173177
logging.info('Checking for mysql plugins directory')
174178
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+
)
176182
sys.exit(1)
177183

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))
181185
scisql_libname = const.SCISQL_LIBNAME
182186
# check for existing shared library file of the same version
183187
scisql_plugin_lib = os.path.join(
184188
args.mysql_plugin_dir,
185189
scisql_libname
186190
)
187191
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))
192195
if args.force or utils.user_yes_no_query(
193196
"WARNING: Do you want to replace this shared library"
194197
+ " by current one and continue ? Answer 'yes' only if you know what you are doing."
195198
):
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+
)
197202
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+
)
200206
sys.exit(1)
201207

202208
scisql_lib = os.path.join(
@@ -211,24 +217,24 @@ def main():
211217

212218
shutil.copy(scisql_lib, args.mysql_plugin_dir)
213219

214-
script=os.path.join(tmp_dir, configure.DEPLOY + ".sh")
220+
script = os.path.join(tmp_dir, configure.DEPLOY + ".sh")
215221
utils.run_command([script])
216222

217223
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")
219225
utils.run_command([script])
220226

221227
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")
223229
utils.run_command([script])
224230

225231
finally:
226232
if logging.getLogger().getEffectiveLevel() > logging.DEBUG:
227233
shutil.rmtree(tmp_dir)
228234
else:
229235
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.")
232238

233239
if __name__ == '__main__':
234240
main()

python/scisql/configure.py

+37-36
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
from scisql import const
2-
from distutils.util import strtobool
32
import logging
43
import os
5-
import subprocess
64
import sys
75
import string
86

@@ -11,40 +9,39 @@
119
STEP_DOC = dict(
1210
zip(STEP_LIST,
1311
[
14-
"""Deploy sciSQL plugin in a MySQL running instance""",
15-
"""Launch tests on sciSQL plugin install """,
16-
"""Undeploy sciSQL plugin from a MySQL running instance""",
17-
]
18-
)
12+
"Deploy sciSQL plugin in a MySQL running instance",
13+
"Launch tests on sciSQL plugin install ",
14+
"Undeploy sciSQL plugin from a MySQL running instance",
15+
])
1916
)
2017

2118
DEPLOY = STEP_LIST[0]
2219
TEST = STEP_LIST[1]
2320
UNDEPLOY = STEP_LIST[2]
21+
CONFIG = dict()
22+
2423

2524
def getConfig():
26-
return config
25+
return CONFIG
26+
2727

2828
def init_config(scisql_base, mysql_bin, mysql_user, mysql_password, mysql_socket):
2929

30-
global config
31-
config = dict()
30+
global CONFIG
3231
section = 'scisql'
33-
config[section] = dict()
34-
config[section]['base'] = scisql_base
35-
config[section]['prefix'] = const.SCISQL_PREFIX
36-
config[section]['version'] = const.SCISQL_VERSION
37-
config[section]['vsuffix'] = const.SCISQL_VSUFFIX
38-
config[section]['libname'] = const.SCISQL_LIBNAME
32+
CONFIG[section] = dict()
33+
CONFIG[section]['base'] = scisql_base
34+
CONFIG[section]['prefix'] = const.SCISQL_PREFIX
35+
CONFIG[section]['version'] = const.SCISQL_VERSION
36+
CONFIG[section]['vsuffix'] = const.SCISQL_VSUFFIX
37+
CONFIG[section]['libname'] = const.SCISQL_LIBNAME
3938
section = 'mysqld'
40-
config[section] = dict()
41-
config[section]['bin'] = mysql_bin
42-
config[section]['user'] = mysql_user
43-
config[section]['pass'] = mysql_password
44-
config[section]['sock'] = mysql_socket
39+
CONFIG[section] = dict()
40+
CONFIG[section]['bin'] = mysql_bin
41+
CONFIG[section]['user'] = mysql_user
42+
CONFIG[section]['pass'] = mysql_password
43+
CONFIG[section]['sock'] = mysql_socket
4544

46-
def getConfig():
47-
return config
4845

4946
def _get_template_params():
5047
""" Compute templates parameters from Qserv meta-configuration file
@@ -54,29 +51,31 @@ def _get_template_params():
5451
config = getConfig()
5552

5653
params_dict = {
57-
'PATH': os.environ.get('PATH'),
58-
'MYSQL_BIN': config['mysqld']['bin'],
59-
'MYSQLD_SOCK': config['mysqld']['sock'],
60-
'MYSQLD_USER': config['mysqld']['user'],
61-
'MYSQLD_PASS': config['mysqld']['pass'],
62-
'SCISQL_BASE': config['scisql']['base'],
63-
'SCISQL_PREFIX': config['scisql']['prefix'],
64-
'SCISQL_VERSION': config['scisql']['version'],
65-
'SCISQL_VSUFFIX': config['scisql']['vsuffix'],
66-
'SCISQL_LIBNAME': config['scisql']['libname'],
54+
'PATH': os.environ.get('PATH'),
55+
'MYSQL_BIN': config['mysqld']['bin'],
56+
'MYSQLD_SOCK': config['mysqld']['sock'],
57+
'MYSQLD_USER': config['mysqld']['user'],
58+
'MYSQLD_PASS': config['mysqld']['pass'],
59+
'SCISQL_BASE': config['scisql']['base'],
60+
'SCISQL_PREFIX': config['scisql']['prefix'],
61+
'SCISQL_VERSION': config['scisql']['version'],
62+
'SCISQL_VSUFFIX': config['scisql']['vsuffix'],
63+
'SCISQL_LIBNAME': config['scisql']['libname'],
6764
}
6865

6966
logger.debug("Input parameters :\n {0}".format(params_dict))
7067

7168
return params_dict
7269

70+
7371
def _set_perms(file):
7472
extension = os.path.splitext(file)[1]
7573
if extension in [".sh"]:
76-
os.chmod(file, 0750)
74+
os.chmod(file, 0o750)
7775
# all other files are configuration files
7876
else:
79-
os.chmod(file, 0640)
77+
os.chmod(file, 0o640)
78+
8079

8180
def apply_tpl(src_file, target_file):
8281
""" Creating one configuration file from one template
@@ -92,7 +91,7 @@ def apply_tpl(src_file, target_file):
9291
out_cfg = t.safe_substitute(**params_dict)
9392
for match in t.pattern.findall(t.template):
9493
name = match[1]
95-
if len(name) != 0 and not params_dict.has_key(name):
94+
if len(name) != 0 and name not in params_dict:
9695
logger.fatal("Template \"%s\" in file %s is not defined in configuration tool", name, src_file)
9796
sys.exit(1)
9897

@@ -102,6 +101,7 @@ def apply_tpl(src_file, target_file):
102101
with open(target_file, "w") as cfg:
103102
cfg.write(out_cfg)
104103

104+
105105
def apply_templates(template_root, dest_root):
106106

107107
logger = logging.getLogger()
@@ -123,6 +123,7 @@ def apply_templates(template_root, dest_root):
123123

124124
return True
125125

126+
126127
class ScisqlConfigTemplate(string.Template):
127128
delimiter = '{{'
128129
pattern = r'''

0 commit comments

Comments
 (0)