From 0e9e5e9512a36f9c410ff398c068d3e85ff06e2c Mon Sep 17 00:00:00 2001 From: Nicolas Hennion Date: Fri, 11 Jun 2021 17:07:29 +0200 Subject: Correct an issue in last commit for #1875 --- glances/__init__.py | 2 +- glances/cpu_percent.py | 6 +++++- glances/plugins/glances_quicklook.py | 16 ++++++++++------ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/glances/__init__.py b/glances/__init__.py index ce616d1b..60337e2a 100644 --- a/glances/__init__.py +++ b/glances/__init__.py @@ -29,7 +29,7 @@ import sys # Global name # Version should start and end with a numerical char # See https://packaging.python.org/specifications/core-metadata/#version -__version__ = '3.2.0b1' +__version__ = '3.2.0b2' __author__ = 'Nicolas Hennion ' __license__ = 'LGPLv3' diff --git a/glances/cpu_percent.py b/glances/cpu_percent.py index 8a7fba96..7f6db901 100644 --- a/glances/cpu_percent.py +++ b/glances/cpu_percent.py @@ -68,8 +68,12 @@ class CpuPercent(object): cpu_freq = psutil.cpu_freq() if hasattr(cpu_freq, 'current'): self.cpu_info['cpu_hz_current'] = cpu_freq.current - if hasattr(cpu_freq, 'cpu_hz'): + else: + self.cpu_info['cpu_hz_current'] = None + if hasattr(cpu_freq, 'max'): self.cpu_info['cpu_hz'] = cpu_freq.max + else: + self.cpu_info['cpu_hz'] = None # Reset timer for cache self.timer_cpu_info.reset(duration=self.cached_timer_cpu_info) return self.cpu_info diff --git a/glances/plugins/glances_quicklook.py b/glances/plugins/glances_quicklook.py index 4d3aa6ca..45b19523 100644 --- a/glances/plugins/glances_quicklook.py +++ b/glances/plugins/glances_quicklook.py @@ -80,9 +80,10 @@ class Plugin(GlancesPlugin): stats['swap'] = None # Get additional information - stats['cpu_name'] = cpu_percent.get_info()['cpu_name'] - stats['cpu_hz_current'] = self._mhz_to_hz(cpu_percent.get_info()['cpu_hz_current']) - stats['cpu_hz'] = self._mhz_to_hz(cpu_percent.get_info()['cpu_hz']) + cpu_info = cpu_percent.get_info() + stats['cpu_name'] = cpu_info['cpu_name'] + stats['cpu_hz_current'] = self._mhz_to_hz(cpu_info['cpu_hz_current']) if cpu_info['cpu_hz_current'] is not None else None + stats['cpu_hz'] = self._mhz_to_hz(cpu_info['cpu_hz']) if cpu_info['cpu_hz'] is not None else None elif self.input_method == 'snmp': # Not available @@ -126,9 +127,12 @@ class Plugin(GlancesPlugin): # Build the string message if 'cpu_name' in self.stats and 'cpu_hz_current' in self.stats and 'cpu_hz' in self.stats: - msg_name = '{} - '.format(self.stats['cpu_name']) - msg_freq = '{:.2f}/{:.2f}GHz'.format(self._hz_to_ghz(self.stats['cpu_hz_current']), - self._hz_to_ghz(self.stats['cpu_hz'])) + msg_name = self.stats['cpu_name'] + if self.stats['cpu_hz_current'] and self.stats['cpu_hz']: + msg_freq = ' - {:.2f}/{:.2f}GHz'.format(self._hz_to_ghz(self.stats['cpu_hz_current']), + self._hz_to_ghz(self.stats['cpu_hz'])) + else: + msg_freq = '' if len(msg_name + msg_freq) - 6 <= max_width: ret.append(self.curse_add_line(msg_name)) ret.append(self.curse_add_line(msg_freq)) -- cgit v1.2.3