提交 14350c5f 编写于 作者: N nicolargo

A simple hask to disable plugin if a an error occurs on load

上级 5bd4d587
......@@ -32,7 +32,7 @@ The return string is a string with one or more line (\n between lines).
If the *one_line* var is true then the AMP will be displayed in one line.
"""
from glances.compat import u
from glances.compat import u, b, n, nativestr
from glances.timer import Timer
from glances.logger import logger
......@@ -180,6 +180,7 @@ class GlancesAmp(object):
"""Store the result (string) into the result key of the AMP
if one_line is true then replace \n by separator
"""
# self.configs['result'] = unicode(result, 'utf-8').encode('utf-8', errors='replace')
if self.one_line():
self.configs['result'] = str(result).replace('\n', separator)
else:
......
......@@ -733,11 +733,11 @@ class _GlancesCurses(object):
if self.args.disable_left_sidebar:
return
for s in self._left_sidebar:
if ((hasattr(self.args, 'enable_' + s) or
hasattr(self.args, 'disable_' + s)) and s in stat_display):
for p in self._left_sidebar:
if ((hasattr(self.args, 'enable_' + p) or
hasattr(self.args, 'disable_' + p)) and s in stat_display):
self.new_line()
self.display_plugin(stat_display[s])
self.display_plugin(stat_display[p])
def __display_right(self, stat_display):
"""Display the right sidebar in the Curses interface.
......@@ -754,17 +754,19 @@ class _GlancesCurses(object):
# Display right sidebar
self.new_column()
for p in self._right_sidebar:
if p not in p:
# Catch for issue #1470
continue
self.new_line()
if p == 'processlist':
self.display_plugin(stat_display['processlist'],
display_optional=(self.screen.getmaxyx()[1] > 102),
display_additional=(not MACOS),
max_y=(self.screen.getmaxyx()[0] - self.get_stats_display_height(stat_display['alert']) - 2))
else:
self.display_plugin(stat_display[p])
if ((hasattr(self.args, 'enable_' + p) or
hasattr(self.args, 'disable_' + p)) and p in stat_display):
if p not in p:
# Catch for issue #1470
continue
self.new_line()
if p == 'processlist':
self.display_plugin(stat_display['processlist'],
display_optional=(self.screen.getmaxyx()[1] > 102),
display_additional=(not MACOS),
max_y=(self.screen.getmaxyx()[0] - self.get_stats_display_height(stat_display['alert']) - 2))
else:
self.display_plugin(stat_display[p])
def display_popup(self, message,
size_x=None, size_y=None,
......
......@@ -117,16 +117,22 @@ class GlancesStats(object):
self._plugins[name] = plugin.Plugin(args=args, config=config)
else:
self._plugins[name] = plugin.Plugin(args=args)
# Set the disable_<name> to False by default
if self.args is not None:
setattr(self.args,
'disable_' + name,
getattr(self.args, 'disable_' + name, False))
except Exception as e:
# If a plugin can not be log, display a critical message
# If a plugin can not be loaded, display a critical message
# on the console but do not crash
logger.critical("Error while initializing the {} plugin ({})".format(name, e))
logger.error(traceback.format_exc())
# Disable the plugin
if args is not None:
setattr(args,
'disable_' + name,
False)
else:
# Set the disable_<name> to False by default
if args is not None:
setattr(args,
'disable_' + name,
getattr(args, 'disable_' + name, False))
def load_plugins(self, args=None):
"""Load all plugins in the 'plugins' folder."""
......@@ -140,6 +146,7 @@ class GlancesStats(object):
# Log plugins list
logger.debug("Active plugins list: {}".format(self.getPluginsList()))
logger.critical(">>> Active plugins list: {}".format(self.getPluginsList()))
def load_exports(self, args=None):
"""Load all export modules in the 'exports' folder."""
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册