Blame SOURCES/blktrace-python3.patch

f31040
make btt scripts python3-ready
f31040
f31040
Many distributions are moving to python3 by default.  Here's
f31040
an attempt to make the python scripts in blktrace python3-ready.
f31040
f31040
Most of this was done with automated tools.  I hand fixed some
f31040
space-vs tab issues, and cast an array index to integer.  It
f31040
passes rudimentary testing when run under python2.7 as well
f31040
as python3.
f31040
f31040
This doesn't do anything with the shebangs, it leaves them both
f31040
invoking whatever "env python" coughs up on the system.
f31040
f31040
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
f31040
---
f31040
f31040
I am not a python guru at all. Happy to have review by anyone more
f31040
pythonic than I am.  Hopefully this helps at least move things
f31040
toward python3-readiness.  Thanks!
f31040
f31040
Index: blktrace-1.2.0/btt/bno_plot.py
f31040
===================================================================
f31040
--- blktrace-1.2.0.orig/btt/bno_plot.py
f31040
+++ blktrace-1.2.0/btt/bno_plot.py
f31040
@@ -1,4 +1,4 @@
f31040
-#! /usr/bin/env python
f31040
+#!/usr/bin/python3
f31040
 #
f31040
 # btt blkno plotting interface
f31040
 #
f31040
@@ -38,6 +38,8 @@ automatically push the keys under the gr
f31040
 To exit the plotter, enter 'quit' or ^D at the 'gnuplot> ' prompt.
f31040
 """
f31040
 
f31040
+from __future__ import absolute_import
f31040
+from __future__ import print_function
f31040
 import getopt, glob, os, sys, tempfile
f31040
 
f31040
 verbose	= 0
f31040
@@ -60,14 +62,14 @@ def parse_args(in_args):
f31040
 
f31040
 	try:
f31040
 		(opts, args) = getopt.getopt(in_args, s_opts, l_opts)
f31040
-	except getopt.error, msg:
f31040
-		print >>sys.stderr, msg
f31040
-		print >>sys.stderr, __doc__
f31040
+	except getopt.error as msg:
f31040
+		print(msg, file=sys.stderr)
f31040
+		print(__doc__, file=sys.stderr)
f31040
 		sys.exit(1)
f31040
 
f31040
 	for (o, a) in opts:
f31040
 		if o in ('-h', '--help'):
f31040
-			print __doc__
f31040
+			print(__doc__)
f31040
 			sys.exit(0)
f31040
 		elif o in ('-v', '--verbose'):
f31040
 			verbose += 1
f31040
@@ -84,10 +86,10 @@ if __name__ == '__main__':
f31040
 	(bnos, keys_below) = parse_args(sys.argv[1:])
f31040
 
f31040
 	if verbose:
f31040
-		print 'Using files:',
f31040
-		for bno in bnos: print bno,
f31040
-		if keys_below:	print '\nKeys are to be placed below graph'
f31040
-		else:		print ''
f31040
+		print('Using files:', end=' ')
f31040
+		for bno in bnos: print(bno, end=' ')
f31040
+		if keys_below:	print('\nKeys are to be placed below graph')
f31040
+		else:		print('')
f31040
 
f31040
 	tmpdir = tempfile.mktemp()
f31040
 	os.mkdir(tmpdir)
f31040
@@ -99,7 +101,7 @@ if __name__ == '__main__':
f31040
 		fo = open(t, 'w')
f31040
 		for line in open(f, 'r'):
f31040
 			fld = line.split(None)
f31040
-			print >>fo, fld[0], fld[1], int(fld[2])-int(fld[1])
f31040
+			print(fld[0], fld[1], int(fld[2])-int(fld[1]), file=fo)
f31040
 		fo.close()
f31040
 
f31040
 		t = t[t.rfind('/')+1:]
f31040
@@ -107,16 +109,16 @@ if __name__ == '__main__':
f31040
 		else:                plot_cmd = "%s,'%s'" % (plot_cmd, t)
f31040
 
f31040
 	fo = open('%s/plot.cmds' % tmpdir, 'w')
f31040
-	print >>fo, cmds
f31040
-	if len(bnos) > 10 or keys_below: print >>fo, 'set key below'
f31040
-	print >>fo, plot_cmd
f31040
+	print(cmds, file=fo)
f31040
+	if len(bnos) > 10 or keys_below: print('set key below', file=fo)
f31040
+	print(plot_cmd, file=fo)
f31040
 	fo.close()
f31040
 
f31040
 	pid = os.fork()
f31040
 	if pid == 0:
f31040
 		cmd = 'gnuplot %s/plot.cmds -' % tmpdir
f31040
 
f31040
-		if verbose: print 'Executing %s' % cmd
f31040
+		if verbose: print('Executing %s' % cmd)
f31040
 
f31040
 		os.chdir(tmpdir)
f31040
 		os.system(cmd)
f31040
Index: blktrace-1.2.0/btt/btt_plot.py
f31040
===================================================================
f31040
--- blktrace-1.2.0.orig/btt/btt_plot.py
f31040
+++ blktrace-1.2.0/btt/btt_plot.py
f31040
@@ -1,4 +1,4 @@
f31040
-#! /usr/bin/env python
f31040
+#!/usr/bin/python3
f31040
 #
f31040
 # btt_plot.py: Generate matplotlib plots for BTT generate data files
f31040
 #
f31040
@@ -55,6 +55,10 @@ Arguments:
f31040
   but the -o (--output) and -T (--title) options will be ignored.
f31040
 """
