gentoo-ebuilds/sys-apps/dstat/files/dstat-0.7.4-use-importlib.patch
Paul Healy 63959edc58
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@gmail.com>
Closes: https://github.com/gentoo/gentoo/pull/39059
Signed-off-by: Sam James <sam@gentoo.org>
2024-12-01 12:39:33 +00:00

37 lines
1.7 KiB
Diff

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)