mirror of
https://github.com/nicolargo/glances.git
synced 2024-12-23 17:22:46 +03:00
Fixed plugin name handling in GlancesPluginModel and optimized package handling in load_additional_plugins
This commit is contained in:
parent
0ce4092df7
commit
037d3f7c89
@ -70,8 +70,16 @@ class GlancesPluginModel(object):
|
|||||||
:stats_init_value: Default value for a stats item
|
:stats_init_value: Default value for a stats item
|
||||||
"""
|
"""
|
||||||
# Build the plugin name
|
# Build the plugin name
|
||||||
# Get second-last entry as the last one will always be 'model'
|
_mod = self.__class__.__module__
|
||||||
self.plugin_name = self.__class__.__module__.split('.')[-2]
|
_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_'):
|
if self.plugin_name.startswith('glances_'):
|
||||||
self.plugin_name = self.plugin_name.split('glances_')[1]
|
self.plugin_name = self.plugin_name.split('glances_')[1]
|
||||||
logger.debug("Init {} plugin".format(self.plugin_name))
|
logger.debug("Init {} plugin".format(self.plugin_name))
|
||||||
|
@ -15,7 +15,7 @@ import sys
|
|||||||
import threading
|
import threading
|
||||||
import traceback
|
import traceback
|
||||||
from importlib import import_module
|
from importlib import import_module
|
||||||
import pkgutil
|
import pathlib
|
||||||
|
|
||||||
from glances.logger import logger
|
from glances.logger import logger
|
||||||
from glances.globals import exports_path, plugins_path, sys_path
|
from glances.globals import exports_path, plugins_path, sys_path
|
||||||
@ -142,10 +142,16 @@ class GlancesStats(object):
|
|||||||
def get_addl_plugins(self, plugin_path):
|
def get_addl_plugins(self, plugin_path):
|
||||||
""" Get list of additonal plugins """
|
""" Get list of additonal plugins """
|
||||||
_plugin_list = []
|
_plugin_list = []
|
||||||
for plugin in pkgutil.walk_packages([plugin_path]):
|
for plugin in os.listdir(plugin_path):
|
||||||
# Make sure we only include top-level packages in that directory
|
path = os.path.join(plugin_path, plugin)
|
||||||
if plugin.ispkg and not plugin.name.startswith('__') and plugin.module_finder.path == plugin_path:
|
if os.path.isdir(path) and not path.startswith('__'):
|
||||||
_plugin_list.append(plugin.name)
|
# 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
|
return _plugin_list
|
||||||
|
|
||||||
@ -154,7 +160,7 @@ class GlancesStats(object):
|
|||||||
if config and config.parser.has_option('global', 'plugin_dir'):
|
if config and config.parser.has_option('global', 'plugin_dir'):
|
||||||
path = config.parser['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
|
path = args.plugin_dir
|
||||||
|
|
||||||
if path:
|
if path:
|
||||||
|
Loading…
Reference in New Issue
Block a user