f31040
 
f31040
+from __future__ import absolute_import
f31040
+from __future__ import print_function
f31040
+import six
f31040
+from six.moves import range
f31040
 __author__ = 'Alan D. Brunelle <alan.brunelle@hp.com>'
f31040
 
f31040
 #------------------------------------------------------------------------------
f31040
@@ -82,7 +86,7 @@ get_base 	= lambda file: file[file.find(
f31040
 def fatal(msg):
f31040
 	"""Generate fatal error message and exit"""
f31040
 
f31040
-	print >>sys.stderr, 'FATAL: %s' % msg
f31040
+	print('FATAL: %s' % msg, file=sys.stderr)
f31040
 	sys.exit(1)
f31040
 
f31040
 #------------------------------------------------------------------------------
f31040
@@ -163,7 +167,7 @@ def get_data(files):
f31040
 		if not os.path.exists(file):
f31040
 			fatal('%s not found' % file)
f31040
 		elif verbose:
f31040
-			print 'Processing %s' % file
f31040
+			print('Processing %s' % file)
f31040
 
f31040
 		xs = []
f31040
 		ys = []
f31040
@@ -214,8 +218,8 @@ def parse_args(args):
f31040
 
f31040
 	try:
f31040
 		(opts, args) = getopt.getopt(args[1:], s_opts, l_opts)
f31040
-	except getopt.error, msg:
f31040
-		print >>sys.stderr, msg
f31040
+	except getopt.error as msg:
f31040
+		print(msg, file=sys.stderr)
f31040
 		fatal(__doc__)
f31040
 
f31040
 	for (o, a) in opts:
f31040
@@ -293,15 +297,15 @@ def generate_output(type, db):
f31040
 	def color(idx, style):
f31040
 		"""Returns a color/symbol type based upon the index passed."""
f31040
 
f31040
-                colors = [ 'b', 'g', 'r', 'c', 'm', 'y', 'k' ]
f31040
+		colors = [ 'b', 'g', 'r', 'c', 'm', 'y', 'k' ]
f31040
 		l_styles = [ '-', ':', '--', '-.' ]
f31040
 		m_styles = [ 'o', '+', '.', ',', 's', 'v', 'x', '<', '>' ]
f31040
 
f31040
 		color = colors[idx % len(colors)]
f31040
 		if style == 'line':
f31040
-			style = l_styles[(idx / len(l_styles)) % len(l_styles)]
f31040
+			style = l_styles[int((idx / len(l_styles)) % len(l_styles))]
f31040
 		elif style == 'marker':
f31040
-			style = m_styles[(idx / len(m_styles)) % len(m_styles)]
f31040
+			style = m_styles[int((idx / len(m_styles)) % len(m_styles))]
f31040
 
f31040
 		return '%s%s' % (color, style)
f31040
 
f31040
@@ -314,7 +318,7 @@ def generate_output(type, db):
f31040
 		ofile = '%s.png' % type
f31040
 
f31040
 	if verbose:
f31040
-		print 'Generating plot into %s' % ofile
f31040
+		print('Generating plot into %s' % ofile)
f31040
 
f31040
 	fig = plt.figure(figsize=plot_size)
f31040
 	ax = fig.add_subplot(111)
f31040
@@ -329,7 +333,7 @@ def generate_output(type, db):
f31040
 		legends = None
f31040
 
f31040
 	keys = []
f31040
-	for file in db.iterkeys():
f31040
+	for file in six.iterkeys(db):
f31040
 		if not file in ['min_x', 'max_x', 'min_y', 'max_y']:
f31040
 			keys.append(file)
f31040
 
f31040
f31040