From d617e95aafecfd027ea364f9eb1ef2aa90c12c2d Mon Sep 17 00:00:00 2001 From: Nicolas Hennion Date: Tue, 26 Aug 2014 15:46:29 +0200 Subject: [PATCH] Correct bug when no batterie is available --- glances/__init__.py | 2 +- glances/plugins/glances_sensors.py | 38 ++++++++++++++++-------------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/glances/__init__.py b/glances/__init__.py index 9f5d4175..ed4082b3 100644 --- a/glances/__init__.py +++ b/glances/__init__.py @@ -20,7 +20,7 @@ """Init the Glances software.""" __appname__ = 'glances' -__version__ = '2.1_RC4' +__version__ = '2.1_RC5' __author__ = 'Nicolas Hennion ' __license__ = 'LGPL' diff --git a/glances/plugins/glances_sensors.py b/glances/plugins/glances_sensors.py index b3c3de84..0ef3d913 100644 --- a/glances/plugins/glances_sensors.py +++ b/glances/plugins/glances_sensors.py @@ -27,7 +27,7 @@ except ImportError: pass # Import Glances lib -from glances.core.glances_globals import is_py3 +from glances.core.glances_globals import is_py3, logger from glances.plugins.glances_batpercent import Plugin as BatPercentPlugin from glances.plugins.glances_hddtemp import Plugin as HddTempPlugin from glances.plugins.glances_plugin import GlancesPlugin @@ -134,23 +134,25 @@ class Plugin(GlancesPlugin): ret.append(self.curse_add_line(msg)) for item in self.stats: - # New line - ret.append(self.curse_new_line()) - # Alias for the lable name ? - label = self.has_alias(item['label'].lower()) - if label is None: - label = item['label'] - label = label[:18] - msg = '{0:18}'.format(label) - ret.append(self.curse_add_line(msg)) - msg = '{0:>5}'.format(item['value']) - if item['type'] == 'battery': - try: - ret.append(self.curse_add_line(msg, self.get_alert(100 - item['value'], header=item['type']))) - except TypeError: - pass - else: - ret.append(self.curse_add_line(msg, self.get_alert(item['value'], header=item['type']))) + if item['value'] is not None and item['value'] != []: + logger.debug(item['value']) + # New line + ret.append(self.curse_new_line()) + # Alias for the lable name ? + label = self.has_alias(item['label'].lower()) + if label is None: + label = item['label'] + label = label[:18] + msg = '{0:18}'.format(label) + ret.append(self.curse_add_line(msg)) + msg = '{0:>5}'.format(item['value']) + if item['type'] == 'battery': + try: + ret.append(self.curse_add_line(msg, self.get_alert(100 - item['value'], header=item['type']))) + except TypeError: + pass + else: + ret.append(self.curse_add_line(msg, self.get_alert(item['value'], header=item['type']))) return ret