Skip to content

Commit e9e73ac

Browse files
committed
Fix string type checking
Fix stderr print functions, logging Use context for config files
1 parent 861c98a commit e9e73ac

File tree

4 files changed

+36
-28
lines changed

4 files changed

+36
-28
lines changed

bin/scisql-deploy.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def check_global_args(args):
125125
is_socket = stat.S_ISSOCK(mode)
126126
if not is_socket:
127127
logging.fatal(
128-
'Invalid MySQL socket. Use --mysql-socket options.'.format(args.mysql_socket)
128+
'Invalid MySQL socket: {0}. Use --mysql-socket options.'.format(args.mysql_socket)
129129
)
130130
sys.exit(1)
131131

test/base.py

+18-12
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
except ImportError:
3131
from configparser import ConfigParser
3232

33+
try:
34+
stringTypes = (str, unicode)
35+
except TypeError:
36+
stringTypes = (str,)
37+
3338
import MySQLdb as sql
3439

3540

@@ -59,25 +64,26 @@ def dbparam(x):
5964
elif isinstance(x, ColumnName):
6065
return "`" + x + "`"
6166
elif isinstance(x, bytes):
62-
return "'" + str(x) + "'"
63-
elif isinstance(x, str):
67+
return "'" + str(x.decode()) + "'"
68+
elif isinstance(x, stringTypes):
6469
return "'" + x + "'"
6570
else:
6671
return repr(x)
6772

6873

6974
def _parseMyCnf(my_cnf):
7075
parser = ConfigParser()
71-
parser.read_file(open(my_cnf), my_cnf)
72-
kw = {}
73-
for section in parser.sections():
74-
for key, val in parser[section].items():
75-
if key == 'user':
76-
kw['user'] = val
77-
elif key == 'password':
78-
kw['passwd'] = val
79-
elif key == 'socket':
80-
kw['unix_socket'] = val
76+
with open(my_cnf) as conf_file:
77+
parser.read_file(conf_file, my_cnf)
78+
kw = {}
79+
for section in parser.sections():
80+
for key, val in parser[section].items():
81+
if key == 'user':
82+
kw['user'] = val
83+
elif key == 'password':
84+
kw['passwd'] = val
85+
elif key == 'socket':
86+
kw['unix_socket'] = val
8187
return kw
8288

8389

tools/docs.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,8 @@ def extract_docs_from_c(filename):
347347
elt = etree.XML(xml)
348348
docs.append(ast(elt))
349349
except:
350-
sys.stderr.write("Failed to parse documentation block:\n\n%s\n\n" % xml)
351-
sys.stderr.write(traceback.format_exc())
350+
print("Failed to parse documentation block:\n\n%s\n\n" % xml, file=sys.stderr)
351+
print(traceback.format_exc(), file=sys.stderr)
352352
return docs
353353

354354

@@ -372,8 +372,8 @@ def extract_docs_from_sql(filename):
372372
elt = etree.XML(string.Template(xml).safe_substitute(os.environ))
373373
docs.append(ast(elt))
374374
except ValueError:
375-
sys.stderr.write("Failed to parse documentation block:\n\n%s\n\n" % xml)
376-
sys.stderr.write(traceback.format_exc())
375+
print("Failed to parse documentation block:\n\n%s\n\n" % xml, file=sys.stderr)
376+
print(traceback.format_exc(), file=sys.stderr)
377377
return docs
378378

379379

@@ -425,7 +425,8 @@ def _test(obj):
425425
with open(os.devnull, 'wb') as devnull:
426426
subprocess.check_call(args, shell=False, stdin=source, stdout=devnull)
427427
except subprocess.CalledProcessError:
428-
sys.stderr.write("Failed to run documentation example:\n\n%s\n\n" % ex.source)
428+
print("Failed to run documentation example:\n\n%s\n\n" % ex.source,
429+
file=sys.stderr)
429430
nfail += 1
430431
return nfail
431432

tools/undeploy.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,17 @@
6767

6868
def _parseMyCnf(my_cnf):
6969
parser = ConfigParser()
70-
parser.read_file(open(my_cnf), my_cnf)
71-
kw = {}
72-
for section in parser.sections():
73-
for key, val in parser[section].items():
74-
if key == 'user':
75-
kw['user'] = val
76-
elif key == 'password':
77-
kw['passwd'] = val
78-
elif key == 'socket':
79-
kw['unix_socket'] = val
70+
with open(my_cnf) as conf_file:
71+
parser.read_file(conf_file, my_cnf)
72+
kw = {}
73+
for section in parser.sections():
74+
for key, val in parser[section].items():
75+
if key == 'user':
76+
kw['user'] = val
77+
elif key == 'password':
78+
kw['passwd'] = val
79+
elif key == 'socket':
80+
kw['unix_socket'] = val
8081
return kw
8182

8283

0 commit comments

Comments
 (0)