Commit b14d3172 authored by Bas Zoetekouw's avatar Bas Zoetekouw

Make python script python3-compatible

parent e1359f06
......@@ -14,6 +14,7 @@ blktrace (1.2.0-1) UNRELEASED; urgency=medium
* Fix typo in README.Debian
* Don't parse changelog during build
* Add doc-base metadata for documentation
* Add python3 support for btt_plot.py and bno_plot.py
-- Bas Zoetekouw <bas@debian.org> Sat, 19 May 2018 21:49:22 +0200
......
......@@ -16,9 +16,9 @@ Vcs-Git: https://salsa.debian.org/debian/blktrace.git
Package: blktrace
Architecture: linux-any
Depends: ${misc:Depends},
${shlibs:Depends},
python
Depends: ${misc:Depends}
,${shlibs:Depends}
,python3
Recommends: libtheora-bin
,ffmpeg
,librsvg2-bin
......
Description: Make python script python3-compatible
Author: Bas Zoetekouw <bas@debian.org>
Origin: other, automatically generated by 2to3
Last-Update: 2018-05-20
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/btt/bno_plot.py
+++ b/btt/bno_plot.py
@@ -1,4 +1,4 @@
-#! /usr/bin/env python
+#! /usr/bin/python3
#
# btt blkno plotting interface
#
@@ -38,6 +38,7 @@
To exit the plotter, enter 'quit' or ^D at the 'gnuplot> ' prompt.
"""
+from __future__ import print_function
import getopt, glob, os, sys, tempfile
verbose = 0
@@ -60,14 +61,14 @@
try:
(opts, args) = getopt.getopt(in_args, s_opts, l_opts)
- except getopt.error, msg:
- print >>sys.stderr, msg
- print >>sys.stderr, __doc__
+ except getopt.error as msg:
+ print(msg, file=sys.stderr)
+ print(__doc__, file=sys.stderr)
sys.exit(1)
for (o, a) in opts:
if o in ('-h', '--help'):
- print __doc__
+ print(__doc__)
sys.exit(0)
elif o in ('-v', '--verbose'):
verbose += 1
@@ -84,10 +85,10 @@
(bnos, keys_below) = parse_args(sys.argv[1:])
if verbose:
- print 'Using files:',
- for bno in bnos: print bno,
- if keys_below: print '\nKeys are to be placed below graph'
- else: print ''
+ print('Using files:', end=' ')
+ for bno in bnos: print(bno, end=' ')
+ if keys_below: print('\nKeys are to be placed below graph')
+ else: print('')
tmpdir = tempfile.mktemp()
os.mkdir(tmpdir)
@@ -99,7 +100,7 @@
fo = open(t, 'w')
for line in open(f, 'r'):
fld = line.split(None)
- print >>fo, fld[0], fld[1], int(fld[2])-int(fld[1])
+ print(fld[0], fld[1], int(fld[2])-int(fld[1]), file=fo)
fo.close()
t = t[t.rfind('/')+1:]
@@ -107,16 +108,16 @@
else: plot_cmd = "%s,'%s'" % (plot_cmd, t)
fo = open('%s/plot.cmds' % tmpdir, 'w')
- print >>fo, cmds
- if len(bnos) > 10 or keys_below: print >>fo, 'set key below'
- print >>fo, plot_cmd
+ print(cmds, file=fo)
+ if len(bnos) > 10 or keys_below: print('set key below', file=fo)
+ print(plot_cmd, file=fo)
fo.close()
pid = os.fork()
if pid == 0:
cmd = 'gnuplot %s/plot.cmds -' % tmpdir
- if verbose: print 'Executing %s' % cmd
+ if verbose: print('Executing %s' % cmd)
os.chdir(tmpdir)
os.system(cmd)
--- a/btt/btt_plot.py
+++ b/btt/btt_plot.py
@@ -1,4 +1,4 @@
-#! /usr/bin/env python
+#! /usr/bin/python3
#
# btt_plot.py: Generate matplotlib plots for BTT generate data files
#
@@ -18,6 +18,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
+from __future__ import print_function
"""
btt_plot.py: Generate matplotlib plots for BTT generated data files
@@ -82,7 +83,7 @@
def fatal(msg):
"""Generate fatal error message and exit"""
- print >>sys.stderr, 'FATAL: %s' % msg
+ print('FATAL: %s' % msg, file=sys.stderr)
sys.exit(1)
#------------------------------------------------------------------------------
@@ -163,7 +164,7 @@
if not os.path.exists(file):
fatal('%s not found' % file)
elif verbose:
- print 'Processing %s' % file
+ print('Processing %s' % file)
xs = []
ys = []
@@ -214,8 +215,8 @@
try:
(opts, args) = getopt.getopt(args[1:], s_opts, l_opts)
- except getopt.error, msg:
- print >>sys.stderr, msg
+ except getopt.error as msg:
+ print(msg, file=sys.stderr)
fatal(__doc__)
for (o, a) in opts:
@@ -293,7 +294,7 @@
def color(idx, style):
"""Returns a color/symbol type based upon the index passed."""
- colors = [ 'b', 'g', 'r', 'c', 'm', 'y', 'k' ]
+ colors = [ 'b', 'g', 'r', 'c', 'm', 'y', 'k' ]
l_styles = [ '-', ':', '--', '-.' ]
m_styles = [ 'o', '+', '.', ',', 's', 'v', 'x', '<', '>' ]
@@ -314,7 +315,7 @@
ofile = '%s.png' % type
if verbose:
- print 'Generating plot into %s' % ofile
+ print('Generating plot into %s' % ofile)
fig = plt.figure(figsize=plot_size)
ax = fig.add_subplot(111)
@@ -329,7 +330,7 @@
legends = None
keys = []
- for file in db.iterkeys():
+ for file in db.keys():
if not file in ['min_x', 'max_x', 'min_y', 'max_y']:
keys.append(file)
......@@ -4,3 +4,4 @@ pdf-date.patch
procnum.patch
spelling.patch
cve-2018-10689
python3-support
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment