Blame SOURCES/blktrace-python3.patch

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