summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaleb S. KEITHLEY <kkeithle@redhat.com>2018-07-02 08:18:54 -0400
committerAmar Tumballi <amarts@redhat.com>2018-07-09 03:38:36 +0000
commit55d1b0531a0b322a1b851fc921fd6fdf25d26331 (patch)
treef3d8c84e4d27fb8894a9c921a9a4ed06257cf80e
parentdab12ce093628860bf43c3e0c7eaf9099cf7a78f (diff)
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>
-rw-r--r--events/src/glustereventsd.py2
-rwxr-xr-xextras/create_new_xlator/generate_xlator.py2
-rwxr-xr-xextras/failed-tests.py2
-rwxr-xr-xextras/git-branch-diff.py4
-rwxr-xr-xextras/prot_filter.py2
-rwxr-xr-xextras/rebalance.py2
-rw-r--r--extras/volfilter.py2
-rw-r--r--geo-replication/src/peer_mountbroker.in21
-rw-r--r--geo-replication/src/peer_mountbroker.py.in7
-rw-r--r--geo-replication/syncdaemon/resource.py2
-rw-r--r--libglusterfs/src/gen-defaults.py10
-rwxr-xr-xlibglusterfs/src/generator.py209
-rwxr-xr-xxlators/experimental/fdl/src/gen_dumper.py4
-rwxr-xr-xxlators/experimental/fdl/src/gen_fdl.py2
-rwxr-xr-xxlators/experimental/fdl/src/gen_recon.py14
-rwxr-xr-xxlators/experimental/jbr-client/src/gen-fops.py8
-rwxr-xr-xxlators/experimental/jbr-server/src/gen-fops.py6
-rw-r--r--xlators/features/cloudsync/src/cloudsync-fops-h.py2
-rw-r--r--xlators/features/glupy/src/glupy.c54
-rw-r--r--xlators/features/utime/src/utime-gen-fops-h.py2
20 files changed, 195 insertions, 162 deletions
diff --git a/events/src/glustereventsd.py b/events/src/glustereventsd.py
index 014f5a0009d..b61d1a1b28b 100644
--- a/events/src/glustereventsd.py
+++ b/events/src/glustereventsd.py
@@ -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)
diff --git a/extras/create_new_xlator/generate_xlator.py b/extras/create_new_xlator/generate_xlator.py
index 0a54089080c..67e2e9c6e17 100755
--- a/extras/create_new_xlator/generate_xlator.py
+++ b/extras/create_new_xlator/generate_xlator.py
@@ -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
diff --git a/extras/failed-tests.py b/extras/failed-tests.py
index 54406f91ad3..0f5ad38aa09 100755
--- a/extras/failed-tests.py
+++ b/extras/failed-tests.py
@@ -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]):
diff --git a/extras/git-branch-diff.py b/extras/git-branch-diff.py
index 99cc707b837..3c29e35bd7b 100755
--- a/extras/git-branch-diff.py
+++ b/extras/git-branch-diff.py
@@ -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,
diff --git a/extras/prot_filter.py b/extras/prot_filter.py
index e2b81218f40..3baa27c3f6d 100755
--- a/extras/prot_filter.py
+++ b/extras/prot_filter.py
@@ -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(
diff --git a/extras/rebalance.py b/extras/rebalance.py
index 32ca067b32d..0023f9970a8 100755
--- a/extras/rebalance.py
+++ b/extras/rebalance.py
@@ -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))
diff --git a/extras/volfilter.py b/extras/volfilter.py
index da0a0e62ddb..ea4bf22a440 100644
--- a/extras/volfilter.py
+++ b/extras/volfilter.py
@@ -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(
diff --git a/geo-replication/src/peer_mountbroker.in b/geo-replication/src/peer_mountbroker.in
index 89bb0c0ba6f..5d19db88b80 100644
--- a/geo-replication/src/peer_mountbroker.in
+++ b/geo-replication/src/peer_mountbroker.in
@@ -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)
diff --git a/geo-replication/src/peer_mountbroker.py.in b/geo-replication/src/peer_mountbroker.py.in
index 8f2367b7d49..d101de561e4 100644
--- a/geo-replication/src/peer_mountbroker.py.in
+++ b/geo-replication/src/peer_mountbroker.py.in
@@ -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
diff --git a/geo-replication/syncdaemon/resource.py b/geo-replication/syncdaemon/resource.py
index e261812f39f..575a6605393 100644
--- a/geo-replication/syncdaemon/resource.py
+++ b/geo-replication/syncdaemon/resource.py
@@ -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(
diff --git a/libglusterfs/src/gen-defaults.py b/libglusterfs/src/gen-defaults.py
index ccd5f5fc6c9..0c96fd0c176 100644
--- a/libglusterfs/src/gen-defaults.py
+++ b/libglusterfs/src/gen-defaults.py
@@ -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():
diff --git a/libglusterfs/src/generator.py b/libglusterfs/src/generator.py
index 3b7df986f1f..64db4e8c479 100755
--- a/libglusterfs/src/generator.py
+++ b/libglusterfs/src/generator.py
@@ -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.
diff --git a/xlators/experimental/fdl/src/gen_dumper.py b/xlators/experimental/fdl/src/gen_dumper.py
index 95313adefcc..c15f7c8870d 100755
--- a/xlators/experimental/fdl/src/gen_dumper.py
+++ b/xlators/experimental/fdl/src/gen_dumper.py
@@ -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.
diff --git a/xlators/experimental/fdl/src/gen_fdl.py b/xlators/experimental/fdl/src/gen_fdl.py
index e8f97dc9957..8647ba7b6f1 100755
--- a/xlators/experimental/fdl/src/gen_fdl.py
+++ b/xlators/experimental/fdl/src/gen_fdl.py
@@ -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
diff --git a/xlators/experimental/fdl/src/gen_recon.py b/xlators/experimental/fdl/src/gen_recon.py
index ff5b5e16066..c6b3b02a2fe 100755
--- a/xlators/experimental/fdl/src/gen_recon.py
+++ b/xlators/experimental/fdl/src/gen_recon.py
@@ -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.
diff --git a/xlators/experimental/jbr-client/src/gen-fops.py b/xlators/experimental/jbr-client/src/gen-fops.py
index 1962d2f8067..47b339910d4 100755
--- a/xlators/experimental/jbr-client/src/gen-fops.py
+++ b/xlators/experimental/jbr-client/src/gen-fops.py
@@ -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
diff --git a/xlators/experimental/jbr-server/src/gen-fops.py b/xlators/experimental/jbr-server/src/gen-fops.py
index c4c87556cb3..bf6ff912d0c 100755
--- a/xlators/experimental/jbr-server/src/gen-fops.py
+++ b/xlators/experimental/jbr-server/src/gen-fops.py
@@ -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
diff --git a/xlators/features/cloudsync/src/cloudsync-fops-h.py b/xlators/features/cloudsync/src/cloudsync-fops-h.py
index 37dfa5b10be..8a97cd0fcdd 100644
--- a/xlators/features/cloudsync/src/cloudsync-fops-h.py
+++ b/xlators/features/cloudsync/src/cloudsync-fops-h.py
@@ -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))
diff --git a/xlators/features/glupy/src/glupy.c b/xlators/features/glupy/src/glupy.c
index 46d1af5533a..bacccfef686 100644
--- a/xlators/features/glupy/src/glupy.c
+++ b/xlators/features/glupy/src/glupy.c
@@ -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;
}
diff --git a/xlators/features/utime/src/utime-gen-fops-h.py b/xlators/features/utime/src/utime-gen-fops-h.py
index 9c297062929..e04cbd41293 100644
--- a/xlators/features/utime/src/utime-gen-fops-h.py
+++ b/xlators/features/utime/src/utime-gen-fops-h.py
@@ -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))