sys-block/fio: add python USE flag

This python USE flag separates the gnuplot from the python
tools that can be optionally installed.

BUG=b:145635956
TEST=emerge-sarien fio; ls /build/sarien/usr/bin/fio* (no python
utilites)
(delete pandas dependency for testing) USE=python emerge-sarien fio
ls /build/sarien/usr/bin/fio* (python tools included)
USE="python gnuplot" emerge-sarien fio
ls /build/sarien/usr/bin/fio* (python and gnuplot tools included)

Change-Id: I1b914ba44bd0c4d6b7af7a45fc890d1b8ee17fb4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/overlays/portage-stable/+/2023432
Tested-by: Trent Begin <tbegin@chromium.org>
Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
diff --git a/sys-block/fio/fio-3.17.ebuild b/sys-block/fio/fio-3.17-r1.ebuild
similarity index 72%
rename from sys-block/fio/fio-3.17.ebuild
rename to sys-block/fio/fio-3.17-r1.ebuild
index 1e97edb..fb5ceb7 100644
--- a/sys-block/fio/fio-3.17.ebuild
+++ b/sys-block/fio/fio-3.17-r1.ebuild
@@ -17,9 +17,10 @@
 LICENSE="GPL-2"
 SLOT="0"
 KEYWORDS="*"
-IUSE="aio curl glusterfs gnuplot gtk libressl numa rbd rdma static tcmalloc zlib"
-REQUIRED_USE="gnuplot? ( ${PYTHON_REQUIRED_USE} )
-	libressl? ( curl )"
+IUSE="aio curl glusterfs gnuplot gtk libressl numa python rbd rdma static tcmalloc zlib"
+REQUIRED_USE="python? ( ${PYTHON_REQUIRED_USE} )
+	libressl? ( curl )
+	gnuplot? ( python )"
 
 BDEPEND="virtual/pkgconfig"
 
@@ -45,11 +46,11 @@
 DEPEND="${RDEPEND}
 	static? ( ${LIB_DEPEND} )"
 RDEPEND+="
-	gnuplot? (
-		sci-visualization/gnuplot
-		$(python_gen_any_dep 'dev-python/pandas[${PYTHON_USEDEP}]')
+	python? (
 		${PYTHON_DEPS}
-	)"
+		$(python_gen_any_dep 'dev-python/pandas[${PYTHON_USEDEP}]')
+	)
+	gnuplot? ( sci-visualization/gnuplot )"
 
 S="${WORKDIR}/${MY_P}"
 
@@ -104,20 +105,41 @@
 src_install() {
 	emake install DESTDIR="${D}" prefix="${EPREFIX}/usr" mandir="${EPREFIX}/usr/share/man"
 
-	if use gnuplot ; then
-		sed -i 's:python2.7:python:g' \
-			"${ED}/usr/bin/fio2gnuplot" \
-			"${ED}/usr/bin/fiologparser_hist.py" \
-			"${ED}/usr/bin/fiologparser.py"
-		python_replicate_script \
-			"${ED}/usr/bin/fio2gnuplot" \
-			"${ED}/usr/bin/fiologparser_hist.py" \
-			"${ED}/usr/bin/fiologparser.py"
+	local python2_7_files=(
+		"${ED}"/usr/bin/fiologparser_hist.py
+		"${ED}"/usr/bin/fiologparser.py
+	)
+
+	local python_files=(
+		"${python2_7_files[@]}"
+		"${ED}"/usr/bin/fio_jsonplus_clat2csv
+	)
+
+	if use python ; then
+		sed -i 's:python2.7:python:g' "${python2_7_files[@]}" || die
+		python_replicate_script "${python2_7_files[@]}"
 	else
-		rm "${ED}"/usr/bin/{fio2gnuplot,fio_generate_plots} || die
-		rm "${ED}"/usr/share/man/man1/{fio2gnuplot,fio_generate_plots}.1 || die
-		rm "${ED}"/usr/share/fio/*.gpm || die
-		rmdir "${ED}"/usr/share/fio/ 2>/dev/null
+		rm "${python_files[@]}" || die
+	fi
+
+	local gnuplot_python2_7_files=(
+		"${ED}"/usr/bin/fio2gnuplot
+	)
+
+	local gnuplot_files=(
+		"${gnuplot_python2_7_files[@]}"
+		"${ED}"/usr/bin/fio_generate_plots
+		"${ED}"/usr/share/man/man1/fio_generate_plots.1
+		"${ED}"/usr/share/man/man1/fio2gnuplot.1
+		"${ED}"/usr/share/fio/*.gpm
+	)
+
+	if use gnuplot ; then
+		sed -i 's:python2.7:python:g' "${gnuplot_python2_7_files[@]}" || die
+		python_replicate_script "${gnuplot_python2_7_files[@]}"
+	else
+		rm "${gnuplot_files[@]}" || die
+		rmdir "${ED}"/usr/share/fio/ || die
 	fi
 
 	# This tool has security/parallel issues -- it hardcodes /tmp/template.fio.