core/various: python3 compat, prepare for python2 -> python3
see https://review.gluster.org/#/c/19788/, https://review.gluster.org/#/c/19871/, https://review.gluster.org/#/c/19952/, https://review.gluster.org/#/c/20104/, https://review.gluster.org/#/c/20162/, https://review.gluster.org/#/c/20185/, https://review.gluster.org/#/c/20207/, https://review.gluster.org/#/c/20227/, https://review.gluster.org/#/c/20307/, https://review.gluster.org/#/c/20320/, https://review.gluster.org/#/c/20332/, and https://review.gluster.org/#/c/20364/ Fixes glupy.py python2isms, iteritems -> items, and some overlooked print() in georep/peer_mountbroker.in Note: Fedora packaging guidelines and SUSE rpmlint require explicit shebangs; popular practices like #!/usr/bin/env python and #!/usr/bin/python are not allowed; they must be #!/usr/bin/python2 or #!/usr/bin/python3 Note: Selected small fixes from 2to3 utility. Specifically apply, basestring, funcattrs, has_key, idioms, map, numliterals, raise, set_literal, types, urllib, and zip have already been applied. Also version agnostic imports for urllib, cpickle, socketserver, _thread, queue, etc., suggested by Aravinda in https://review.gluster.org/#/c/19767/1 Note: these 2to3 fixes report no changes are necessary: asserts, buffer, exec, execfile, exitfunc, filter, getcwdu, imports2, input, intern, itertools, metaclass, methodattrs, ne, next, nonzero, operator, paren, raw_input, reduce, reload, renames, repr, standarderror, sys_exc, throw, tuple_params, xreadlines. Change-Id: Idda031c1ec975417c79323aea33e7b694e752b2a updates: #411 Signed-off-by: Kaleb S. KEITHLEY <kkeithle@redhat.com>
This commit is contained in:
parent
dab12ce093
commit
55d1b0531a
@ -49,7 +49,7 @@ class GlusterEventsRequestHandler(SocketServer.BaseRequestHandler):
|
||||
logger.warn("Unable to parse Event {0}".format(data))
|
||||
return
|
||||
|
||||
for k, v in data_dict.iteritems():
|
||||
for k, v in data_dict.items():
|
||||
try:
|
||||
if k in AUTO_BOOL_ATTRIBUTES:
|
||||
data_dict[k] = boolify(v)
|
||||
|
@ -67,7 +67,7 @@ def generate(tmpl, name, table):
|
||||
sdict["@RET_TYPE@"] = string.join(ret_type, "")
|
||||
sdict["@RET_VAR@"] = string.join(ret_var, "")
|
||||
|
||||
for old, new in sdict.iteritems():
|
||||
for old, new in sdict.items():
|
||||
tmpl = tmpl.replace(old, new)
|
||||
# TBD: reindent/reformat the result for maximum readability.
|
||||
return tmpl
|
||||
|
@ -74,7 +74,7 @@ def print_summary(failed_builds, total_builds, html=False):
|
||||
count[template],
|
||||
{'failed': failed_builds, 'total': total_builds}
|
||||
))
|
||||
for k, v in summary.iteritems():
|
||||
for k, v in summary.items():
|
||||
if k == 'core':
|
||||
print(''.join([TERM.red, "Found cores:", TERM.normal]))
|
||||
for comp, link in zip(v[::2], v[1::2]):
|
||||
|
@ -217,7 +217,7 @@ class GitBranchDiff:
|
||||
print(self.tick + " Successfully Backported changes:")
|
||||
print(' {' + 'from: ' + self.s_pattern + \
|
||||
' to: '+ self.t_pattern + '}\n')
|
||||
for key, value in self.s_dict.iteritems():
|
||||
for key, value in self.s_dict.items():
|
||||
if value in self.t_dict.itervalues():
|
||||
print("[%s%s%s] %s" %(self.yello_set,
|
||||
key,
|
||||
@ -231,7 +231,7 @@ class GitBranchDiff:
|
||||
else:
|
||||
review_list = []
|
||||
|
||||
for key, value in self.s_dict.iteritems():
|
||||
for key, value in self.s_dict.items():
|
||||
if value not in self.t_dict.itervalues():
|
||||
if any(value in s for s in review_list):
|
||||
print("[%s%s%s] %s %s(under review)%s" %(self.yello_set,
|
||||
|
@ -91,7 +91,7 @@ def generate (graph, last, stream=sys.stdout):
|
||||
sv.dumped = True
|
||||
print("volume %s" % last.name, file=stream)
|
||||
print(" type %s" % last.xl_type, file=stream)
|
||||
for k, v in last.opts.iteritems():
|
||||
for k, v in last.opts.items():
|
||||
print(" option %s %s" % (k, v), file=stream)
|
||||
if last.subvols:
|
||||
print(" subvolumes %s" % string.join(
|
||||
|
@ -49,7 +49,7 @@ def generate_stanza (vf, all_xlators, cur_subvol):
|
||||
sv_list.append(sv.name)
|
||||
vf.write("volume %s\n"%cur_subvol.name)
|
||||
vf.write(" type %s\n"%cur_subvol.type)
|
||||
for kvpair in cur_subvol.opts.iteritems():
|
||||
for kvpair in cur_subvol.opts.items():
|
||||
vf.write(" option %s %s\n"%kvpair)
|
||||
if sv_list:
|
||||
vf.write(" subvolumes %s\n"%string.join(sv_list))
|
||||
|
@ -132,7 +132,7 @@ def generate (graph, last, stream=sys.stdout):
|
||||
sv.dumped = True
|
||||
print("volume %s" % last.name, file=stream)
|
||||
print(" type %s" % last.type, file=stream)
|
||||
for k, v in last.opts.iteritems():
|
||||
for k, v in last.opts.items():
|
||||
print(" option %s %s" % (k, v), file=stream)
|
||||
if last.subvols:
|
||||
print(" subvolumes %s" % string.join(
|
||||
|
@ -1,11 +1,12 @@
|
||||
#!/usr/bin/python2
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import os
|
||||
from argparse import ArgumentParser, RawDescriptionHelpFormatter
|
||||
import json
|
||||
import sys
|
||||
|
||||
|
||||
PROG_DESCRIPTION = """
|
||||
GlusterFS Mountbroker user management
|
||||
"""
|
||||
@ -15,19 +16,19 @@ args = None
|
||||
|
||||
def ok(message=""):
|
||||
if (not args and "-j" in sys.argv) or (args and args.json):
|
||||
print json.dumps({"ok": True, "message": message})
|
||||
print(json.dumps({"ok": True, "message": message}))
|
||||
else:
|
||||
if message:
|
||||
print message
|
||||
print(message)
|
||||
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
def notok(message=""):
|
||||
if (not args and "-j" in sys.argv) or (args and args.json):
|
||||
print json.dumps({"ok": False, "message": message})
|
||||
print(json.dumps({"ok": False, "message": message}))
|
||||
else:
|
||||
print "error: %s" % message
|
||||
print("error: %s" % message)
|
||||
|
||||
# Always return zero due to limitation while executing
|
||||
# as `gluster system:: execute`
|
||||
@ -65,7 +66,7 @@ class MountbrokerUserMgmt(object):
|
||||
def _get_write_data(self):
|
||||
op = "volume management\n"
|
||||
op += " type mgmt/glusterd\n"
|
||||
for k, v in self._options.iteritems():
|
||||
for k, v in self._options.items():
|
||||
op += " option %s %s\n" % (k, v)
|
||||
for line in self.commented_lines:
|
||||
op += " %s\n" % line
|
||||
@ -88,7 +89,7 @@ class MountbrokerUserMgmt(object):
|
||||
|
||||
def add_user(self, user, volumes):
|
||||
vols = set()
|
||||
for k, v in self._options.iteritems():
|
||||
for k, v in self._options.items():
|
||||
if k.startswith("mountbroker-geo-replication.") \
|
||||
and user == k.split(".")[-1]:
|
||||
vols.update(v.split(","))
|
||||
@ -99,7 +100,7 @@ class MountbrokerUserMgmt(object):
|
||||
|
||||
def remove_volume(self, user, volumes):
|
||||
vols = set()
|
||||
for k, v in self._options.iteritems():
|
||||
for k, v in self._options.items():
|
||||
if k.startswith("mountbroker-geo-replication.") \
|
||||
and user == k.split(".")[-1]:
|
||||
vols.update(v.split(","))
|
||||
@ -119,7 +120,7 @@ class MountbrokerUserMgmt(object):
|
||||
def info(self):
|
||||
data = {"users": []}
|
||||
|
||||
for k, v in self._options.iteritems():
|
||||
for k, v in self._options.items():
|
||||
if k.startswith("mountbroker-geo-replication."):
|
||||
data["users"].append(
|
||||
{"name": k.split(".")[-1], "volumes": v.split(",")}
|
||||
@ -133,7 +134,7 @@ class MountbrokerUserMgmt(object):
|
||||
def format_info(data):
|
||||
op = "%s %s\n" % ("Option".ljust(50), "Value".ljust(50))
|
||||
op += ("-" * 101) + "\n"
|
||||
for key, value in data.iteritems():
|
||||
for key, value in data.items():
|
||||
if key != "users":
|
||||
op += "%s %s\n" % (key.ljust(50), value)
|
||||
|
||||
|
@ -1,4 +1,7 @@
|
||||
#!/usr/bin/python2
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import os
|
||||
from errno import EEXIST, ENOENT
|
||||
|
||||
@ -48,7 +51,7 @@ class MountbrokerUserMgmt(object):
|
||||
if line.startswith("#"):
|
||||
self.commented_lines.append(line)
|
||||
|
||||
for k, v in self._options.iteritems():
|
||||
for k, v in self._options.items():
|
||||
if k.startswith("mountbroker-geo-replication."):
|
||||
user = k.split(".")[-1]
|
||||
self.user_volumes[user] = set(v.split(","))
|
||||
@ -59,7 +62,7 @@ class MountbrokerUserMgmt(object):
|
||||
def _get_write_data(self):
|
||||
op = "volume management\n"
|
||||
op += " type mgmt/glusterd\n"
|
||||
for k, v in self._options.iteritems():
|
||||
for k, v in self._options.items():
|
||||
if k.startswith("mountbroker-geo-replication."):
|
||||
# Users will be added seperately
|
||||
continue
|
||||
|
@ -1325,7 +1325,7 @@ class SSH(object):
|
||||
da0 = (rv, exrv)
|
||||
da1 = ({}, {})
|
||||
for i in range(2):
|
||||
for k, v in da0[i].iteritems():
|
||||
for k, v in da0[i].items():
|
||||
da1[i][k] = int(v)
|
||||
if da1[0] != da1[1]:
|
||||
raise GsyncdError(
|
||||
|
@ -61,15 +61,15 @@ default_@NAME@ (
|
||||
"""
|
||||
|
||||
def gen_defaults ():
|
||||
for name in ops.iterkeys():
|
||||
for name in list(ops.keys()):
|
||||
print(generate(FAILURE_CBK_TEMPLATE, name, cbk_subs))
|
||||
for name in ops.iterkeys():
|
||||
for name in list(ops.keys()):
|
||||
print(generate(CBK_RESUME_TEMPLATE, name, cbk_subs))
|
||||
for name in ops.iterkeys():
|
||||
for name in list(ops.keys()):
|
||||
print(generate(CBK_TEMPLATE, name, cbk_subs))
|
||||
for name in ops.iterkeys():
|
||||
for name in list(ops.keys()):
|
||||
print(generate(RESUME_TEMPLATE, name, fop_subs))
|
||||
for name in ops.iterkeys():
|
||||
for name in list(ops.keys()):
|
||||
print(generate(FOP_TEMPLATE, name, fop_subs))
|
||||
|
||||
for l in open(sys.argv[1], 'r').readlines():
|
||||
|
@ -543,170 +543,170 @@ ops['getspec'] = (
|
||||
)
|
||||
|
||||
ops['lease'] = (
|
||||
('fop-arg', 'loc', 'loc_t *'),
|
||||
('fop-arg', 'lease', 'struct gf_lease *'),
|
||||
('fop-arg', 'xdata', 'dict_t *'),
|
||||
('cbk-arg', 'lease', 'struct gf_lease *'),
|
||||
('cbk-arg', 'xdata', 'dict_t *'),
|
||||
('fop-arg', 'loc', 'loc_t *'),
|
||||
('fop-arg', 'lease', 'struct gf_lease *'),
|
||||
('fop-arg', 'xdata', 'dict_t *'),
|
||||
('cbk-arg', 'lease', 'struct gf_lease *'),
|
||||
('cbk-arg', 'xdata', 'dict_t *'),
|
||||
)
|
||||
|
||||
ops['getactivelk'] = (
|
||||
('fop-arg', 'loc', 'loc_t *'),
|
||||
('fop-arg', 'xdata', 'dict_t *'),
|
||||
('cbk-arg', 'locklist', 'lock_migration_info_t *'),
|
||||
('cbk-arg', 'xdata', 'dict_t *'),
|
||||
('fop-arg', 'loc', 'loc_t *'),
|
||||
('fop-arg', 'xdata', 'dict_t *'),
|
||||
('cbk-arg', 'locklist', 'lock_migration_info_t *'),
|
||||
('cbk-arg', 'xdata', 'dict_t *'),
|
||||
)
|
||||
|
||||
ops['setactivelk'] = (
|
||||
('fop-arg', 'loc', 'loc_t *'),
|
||||
('fop-arg', 'locklist', 'lock_migration_info_t *'),
|
||||
('fop-arg', 'xdata', 'dict_t *'),
|
||||
('cbk-arg', 'xdata', 'dict_t *'),
|
||||
('fop-arg', 'loc', 'loc_t *'),
|
||||
('fop-arg', 'locklist', 'lock_migration_info_t *'),
|
||||
('fop-arg', 'xdata', 'dict_t *'),
|
||||
('cbk-arg', 'xdata', 'dict_t *'),
|
||||
)
|
||||
|
||||
ops['put'] = (
|
||||
('fop-arg', 'loc', 'loc_t *', 'loc'),
|
||||
('fop-arg', 'mode', 'mode_t', 'mode'),
|
||||
('fop-arg', 'umask', 'mode_t', 'umask'),
|
||||
('fop-arg', 'flags', 'uint32_t', 'flags'),
|
||||
('fop-arg', 'vector', 'struct iovec *', 'vector'),
|
||||
('fop-arg', 'count', 'int32_t'),
|
||||
('fop-arg', 'off', 'off_t', 'offset'),
|
||||
('fop-arg', 'iobref', 'struct iobref *'),
|
||||
('fop-arg', 'dict', 'dict_t *', 'xattr'),
|
||||
('fop-arg', 'xdata', 'dict_t *', 'xdata'),
|
||||
('cbk-arg', 'inode', 'inode_t *'),
|
||||
('cbk-arg', 'buf', 'struct iatt *'),
|
||||
('cbk-arg', 'preparent', 'struct iatt *'),
|
||||
('cbk-arg', 'postparent', 'struct iatt *'),
|
||||
('cbk-arg', 'xdata', 'dict_t *'),
|
||||
('fop-arg', 'loc', 'loc_t *', 'loc'),
|
||||
('fop-arg', 'mode', 'mode_t', 'mode'),
|
||||
('fop-arg', 'umask', 'mode_t', 'umask'),
|
||||
('fop-arg', 'flags', 'uint32_t', 'flags'),
|
||||
('fop-arg', 'vector', 'struct iovec *', 'vector'),
|
||||
('fop-arg', 'count', 'int32_t'),
|
||||
('fop-arg', 'off', 'off_t', 'offset'),
|
||||
('fop-arg', 'iobref', 'struct iobref *'),
|
||||
('fop-arg', 'dict', 'dict_t *', 'xattr'),
|
||||
('fop-arg', 'xdata', 'dict_t *', 'xdata'),
|
||||
('cbk-arg', 'inode', 'inode_t *'),
|
||||
('cbk-arg', 'buf', 'struct iatt *'),
|
||||
('cbk-arg', 'preparent', 'struct iatt *'),
|
||||
('cbk-arg', 'postparent', 'struct iatt *'),
|
||||
('cbk-arg', 'xdata', 'dict_t *'),
|
||||
)
|
||||
|
||||
ops['icreate'] = (
|
||||
('fop-arg', 'loc', 'loc_t *'),
|
||||
('fop-arg', 'mode', 'mode_t'),
|
||||
('fop-arg', 'xdata', 'dict_t *'),
|
||||
('cbk-arg', 'inode', 'inode_t *'),
|
||||
('cbk-arg', 'buf', 'struct iatt *'),
|
||||
('cbk-arg', 'xdata', 'dict_t *'),
|
||||
('fop-arg', 'loc', 'loc_t *'),
|
||||
('fop-arg', 'mode', 'mode_t'),
|
||||
('fop-arg', 'xdata', 'dict_t *'),
|
||||
('cbk-arg', 'inode', 'inode_t *'),
|
||||
('cbk-arg', 'buf', 'struct iatt *'),
|
||||
('cbk-arg', 'xdata', 'dict_t *'),
|
||||
)
|
||||
|
||||
ops['namelink'] = (
|
||||
('fop-arg', 'loc', 'loc_t *'),
|
||||
('fop-arg', 'xdata', 'dict_t *'),
|
||||
('cbk-arg', 'prebuf', 'struct iatt *'),
|
||||
('cbk-arg', 'postbuf', 'struct iatt *'),
|
||||
('cbk-arg', 'xdata', 'dict_t *'),
|
||||
('fop-arg', 'loc', 'loc_t *'),
|
||||
('fop-arg', 'xdata', 'dict_t *'),
|
||||
('cbk-arg', 'prebuf', 'struct iatt *'),
|
||||
('cbk-arg', 'postbuf', 'struct iatt *'),
|
||||
('cbk-arg', 'xdata', 'dict_t *'),
|
||||
)
|
||||
|
||||
#####################################################################
|
||||
xlator_cbks['forget'] = (
|
||||
('fn-arg', 'this', 'xlator_t *'),
|
||||
('fn-arg', 'inode', 'inode_t *'),
|
||||
('fn-arg', 'this', 'xlator_t *'),
|
||||
('fn-arg', 'inode', 'inode_t *'),
|
||||
('ret-val', 'int32_t', '0'),
|
||||
)
|
||||
|
||||
xlator_cbks['release'] = (
|
||||
('fn-arg', 'this', 'xlator_t *'),
|
||||
('fn-arg', 'fd', 'fd_t *'),
|
||||
('ret-val', 'int32_t', '0'),
|
||||
('fn-arg', 'this', 'xlator_t *'),
|
||||
('fn-arg', 'fd', 'fd_t *'),
|
||||
('ret-val', 'int32_t', '0'),
|
||||
)
|
||||
|
||||
xlator_cbks['releasedir'] = (
|
||||
('fn-arg', 'this', 'xlator_t *'),
|
||||
('fn-arg', 'fd', 'fd_t *'),
|
||||
('ret-val', 'int32_t', '0'),
|
||||
('fn-arg', 'this', 'xlator_t *'),
|
||||
('fn-arg', 'fd', 'fd_t *'),
|
||||
('ret-val', 'int32_t', '0'),
|
||||
)
|
||||
|
||||
xlator_cbks['invalidate'] = (
|
||||
('fn-arg', 'this', 'xlator_t *'),
|
||||
('fn-arg', 'inode', 'inode_t *'),
|
||||
('ret-val', 'int32_t', '0'),
|
||||
('fn-arg', 'this', 'xlator_t *'),
|
||||
('fn-arg', 'inode', 'inode_t *'),
|
||||
('ret-val', 'int32_t', '0'),
|
||||
)
|
||||
|
||||
xlator_cbks['client_destroy'] = (
|
||||
('fn-arg', 'this', 'xlator_t *'),
|
||||
('fn-arg', 'client', 'client_t *'),
|
||||
('ret-val', 'int32_t', '0'),
|
||||
('fn-arg', 'this', 'xlator_t *'),
|
||||
('fn-arg', 'client', 'client_t *'),
|
||||
('ret-val', 'int32_t', '0'),
|
||||
)
|
||||
|
||||
xlator_cbks['client_disconnect'] = (
|
||||
('fn-arg', 'this', 'xlator_t *'),
|
||||
('fn-arg', 'client', 'client_t *'),
|
||||
('ret-val', 'int32_t', '0'),
|
||||
('fn-arg', 'this', 'xlator_t *'),
|
||||
('fn-arg', 'client', 'client_t *'),
|
||||
('ret-val', 'int32_t', '0'),
|
||||
)
|
||||
|
||||
xlator_cbks['ictxmerge'] = (
|
||||
('fn-arg', 'this', 'xlator_t *'),
|
||||
('fn-arg', 'fd', 'fd_t *'),
|
||||
('fn-arg', 'inode', 'inode_t *'),
|
||||
('fn-arg', 'linked_inode', 'inode_t *'),
|
||||
('ret-val', 'void', ''),
|
||||
('fn-arg', 'this', 'xlator_t *'),
|
||||
('fn-arg', 'fd', 'fd_t *'),
|
||||
('fn-arg', 'inode', 'inode_t *'),
|
||||
('fn-arg', 'linked_inode', 'inode_t *'),
|
||||
('ret-val', 'void', ''),
|
||||
)
|
||||
|
||||
#####################################################################
|
||||
xlator_dumpops['priv'] = (
|
||||
('fn-arg', 'this', 'xlator_t *'),
|
||||
('ret-val', 'int32_t', '0'),
|
||||
('fn-arg', 'this', 'xlator_t *'),
|
||||
('ret-val', 'int32_t', '0'),
|
||||
)
|
||||
|
||||
xlator_dumpops['inode'] = (
|
||||
('fn-arg', 'this', 'xlator_t *'),
|
||||
('ret-val', 'int32_t', '0'),
|
||||
('fn-arg', 'this', 'xlator_t *'),
|
||||
('ret-val', 'int32_t', '0'),
|
||||
)
|
||||
|
||||
xlator_dumpops['fd'] = (
|
||||
('fn-arg', 'this', 'xlator_t *'),
|
||||
('ret-val', 'int32_t', '0'),
|
||||
('fn-arg', 'this', 'xlator_t *'),
|
||||
('ret-val', 'int32_t', '0'),
|
||||
)
|
||||
|
||||
xlator_dumpops['inodectx'] = (
|
||||
('fn-arg', 'this', 'xlator_t *'),
|
||||
('fn-arg', 'ino', 'inode_t *'),
|
||||
('ret-val', 'int32_t', '0'),
|
||||
('fn-arg', 'this', 'xlator_t *'),
|
||||
('fn-arg', 'ino', 'inode_t *'),
|
||||
('ret-val', 'int32_t', '0'),
|
||||
)
|
||||
|
||||
xlator_dumpops['fdctx'] = (
|
||||
('fn-arg', 'this', 'xlator_t *'),
|
||||
('fn-arg', 'fd', 'fd_t *'),
|
||||
('ret-val', 'int32_t', '0'),
|
||||
('fn-arg', 'this', 'xlator_t *'),
|
||||
('fn-arg', 'fd', 'fd_t *'),
|
||||
('ret-val', 'int32_t', '0'),
|
||||
)
|
||||
|
||||
xlator_dumpops['priv_to_dict'] = (
|
||||
('fn-arg', 'this', 'xlator_t *'),
|
||||
('fn-arg', 'dict', 'dict_t *'),
|
||||
('ret-val', 'int32_t', '0'),
|
||||
('fn-arg', 'this', 'xlator_t *'),
|
||||
('fn-arg', 'dict', 'dict_t *'),
|
||||
('ret-val', 'int32_t', '0'),
|
||||
)
|
||||
|
||||
xlator_dumpops['inode_to_dict'] = (
|
||||
('fn-arg', 'this', 'xlator_t *'),
|
||||
('fn-arg', 'dict', 'dict_t *'),
|
||||
('ret-val', 'int32_t', '0'),
|
||||
('fn-arg', 'this', 'xlator_t *'),
|
||||
('fn-arg', 'dict', 'dict_t *'),
|
||||
('ret-val', 'int32_t', '0'),
|
||||
)
|
||||
|
||||
xlator_dumpops['fd_to_dict'] = (
|
||||
('fn-arg', 'this', 'xlator_t *'),
|
||||
('fn-arg', 'dict', 'dict_t *'),
|
||||
('ret-val', 'int32_t', '0'),
|
||||
('fn-arg', 'this', 'xlator_t *'),
|
||||
('fn-arg', 'dict', 'dict_t *'),
|
||||
('ret-val', 'int32_t', '0'),
|
||||
)
|
||||
|
||||
xlator_dumpops['inodectx_to_dict'] = (
|
||||
('fn-arg', 'this', 'xlator_t *'),
|
||||
('fn-arg', 'ino', 'inode_t *'),
|
||||
('fn-arg', 'dict', 'dict_t *'),
|
||||
('ret-val', 'int32_t', '0'),
|
||||
('fn-arg', 'this', 'xlator_t *'),
|
||||
('fn-arg', 'ino', 'inode_t *'),
|
||||
('fn-arg', 'dict', 'dict_t *'),
|
||||
('ret-val', 'int32_t', '0'),
|
||||
)
|
||||
|
||||
xlator_dumpops['fdctx_to_dict'] = (
|
||||
('fn-arg', 'this', 'xlator_t *'),
|
||||
('fn-arg', 'fd', 'fd_t *'),
|
||||
('fn-arg', 'dict', 'dict_t *'),
|
||||
('ret-val', 'int32_t', '0'),
|
||||
('fn-arg', 'this', 'xlator_t *'),
|
||||
('fn-arg', 'fd', 'fd_t *'),
|
||||
('fn-arg', 'dict', 'dict_t *'),
|
||||
('ret-val', 'int32_t', '0'),
|
||||
)
|
||||
|
||||
xlator_dumpops['history'] = (
|
||||
('fn-arg', 'this', 'xlator_t *'),
|
||||
('ret-val', 'int32_t', '0'),
|
||||
('fn-arg', 'this', 'xlator_t *'),
|
||||
('ret-val', 'int32_t', '0'),
|
||||
)
|
||||
|
||||
def get_error_arg (type_str):
|
||||
@ -716,18 +716,17 @@ def get_error_arg (type_str):
|
||||
|
||||
def get_subs (names, types, cbktypes=None):
|
||||
sdict = {}
|
||||
sdict["@SHORT_ARGS@"] = string.join(names, ", ")
|
||||
sdict["@SHORT_ARGS@"] = ', '.join(names)
|
||||
# Convert two separate tuples to one of (name, type) sub-tuples.
|
||||
as_tuples = list(zip(types, names))
|
||||
# Convert each sub-tuple into a "type name" string.
|
||||
as_strings = list(map(string.join, as_tuples))
|
||||
as_strings = [' '.join(item) for item in as_tuples]
|
||||
# Join all of those into one big string.
|
||||
sdict["@LONG_ARGS@"] = string.join(as_strings, ",\n\t")
|
||||
sdict["@LONG_ARGS@"] = ',\n\t'.join(as_strings)
|
||||
# So much more readable than string.join(map(string.join,zip(...))))
|
||||
sdict["@ERROR_ARGS@"] = string.join(list(map(get_error_arg, types)), ", ")
|
||||
if cbktypes is not None:
|
||||
sdict["@CBK_ERROR_ARGS@"] = string.join(list(map(
|
||||
get_error_arg, cbktypes)), ", ")
|
||||
sdict["@ERROR_ARGS@"] = ', '.join(list(map(get_error_arg, types)))
|
||||
if cbktypes is not None:
|
||||
sdict["@CBK_ERROR_ARGS@"] = ', '.join(list(map(get_error_arg, cbktypes)))
|
||||
return sdict
|
||||
|
||||
def generate (tmpl, name, subs):
|
||||
@ -735,24 +734,24 @@ def generate (tmpl, name, subs):
|
||||
if name == "writev":
|
||||
# More spurious inconsistency.
|
||||
text = text.replace("@UPNAME@", "WRITE")
|
||||
elif name == "readv":
|
||||
text = text.replace("@UPNAME@", "READ")
|
||||
elif name == "readv":
|
||||
text = text.replace("@UPNAME@", "READ")
|
||||
else:
|
||||
text = text.replace("@UPNAME@", name.upper())
|
||||
for old, new in subs[name].iteritems():
|
||||
for old, new in subs[name].items():
|
||||
text = text.replace(old, new)
|
||||
# TBD: reindent/reformat the result for maximum readability.
|
||||
return text
|
||||
return text
|
||||
|
||||
fop_subs = {}
|
||||
cbk_subs = {}
|
||||
|
||||
for name, args in ops.iteritems():
|
||||
for name, args in ops.items():
|
||||
|
||||
# Create the necessary substitution strings for fops.
|
||||
arg_names = [ a[1] for a in args if a[0] == 'fop-arg']
|
||||
arg_types = [ a[2] for a in args if a[0] == 'fop-arg']
|
||||
cbk_types = [ a[2] for a in args if a[0] == 'cbk-arg']
|
||||
cbk_types = [ a[2] for a in args if a[0] == 'cbk-arg']
|
||||
fop_subs[name] = get_subs(arg_names, arg_types, cbk_types)
|
||||
|
||||
# Same thing for callbacks.
|
||||
|
@ -73,7 +73,7 @@ def get_special_subs (args):
|
||||
|
||||
def gen_functions ():
|
||||
code = ""
|
||||
for name, value in ops.iteritems():
|
||||
for name, value in ops.items():
|
||||
if "journal" not in [ x[0] for x in value ]:
|
||||
continue
|
||||
fop_subs[name]["@FUNCTION_BODY@"] = get_special_subs(value)
|
||||
@ -83,7 +83,7 @@ def gen_functions ():
|
||||
|
||||
def gen_cases ():
|
||||
code = ""
|
||||
for name, value in ops.iteritems():
|
||||
for name, value in ops.items():
|
||||
if "journal" not in [ x[0] for x in value ]:
|
||||
continue
|
||||
# Add the CASE fragment for this fop.
|
||||
|
@ -310,7 +310,7 @@ selective_generate = {
|
||||
|
||||
def gen_fdl ():
|
||||
entrypoints = []
|
||||
for name, value in ops.iteritems():
|
||||
for name, value in ops.items():
|
||||
if "journal" not in [ x[0] for x in value ]:
|
||||
continue
|
||||
|
||||
|
@ -142,14 +142,14 @@ def get_special_subs (name, args, fop_type):
|
||||
# is not stored in or read from the journal. There are other ways to
|
||||
# do that, but this is the only place we need anything similar and we
|
||||
# already have to treat it as a special case so this is simplest.
|
||||
s_args_str = 'fd, &vector, 1, off, iobref, flags, &preop, &postop, xdata'
|
||||
s_args_str = 'fd, &vector, 1, off, iobref, flags, &preop, &postop, xdata'
|
||||
elif name == 'symlink':
|
||||
# Swap 'linkpath' and 'loc'.
|
||||
s_args_str = '&loc, linkpath, &iatt, xdata'
|
||||
elif name == 'xattrop':
|
||||
s_args_str = '&loc, flags, dict, xdata, NULL'
|
||||
elif name == 'fxattrop':
|
||||
s_args_str = 'fd, flags, dict, xdata, NULL'
|
||||
elif name == 'xattrop':
|
||||
s_args_str = '&loc, flags, dict, xdata, NULL'
|
||||
elif name == 'fxattrop':
|
||||
s_args_str = 'fd, flags, dict, xdata, NULL'
|
||||
else:
|
||||
s_args_str = string.join (s_args, ", ")
|
||||
return code, links, s_args_str, cleanups
|
||||
@ -162,7 +162,7 @@ def get_special_subs (name, args, fop_type):
|
||||
# an error is detected. This will probably get messy.
|
||||
def gen_functions ():
|
||||
code = ""
|
||||
for name, value in ops.iteritems():
|
||||
for name, value in ops.items():
|
||||
fop_type = [ x[1] for x in value if x[0] == "journal" ]
|
||||
if not fop_type:
|
||||
continue
|
||||
@ -184,7 +184,7 @@ def gen_functions ():
|
||||
|
||||
def gen_cases ():
|
||||
code = ""
|
||||
for name, value in ops.iteritems():
|
||||
for name, value in ops.items():
|
||||
if "journal" not in [ x[0] for x in value ]:
|
||||
continue
|
||||
# Add the CASE fragment for this fop.
|
||||
|
@ -14,7 +14,7 @@ from generator import ops, fop_subs, cbk_subs, generate
|
||||
# We really want the callback argument list, even when we're generating fop
|
||||
# code, so we propagate here.
|
||||
# TBD: this should probably be right in generate.py
|
||||
for k, v in cbk_subs.iteritems():
|
||||
for k, v in cbk_subs.items():
|
||||
fop_subs[k]['@ERROR_ARGS@'] = v['@ERROR_ARGS@']
|
||||
|
||||
# Stolen from old codegen.py
|
||||
@ -29,18 +29,18 @@ def load_templates (path):
|
||||
m = tmpl_re.match(line)
|
||||
if m:
|
||||
if t_name:
|
||||
templates[t_name] = string.join(t_contents, '')
|
||||
templates[t_name] = ''.join(t_contents)
|
||||
t_name = m.group(1).strip()
|
||||
t_contents = []
|
||||
elif t_name:
|
||||
t_contents.append(line)
|
||||
if t_name:
|
||||
templates[t_name] = string.join(t_contents, '')
|
||||
templates[t_name] = ''.join(t_contents)
|
||||
return templates
|
||||
|
||||
# Stolen from gen_fdl.py
|
||||
def gen_client (templates):
|
||||
for name, value in ops.iteritems():
|
||||
for name, value in ops.items():
|
||||
if name == 'getspec':
|
||||
# It's not real if it doesn't have a stub function.
|
||||
continue
|
||||
|
@ -19,7 +19,7 @@ from generator import ops, fop_subs, cbk_subs, generate
|
||||
# We really want the callback argument list, even when we're generating fop
|
||||
# code, so we propagate here.
|
||||
# TBD: this should probably be right in generate.py
|
||||
for k, v in cbk_subs.iteritems():
|
||||
for k, v in cbk_subs.items():
|
||||
fop_subs[k]['@ERROR_ARGS@'] = v['@ERROR_ARGS@']
|
||||
|
||||
# Stolen from old codegen.py
|
||||
@ -34,13 +34,13 @@ def load_templates (path):
|
||||
m = tmpl_re.match(line)
|
||||
if m:
|
||||
if t_name:
|
||||
templates[t_name] = string.join(t_contents, '')
|
||||
templates[t_name] = ''.join(t_contents)
|
||||
t_name = m.group(1).strip()
|
||||
t_contents = []
|
||||
elif t_name:
|
||||
t_contents.append(line)
|
||||
if t_name:
|
||||
templates[t_name] = string.join(t_contents, '')
|
||||
templates[t_name] = ''.join(t_contents)
|
||||
return templates
|
||||
|
||||
# We need two types of templates. The first, for pure read operations, just
|
||||
|
@ -16,7 +16,7 @@ cs_@NAME@ (call_frame_t *frame, xlator_t *this,
|
||||
"""
|
||||
|
||||
def gen_defaults():
|
||||
for name, value in ops.iteritems():
|
||||
for name, value in ops.items():
|
||||
if name == 'getspec':
|
||||
continue
|
||||
print(generate(OP_FOP_TEMPLATE, name, fop_subs))
|
||||
|
@ -2317,6 +2317,41 @@ mem_acct_init (xlator_t *this)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void
|
||||
py_error_log(const char *name, PyObject *pystr)
|
||||
{
|
||||
#if PY_MAJOR_VERSION > 2
|
||||
char scr[256];
|
||||
if (PyUnicode_Check(pystr)) {
|
||||
PyObject *tmp =
|
||||
PyUnicode_AsEncodedString(pystr, "UTF-8", "strict");
|
||||
if (tmp != NULL) {
|
||||
strncpy(scr, PyBytes_AS_STRING(pystr), sizeof(scr));
|
||||
Py_DECREF(tmp);
|
||||
} else {
|
||||
strncpy(scr, "string encoding error", sizeof(scr));
|
||||
}
|
||||
} else if (PyBytes_Check(pystr)) {
|
||||
strncpy(scr, PyBytes_AS_STRING(pystr), sizeof(scr));
|
||||
} else {
|
||||
strncpy(scr, "string encoding error", sizeof(scr));
|
||||
}
|
||||
gf_log (name, GF_LOG_ERROR, "Python error: %s", scr);
|
||||
#else
|
||||
gf_log (name, GF_LOG_ERROR, "Python error: %s", PyString_AsString(pystr));
|
||||
#endif
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
encode (const char *str)
|
||||
{
|
||||
#if PY_MAJOR_VERSION > 2
|
||||
return PyUnicode_FromString(str);
|
||||
#else
|
||||
return PyString_FromString(str);
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t
|
||||
init (xlator_t *this)
|
||||
{
|
||||
@ -2385,17 +2420,16 @@ init (xlator_t *this)
|
||||
|
||||
/* Adjust python's path */
|
||||
syspath = PySys_GetObject("path");
|
||||
path = PyString_FromString(GLUSTER_PYTHON_PATH);
|
||||
path = encode(GLUSTER_PYTHON_PATH);
|
||||
PyList_Append(syspath, path);
|
||||
Py_DECREF(path);
|
||||
|
||||
py_mod_name = PyString_FromString(module_name);
|
||||
py_mod_name = encode(module_name);
|
||||
if (!py_mod_name) {
|
||||
gf_log (this->name, GF_LOG_ERROR, "could not create name");
|
||||
if (PyErr_Occurred()) {
|
||||
PyErr_Fetch (&error_type, &error_msg, &error_bt);
|
||||
gf_log (this->name, GF_LOG_ERROR, "Python error: %s",
|
||||
PyString_AsString(error_msg));
|
||||
py_error_log(this->name, error_msg);
|
||||
}
|
||||
goto *err_cleanup;
|
||||
}
|
||||
@ -2408,8 +2442,7 @@ init (xlator_t *this)
|
||||
module_name);
|
||||
if (PyErr_Occurred()) {
|
||||
PyErr_Fetch (&error_type, &error_msg, &error_bt);
|
||||
gf_log (this->name, GF_LOG_ERROR, "Python error: %s",
|
||||
PyString_AsString(error_msg));
|
||||
py_error_log (this->name, error_msg);
|
||||
}
|
||||
goto *err_cleanup;
|
||||
}
|
||||
@ -2421,8 +2454,7 @@ init (xlator_t *this)
|
||||
gf_log (this->name, GF_LOG_ERROR, "missing init func");
|
||||
if (PyErr_Occurred()) {
|
||||
PyErr_Fetch (&error_type, &error_msg, &error_bt);
|
||||
gf_log (this->name, GF_LOG_ERROR, "Python error: %s",
|
||||
PyString_AsString(error_msg));
|
||||
py_error_log (this->name, error_msg);
|
||||
}
|
||||
goto *err_cleanup;
|
||||
}
|
||||
@ -2433,8 +2465,7 @@ init (xlator_t *this)
|
||||
gf_log (this->name, GF_LOG_ERROR, "could not create args");
|
||||
if (PyErr_Occurred()) {
|
||||
PyErr_Fetch (&error_type, &error_msg, &error_bt);
|
||||
gf_log (this->name, GF_LOG_ERROR, "Python error: %s",
|
||||
PyString_AsString(error_msg));
|
||||
py_error_log (this->name, error_msg);
|
||||
}
|
||||
goto *err_cleanup;
|
||||
}
|
||||
@ -2447,8 +2478,7 @@ init (xlator_t *this)
|
||||
gf_log (this->name, GF_LOG_ERROR, "Python init failed");
|
||||
if (PyErr_Occurred()) {
|
||||
PyErr_Fetch (&error_type, &error_msg, &error_bt);
|
||||
gf_log (this->name, GF_LOG_ERROR, "Python error: %s",
|
||||
PyString_AsString(error_msg));
|
||||
py_error_log (this->name, error_msg);
|
||||
}
|
||||
goto *err_cleanup;
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ utime_ops = ['fallocate', 'zerofill', 'opendir', 'mknod', 'mkdir',
|
||||
'readv', 'writev', 'setattr', 'fsetattr']
|
||||
|
||||
def gen_defaults():
|
||||
for name, value in ops.iteritems():
|
||||
for name, value in ops.items():
|
||||
if name in utime_ops:
|
||||
print(generate(OP_FOP_TEMPLATE, name, fop_subs))
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user