commit:     63959edc58c8a87d8a4661bedde274a504cc793a
Author:     Paul Healy <lmiphay <AT> gmail <DOT> com>
AuthorDate: Sun Oct 20 19:42:28 2024 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sun Dec  1 12:39:33 2024 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=63959edc

sys-apps/dstat: use importlib for plugins

Replace imp module use with importlib
Remove unfinished code block for loading shared lib plugins

Bug: https://bugs.gentoo.org/941872
Signed-off-by: Paul Healy <lmiphay <AT> gmail.com>
Closes: https://github.com/gentoo/gentoo/pull/39059
Signed-off-by: Sam James <sam <AT> gentoo.org>

 sys-apps/dstat/dstat-0.7.4-r4.ebuild               | 61 ++++++++++++++++++++++
 .../dstat/files/dstat-0.7.4-use-importlib.patch    | 37 +++++++++++++
 2 files changed, 98 insertions(+)

diff --git a/sys-apps/dstat/dstat-0.7.4-r4.ebuild 
b/sys-apps/dstat/dstat-0.7.4-r4.ebuild
new file mode 100644
index 000000000000..d0c6bd489b80
--- /dev/null
+++ b/sys-apps/dstat/dstat-0.7.4-r4.ebuild
@@ -0,0 +1,61 @@
+# Copyright 1999-2024 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+
+PYTHON_COMPAT=( python3_{10..12} )
+
+inherit python-r1
+
+DESCRIPTION="Versatile replacement for vmstat, iostat and ifstat"
+HOMEPAGE="http://dag.wieers.com/home-made/dstat/";
+SRC_URI="https://github.com/dagwieers/${PN}/archive/v${PV}.tar.gz -> 
${P}.tar.gz"
+
+LICENSE="GPL-2+"
+SLOT="0"
+KEYWORDS="~alpha amd64 ~arm64 ~hppa ~mips ppc ppc64 sparc x86 ~x86-linux"
+IUSE="doc examples"
+REQUIRED_USE="${PYTHON_REQUIRED_USE}"
+
+RDEPEND="${PYTHON_DEPS}
+       dev-python/six[${PYTHON_USEDEP}]"
+DEPEND="${RDEPEND}"
+
+PATCHES=(
+       "${FILESDIR}/dstat-${PV}-skip-non-sandbox-tests.patch"
+       "${FILESDIR}/fix-collections-deprecation-warning.patch"
+       "${FILESDIR}/dstat-0.7.4-fix-csv-output.patch"
+       "${FILESDIR}/dstat-${PV}-fix-backslash-in-regex.patch"
+       "${FILESDIR}/dstat-${PV}-use-importlib.patch"
+)
+
+src_prepare() {
+       # bug fix: allow delay to be specified
+       # backport from: https://github.com/dagwieers/dstat/pull/167/files
+       sed -e 's; / op\.delay; // op.delay;' -i "dstat" || die
+
+       default
+}
+
+src_test() {
+       python_foreach_impl emake test
+}
+
+src_install() {
+       python_foreach_impl python_doscript dstat
+
+       insinto /usr/share/dstat
+       newins dstat dstat.py
+       doins plugins/dstat_*.py
+
+       doman docs/dstat.1
+
+       einstalldocs
+
+       if use examples; then
+               dodoc examples/{mstat,read}.py
+       fi
+       if use doc; then
+               dodoc docs/*.html
+       fi
+}

diff --git a/sys-apps/dstat/files/dstat-0.7.4-use-importlib.patch 
b/sys-apps/dstat/files/dstat-0.7.4-use-importlib.patch
new file mode 100644
index 000000000000..a6650ff1b37b
--- /dev/null
+++ b/sys-apps/dstat/files/dstat-0.7.4-use-importlib.patch
@@ -0,0 +1,37 @@
+diff --git a/dstat b/dstat
+index 9359965..541fe95 100755
+--- a/dstat
++++ b/dstat
+@@ -2613,28 +2613,19 @@ def main():
+             pluginfile = 'dstat_' + mod.replace('-', '_')
+             try:
+                 if pluginfile not in globals():
+-                    import imp
+-                    fp, pathname, description = imp.find_module(pluginfile, 
pluginpath)
+-                    fp.close()
++                    import importlib.machinery
++                    spec = 
importlib.machinery.PathFinder().find_spec(pluginfile, pluginpath)
+ 
+                     ### TODO: Would using .pyc help with anything ?
+                     ### Try loading python plugin
+-                    if description[0] in ('.py', ):
+-                        exec(open(pathname).read())
++                    if spec.origin.endswith('.py'):
++                        exec(open(spec.origin).read())
+                         #execfile(pathname)
+                         exec('global plug; plug = dstat_plugin(); 
del(dstat_plugin)')
+                         plug.filename = pluginfile
+                         plug.check()
+                         plug.prepare()
+ 
+-                    ### Try loading C plugin (not functional yet)
+-                    elif description[0] == '.so':
+-                        exec('import %s; global plug; plug = %s.new()' % 
(pluginfile, pluginfile))
+-                        plug.check()
+-                        plug.prepare()
+-#                        print(dir(plug))
+-#                        print(plug.__module__)
+-#                        print(plug.name)
+                     else:
+                         print('Module %s is of unknown type.' % pluginfile, 
file=sys.stderr)
+ 

Reply via email to