diff --git a/glances/plugins/plugin/model.py b/glances/plugins/plugin/model.py index d36ddbfb..2ebcf046 100644 --- a/glances/plugins/plugin/model.py +++ b/glances/plugins/plugin/model.py @@ -70,8 +70,16 @@ class GlancesPluginModel(object): :stats_init_value: Default value for a stats item """ # Build the plugin name - # Get second-last entry as the last one will always be 'model' - self.plugin_name = self.__class__.__module__.split('.')[-2] + _mod = self.__class__.__module__ + _comp = _mod.split('.') + # Internal or external module (former prefixed by 'glances.plugins') + if 'glances.plugins' in _mod: + _ndx = 2 + else: + _ndx = -2 + + self.plugin_name = _comp[_ndx] + if self.plugin_name.startswith('glances_'): self.plugin_name = self.plugin_name.split('glances_')[1] logger.debug("Init {} plugin".format(self.plugin_name)) diff --git a/glances/stats.py b/glances/stats.py index 67688127..e8c89a8c 100644 --- a/glances/stats.py +++ b/glances/stats.py @@ -15,7 +15,7 @@ import sys import threading import traceback from importlib import import_module -import pkgutil +import pathlib from glances.logger import logger from glances.globals import exports_path, plugins_path, sys_path @@ -142,10 +142,16 @@ class GlancesStats(object): def get_addl_plugins(self, plugin_path): """ Get list of additonal plugins """ _plugin_list = [] - for plugin in pkgutil.walk_packages([plugin_path]): - # Make sure we only include top-level packages in that directory - if plugin.ispkg and not plugin.name.startswith('__') and plugin.module_finder.path == plugin_path: - _plugin_list.append(plugin.name) + for plugin in os.listdir(plugin_path): + path = os.path.join(plugin_path, plugin) + if os.path.isdir(path) and not path.startswith('__'): + # Poor man's walk_pkgs - can't use pkgutil as the module would be already imported here! + for fil in pathlib.Path(path).glob('*.py'): + if fil.is_file(): + with open(fil) as fd: + if 'PluginModel' in fd.read(): + _plugin_list.append(plugin) + break return _plugin_list @@ -154,7 +160,7 @@ class GlancesStats(object): if config and config.parser.has_option('global', 'plugin_dir'): path = config.parser['global']['plugin_dir'] - if args and 'plugin_dir' in args: + if args and 'plugin_dir' in args and args.plugin_dir: path = args.plugin_dir if path: