From 8629f5f5c24e8a02c0a168cff22a40ec0788bb2d Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sun, 7 Jun 2020 12:11:03 -0700 Subject: [PATCH] Switch to Python3 Support for Python2.7 in Linux distributions is being phased out. As an example, some Linux distributions do not provide Python2.7 versions of some of the Python packages fio Python scripts relies on. Hence switch to Python3. Most of the Python code changes in this patch have been generated by running the Python scripts through 2to3, the Python2 to Python3 converter from python.org. Notes: - Python is only used by fio test scripts and not by fio itself. - Older versions of RHEL / CentOS 6 do not support Python3. Python3 binaries for RHEL 6 / CentOS 6 are available e.g. in the EPEL repository (https://fedoraproject.org/wiki/EPEL). Signed-off-by: Bart Van Assche Signed-off-by: Jens Axboe --- t/sgunmap-perf.py | 2 +- t/sgunmap-test.py | 2 +- tools/fio_jsonplus_clat2csv | 2 +- tools/fiologparser.py | 3 ++- tools/hist/fio-histo-log-pctiles.py | 5 +++-- tools/hist/fiologparser_hist.py | 11 ++++------- tools/hist/half-bins.py | 2 +- tools/plot/fio2gnuplot | 2 +- 8 files changed, 14 insertions(+), 15 deletions(-) diff --git a/t/sgunmap-perf.py b/t/sgunmap-perf.py index fadbb859..962d187d 100755 --- a/t/sgunmap-perf.py +++ b/t/sgunmap-perf.py @@ -1,4 +1,4 @@ -#!/usr/bin/python2.7 +#!/usr/bin/env python3 # # sgunmap-test.py # diff --git a/t/sgunmap-test.py b/t/sgunmap-test.py index f8f10ab3..4960a040 100755 --- a/t/sgunmap-test.py +++ b/t/sgunmap-test.py @@ -1,4 +1,4 @@ -#!/usr/bin/python2.7 +#!/usr/bin/env python3 # Note: this script is python2 and python 3 compatible. # # sgunmap-test.py diff --git a/tools/fio_jsonplus_clat2csv b/tools/fio_jsonplus_clat2csv index 9544ab74..7f310fcc 100755 --- a/tools/fio_jsonplus_clat2csv +++ b/tools/fio_jsonplus_clat2csv @@ -1,4 +1,4 @@ -#!/usr/bin/python2.7 +#!/usr/bin/env python3 # Note: this script is python2 and python3 compatible. """ diff --git a/tools/fiologparser.py b/tools/fiologparser.py index cc29f1c7..054f1f60 100755 --- a/tools/fiologparser.py +++ b/tools/fiologparser.py @@ -1,4 +1,4 @@ -#!/usr/bin/python2.7 +#!/usr/bin/env python3 # Note: this script is python2 and python 3 compatible. # # fiologparser.py @@ -18,6 +18,7 @@ from __future__ import absolute_import from __future__ import print_function import argparse import math +from functools import reduce def parse_args(): parser = argparse.ArgumentParser() diff --git a/tools/hist/fio-histo-log-pctiles.py b/tools/hist/fio-histo-log-pctiles.py index f9df2a3d..08e7722d 100755 --- a/tools/hist/fio-histo-log-pctiles.py +++ b/tools/hist/fio-histo-log-pctiles.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # module to parse fio histogram log files, not using pandas # runs in python v2 or v3 @@ -24,6 +24,7 @@ import sys, os, math, copy, time from copy import deepcopy import argparse +from functools import reduce unittest2_imported = True try: @@ -82,7 +83,7 @@ def parse_hist_file(logfn, buckets_per_interval, log_hist_msec): except ValueError as e: raise FioHistoLogExc('non-integer value %s' % exception_suffix(k+1, logfn)) - neg_ints = list(filter( lambda tk : tk < 0, int_tokens )) + neg_ints = list([tk for tk in int_tokens if tk < 0]) if len(neg_ints) > 0: raise FioHistoLogExc('negative integer value %s' % exception_suffix(k+1, logfn)) diff --git a/tools/hist/fiologparser_hist.py b/tools/hist/fiologparser_hist.py index 8910d5fa..159454b1 100755 --- a/tools/hist/fiologparser_hist.py +++ b/tools/hist/fiologparser_hist.py @@ -1,4 +1,4 @@ -#!/usr/bin/python2.7 +#!/usr/bin/env python3 """ Utility for converting *_clat_hist* files generated by fio into latency statistics. @@ -124,7 +124,7 @@ def gen_output_columns(ctx): columns = ["end-time", "dir", "samples", "min", "avg", "median"] else: columns = ["end-time", "samples", "min", "avg", "median"] - columns.extend(list(map(lambda x: x+'%', strpercs))) + columns.extend(list([x+'%' for x in strpercs])) columns.append("max") def fmt_float_list(ctx, num=1): @@ -339,7 +339,7 @@ def guess_max_from_bins(ctx, hist_cols): else: bins = [1216,1280,1344,1408,1472,1536,1600,1664] coarses = range(max_coarse + 1) - fncn = lambda z: list(map(lambda x: z/2**x if z % 2**x == 0 else -10, coarses)) + fncn = lambda z: list([z/2**x if z % 2**x == 0 else -10 for x in coarses]) arr = np.transpose(list(map(fncn, bins))) idx = np.where(arr == hist_cols) @@ -470,10 +470,7 @@ def output_interval_data(ctx,directions): def main(ctx): if ctx.job_file: - try: - from configparser import SafeConfigParser, NoOptionError - except ImportError: - from ConfigParser import SafeConfigParser, NoOptionError + from configparser import SafeConfigParser, NoOptionError cp = SafeConfigParser(allow_no_value=True) with open(ctx.job_file, 'r') as fp: diff --git a/tools/hist/half-bins.py b/tools/hist/half-bins.py index 1bba8ff7..42af9540 100755 --- a/tools/hist/half-bins.py +++ b/tools/hist/half-bins.py @@ -1,4 +1,4 @@ -#!/usr/bin/python2.7 +#!/usr/bin/env python3 """ Cut the number bins in half in fio histogram output. Example usage: $ half-bins.py -c 2 output_clat_hist.1.log > smaller_clat_hist.1.log diff --git a/tools/plot/fio2gnuplot b/tools/plot/fio2gnuplot index 69aa791e..78ee82fb 100755 --- a/tools/plot/fio2gnuplot +++ b/tools/plot/fio2gnuplot @@ -1,4 +1,4 @@ -#!/usr/bin/python2.7 +#!/usr/bin/env python3 # Note: this script is python2 and python3 compatible. # # Copyright (C) 2013 eNovance SAS -- 2.25.1