diff options
| author | Kaleb S. KEITHLEY <kkeithle@redhat.com> | 2018-06-07 12:27:23 -0400 | 
|---|---|---|
| committer | Kaleb S. KEITHLEY <kkeithle@redhat.com> | 2018-06-07 12:37:43 -0400 | 
| commit | ee75c5abc41f43aa79b5e758e43f70a92672d3a2 (patch) | |
| tree | 67433fa9021a2f85b861f8dbee0df3a46ae04e45 /extras | |
| parent | d788cc59b1cd4278ca0b8b2d9f6fe93f80550af3 (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/, and
    https://review.gluster.org/#/c/20104/
    https://review.gluster.org/#/c/20162/
This patch changes uses of map() and raise(), and a few cases of print()
that were overlooked in the prior patch that fixed print.
Note: Fedora packaging guidelines require explicit shebangs, so 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, idioms, numliterals, set_literal, types, urllib,
zip, map, and raise 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, intern, itertools, metaclass,
methodattrs, ne, next, nonzero, operator, paren, raw_input, reduce,
reload, renames, repr, standarderror, sys_exc, throw, tuple_params,
xreadlines.
Change-Id: Id62ea491e4ab5dd390075c5c6d9d889cf6f9da27
updates: #411
Signed-off-by: Kaleb S. KEITHLEY <kkeithle@redhat.com>
Diffstat (limited to 'extras')
| -rwxr-xr-x | extras/create_new_xlator/generate_xlator.py | 4 | ||||
| -rwxr-xr-x | extras/prot_filter.py | 8 | ||||
| -rwxr-xr-x | extras/quota/quota_fsck.py | 31 | ||||
| -rw-r--r-- | extras/volfilter.py | 10 | 
4 files changed, 27 insertions, 26 deletions
diff --git a/extras/create_new_xlator/generate_xlator.py b/extras/create_new_xlator/generate_xlator.py index 1647efa2618..a0b1e691c17 100755 --- a/extras/create_new_xlator/generate_xlator.py +++ b/extras/create_new_xlator/generate_xlator.py @@ -38,7 +38,7 @@ def get_param(names, types):          # 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 = map(string.join, as_tuples) +        as_strings = list(map(string.join, as_tuples))          # Join all of those into one big string.          return string.join(as_strings, ",\n\t") @@ -58,7 +58,7 @@ def generate(tmpl, name, table):          #Args are (var1, var2,...)          sdict["@WIND_ARGS@"] = string.join(w_arg_names, ", ")          sdict["@UNWIND_ARGS@"] = string.join(u_arg_names, ", ") -        sdict["@ERROR_ARGS@"] = string.join(map(get_error_arg, u_arg_types), ", ") +        sdict["@ERROR_ARGS@"] = string.join(list(map(get_error_arg, u_arg_types)), ", ")          sdict["@WIND_PARAMS@"] = get_param(w_arg_names, w_arg_types)          sdict["@UNWIND_PARAMS@"] = get_param(u_arg_names, u_arg_types)          sdict["@FUNC_PARAMS@"] = get_param(fn_arg_names, fn_arg_types) diff --git a/extras/prot_filter.py b/extras/prot_filter.py index 0e3e72cf461..bc61c097faf 100755 --- a/extras/prot_filter.py +++ b/extras/prot_filter.py @@ -58,11 +58,11 @@ def load (path):              continue          if text[0] == "volume":              if xlator: -                raise RuntimeError, "nested volume definition" +                raise RuntimeError("nested volume definition")              xlator = Translator(text[1])              continue          if not xlator: -            raise RuntimeError, "text outside volume definition" +            raise RuntimeError("text outside volume definition")          if text[0] == "type":              xlator.xl_type = text[1]              continue @@ -78,9 +78,9 @@ def load (path):              last_xlator = xlator              xlator = None              continue -        raise RuntimeError, "unrecognized keyword %s" % text[0] +        raise RuntimeError("unrecognized keyword %s" % text[0])      if xlator: -        raise RuntimeError, "unclosed volume definition" +        raise RuntimeError("unclosed volume definition")      return all_xlators, last_xlator  def generate (graph, last, stream=sys.stdout): diff --git a/extras/quota/quota_fsck.py b/extras/quota/quota_fsck.py index 0ca93a4b7d9..e2bb580dd5d 100755 --- a/extras/quota/quota_fsck.py +++ b/extras/quota/quota_fsck.py @@ -12,6 +12,7 @@     later), or the GNU General Public License, version 2 (GPLv2), in all     cases as published by the Free Software Foundation.  ''' +from __future__ import print_function  import os, sys, re  from stat import *  import subprocess @@ -51,17 +52,17 @@ epilog_msg='''  def print_msg(log_type, path, xattr_dict = {}, stbuf = "", dir_size = None):      if log_type == QUOTA_VERBOSE: -        print '%-24s %-60s\nxattr_values: %s\n%s\n' % ("Verbose", path ,  xattr_dict, stbuf) +        print('%-24s %-60s\nxattr_values: %s\n%s\n' % {"Verbose", path ,  xattr_dict, stbuf})      elif log_type == QUOTA_META_ABSENT: -        print '%-24s %-60s\n%s\n' % ("Quota-Meta Absent", path , xattr_dict) +        print('%-24s %-60s\n%s\n' % {"Quota-Meta Absent", path , xattr_dict})      elif log_type == QUOTA_SIZE_MISMATCH: -        print "mismatch" +        print("mismatch")          if dir_size is not None: -            print '%24s %60s %12s %12s' % ("Size Mismatch",path , xattr_dict['contri_size'], -                   dir_size) +            print('%24s %60s %12s %12s' % {"Size Mismatch", path , xattr_dict['contri_size'], +                   dir_size})          else: -            print '%-24s %-60s %-12i %-12i' % ("Size Mismatch",path , xattr_dict['contri_size'], -                   stbuf.st_size) +            print('%-24s %-60s %-12i %-12i' % {"Size Mismatch", path , xattr_dict['contri_size'], +                   stbuf.st_size})  def size_differs_lot(s1, s2):      ''' @@ -119,12 +120,12 @@ def fix_xattr(file_name, mark_dirty):      if mnt_path is None:          return      if mark_dirty: -        print "MARKING DIRTY: " + file_name +        print("MARKING DIRTY: " + file_name)          out = subprocess.check_output (["/usr/bin/setfattr", "-n",                                         "trusted.glusterfs.quota.dirty",                                         "-v", IS_DIRTY, file_name])      rel_path = os.path.relpath(file_name, brick_path) -    print "stat on "  + mnt_path + "/" + rel_path +    print("stat on "  + mnt_path + "/" + rel_path)      stbuf = os.lstat(mnt_path + "/" + rel_path)      obj_fix_count += 1 @@ -175,7 +176,7 @@ def get_quota_xattr_brick(dpath):                  xattr_dict['version'] = xattr_version              else:                  if xattr_version != xattr_dict['version']: -                   print "Multiple xattr version found" +                   print("Multiple xattr version found")              cur_parent = xattr_key.split(".")[3] @@ -280,7 +281,7 @@ def walktree(t_dir, hard_link_dict):          if S_ISDIR(stbuf.st_mode):              # It's a directory, recurse into it              if entry == '.glusterfs': -                print "skipping " + pathname +                print("skipping " + pathname)                  continue              descendent_hardlinks = {}              subtree_size = walktree(pathname, descendent_hardlinks) @@ -317,7 +318,7 @@ def walktree(t_dir, hard_link_dict):          else:              # Unknown file type, print a message -            print 'Skipping %s, due to file mode' % pathname +            print('Skipping %s, due to file mode' % (pathname))      if t_dir not in aggr_size:          aggr_size[t_dir] = 0 @@ -372,7 +373,7 @@ if __name__ == '__main__':      else:          walktree(brick_path, hard_link_dict) -    print "Files verified : " + str(file_count) -    print "Directories verified : " + str(dir_count) +    print("Files verified : " + str(file_count)) +    print("Directories verified : " + str(dir_count))      if mnt_path is not None: -        print "Objects Fixed : " + str(obj_fix_count) +        print("Objects Fixed : " + str(obj_fix_count)) diff --git a/extras/volfilter.py b/extras/volfilter.py index 79be8f7c378..515a6408bb9 100644 --- a/extras/volfilter.py +++ b/extras/volfilter.py @@ -99,11 +99,11 @@ def load (path):  			continue  		if text[0] == "volume":  			if xlator: -				raise RuntimeError, "nested volume definition" +				raise RuntimeError("nested volume definition")  			xlator = Translator(text[1])  			continue  		if not xlator: -			raise RuntimeError, "text outside volume definition" +			raise RuntimeError("text outside volume definition")  		if text[0] == "type":  			xlator.type = text[1]  			continue @@ -119,9 +119,9 @@ def load (path):  			last_xlator = xlator  			xlator = None  			continue -		raise RuntimeError, "unrecognized keyword %s" % text[0] +		raise RuntimeError("unrecognized keyword %s" % text[0])  	if xlator: -		raise RuntimeError, "unclosed volume definition" +		raise RuntimeError("unclosed volume definition")  	return all_xlators, last_xlator  def generate (graph, last, stream=sys.stdout): @@ -157,7 +157,7 @@ def push_filter (graph, old_xl, filt_type, opts={}):  def delete (graph, victim):  	if len(victim.subvols) != 1: -		raise RuntimeError, "attempt to delete non-unary translator" +		raise RuntimeError("attempt to delete non-unary translator")  	for xl in graph.itervalues():  		while xl.subvols.count(victim):  			i = xl.subvols.index(victim)  | 
