From 0c40cc2cec9ef1220b2bf9633c2c54f54908c94d Mon Sep 17 00:00:00 2001 From: Nicolargo Date: Sat, 17 Jan 2015 22:22:53 +0100 Subject: [PATCH] Add view (MVC speeking) for the plugins. MEM and MEM SWAP OK. --- glances/plugins/glances_mem.py | 34 ++++++++++++++++++++++-------- glances/plugins/glances_memswap.py | 14 +++++++++++- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/glances/plugins/glances_mem.py b/glances/plugins/glances_mem.py index 52bee12a..cf6ce4c5 100644 --- a/glances/plugins/glances_mem.py +++ b/glances/plugins/glances_mem.py @@ -155,8 +155,24 @@ class Plugin(GlancesPlugin): # Update the history list self.update_stats_history() + # Update the view + self.update_views() + return self.stats + def update_views(self): + """Update stats views""" + # Call the father's method + GlancesPlugin.update_views(self) + + # Add specifics informations + # Alert and log + self.views['used']['decoration'] = self.get_alert_log(self.stats['used'], max=self.stats['total']) + # Optional + for key in ['active', 'inactive', 'buffers', 'cached']: + if key in self.stats: + self.views[key]['optional'] = True + def msg_curse(self, args=None): """Return the dict to display in the curse interface.""" # Init the return message @@ -176,9 +192,9 @@ class Plugin(GlancesPlugin): # Active memory usage if 'active' in self.stats: msg = ' {0:9}'.format(_("active:")) - ret.append(self.curse_add_line(msg, optional=True)) + ret.append(self.curse_add_line(msg, optional=self.get_views(key='active', option='optional'))) msg = '{0:>7}'.format(self.auto_unit(self.stats['active'])) - ret.append(self.curse_add_line(msg, optional=True)) + ret.append(self.curse_add_line(msg, optional=self.get_views(key='active', option='optional'))) # New line ret.append(self.curse_new_line()) # Total memory usage @@ -189,9 +205,9 @@ class Plugin(GlancesPlugin): # Inactive memory usage if 'inactive' in self.stats: msg = ' {0:9}'.format(_("inactive:")) - ret.append(self.curse_add_line(msg, optional=True)) + ret.append(self.curse_add_line(msg, optional=self.get_views(key='inactive', option='optional'))) msg = '{0:>7}'.format(self.auto_unit(self.stats['inactive'])) - ret.append(self.curse_add_line(msg, optional=True)) + ret.append(self.curse_add_line(msg, optional=self.get_views(key='inactive', option='optional'))) # New line ret.append(self.curse_new_line()) # Used memory usage @@ -199,13 +215,13 @@ class Plugin(GlancesPlugin): ret.append(self.curse_add_line(msg)) msg = '{0:>7}'.format(self.auto_unit(self.stats['used'])) ret.append(self.curse_add_line( - msg, self.get_alert_log(self.stats['used'], max=self.stats['total']))) + msg, self.get_views(key='used', option='decoration'))) # Buffers memory usage if 'buffers' in self.stats: msg = ' {0:9}'.format(_("buffers:")) - ret.append(self.curse_add_line(msg, optional=True)) + ret.append(self.curse_add_line(msg, optional=self.get_views(key='buffers', option='optional'))) msg = '{0:>7}'.format(self.auto_unit(self.stats['buffers'])) - ret.append(self.curse_add_line(msg, optional=True)) + ret.append(self.curse_add_line(msg, optional=self.get_views(key='buffers', option='optional'))) # New line ret.append(self.curse_new_line()) # Free memory usage @@ -216,8 +232,8 @@ class Plugin(GlancesPlugin): # Cached memory usage if 'cached' in self.stats: msg = ' {0:9}'.format(_("cached:")) - ret.append(self.curse_add_line(msg, optional=True)) + ret.append(self.curse_add_line(msg, optional=self.get_views(key='cached', option='optional'))) msg = '{0:>7}'.format(self.auto_unit(self.stats['cached'])) - ret.append(self.curse_add_line(msg, optional=True)) + ret.append(self.curse_add_line(msg, optional=self.get_views(key='cached', option='optional'))) return ret diff --git a/glances/plugins/glances_memswap.py b/glances/plugins/glances_memswap.py index 20751add..084f7596 100644 --- a/glances/plugins/glances_memswap.py +++ b/glances/plugins/glances_memswap.py @@ -130,8 +130,20 @@ class Plugin(GlancesPlugin): # Update the history list self.update_stats_history() + # Update the view + self.update_views() + return self.stats + def update_views(self): + """Update stats views""" + # Call the father's method + GlancesPlugin.update_views(self) + + # Add specifics informations + # Alert and log + self.views['used']['decoration'] = self.get_alert_log(self.stats['used'], max=self.stats['total']) + def msg_curse(self, args=None): """Return the dict to display in the curse interface.""" # Init the return message @@ -162,7 +174,7 @@ class Plugin(GlancesPlugin): ret.append(self.curse_add_line(msg)) msg = '{0:>6}'.format(self.auto_unit(self.stats['used'])) ret.append(self.curse_add_line( - msg, self.get_alert_log(self.stats['used'], max=self.stats['total']))) + msg, self.get_views(key='used', option='decoration'))) # New line ret.append(self.curse_new_line()) # Free memory usage