Add view (MVC speeking) for the plugins. FS and SENSORS OK.

This commit is contained in:
Nicolargo
2015-01-18 16:08:40 +01:00
parent 859ed24cab
commit 8a94bc65bb
3 changed files with 68 additions and 21 deletions

View File

@@ -122,8 +122,25 @@ class Plugin(GlancesPlugin):
# Update the history list
self.update_stats_history('disk_name')
# 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
for i in sorted(self.stats, key=operator.itemgetter(self.get_key())):
disk_real_name = i['disk_name']
self.views[i[self.get_key()]]['read_bytes']['decoration'] = self.get_alert(int(i['read_bytes'] // i['time_since_update']),
header=disk_real_name + '_rx')
self.views[i[self.get_key()]]['write_bytes']['decoration'] = self.get_alert(int(i['write_bytes'] // i['time_since_update']),
header=disk_real_name + '_tx')
def msg_curse(self, args=None):
"""Return the dict to display in the curse interface."""
# Init the return message
@@ -164,11 +181,13 @@ class Plugin(GlancesPlugin):
int(i['write_bytes'] // i['time_since_update']))
msg = '{0:>7}'.format(txps)
ret.append(self.curse_add_line(msg,
self.get_alert(int(i['read_bytes'] // i['time_since_update']),
header=disk_real_name + '_rx')))
self.get_views(item=i[self.get_key()],
key='read_bytes',
option='decoration')))
msg = '{0:>7}'.format(rxps)
ret.append(self.curse_add_line(msg,
self.get_alert(int(i['write_bytes'] // i['time_since_update']),
header=disk_real_name + '_tx')))
self.get_views(item=i[self.get_key()],
key='write_bytes',
option='decoration')))
return ret

View File

@@ -168,8 +168,21 @@ class Plugin(GlancesPlugin):
# Update the history list
self.update_stats_history('mnt_point')
# 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
for i in sorted(self.stats, key=operator.itemgetter(self.get_key())):
self.views[i[self.get_key()]]['used']['decoration'] = self.get_alert(i['used'], max=i['size'], header=i['mnt_point'])
def msg_curse(self, args=None, max_width=None):
"""Return the dict to display in the curse interface."""
# Init the return message
@@ -219,9 +232,9 @@ class Plugin(GlancesPlugin):
msg = '{0:>7}'.format(self.auto_unit(i['free']))
else:
msg = '{0:>7}'.format(self.auto_unit(i['used']))
ret.append(self.curse_add_line(msg, self.get_alert(i['used'],
max=i['size'],
header=i['mnt_point'])))
ret.append(self.curse_add_line(msg, self.get_views(item=i[self.get_key()],
key='used',
option='decoration')))
msg = '{0:>7}'.format(self.auto_unit(i['size']))
ret.append(self.curse_add_line(msg))

View File

@@ -108,8 +108,12 @@ class Plugin(GlancesPlugin):
# Update stats using SNMP
# No standard:
# http://www.net-snmp.org/wiki/index.php/Net-SNMP_and_lm-sensors_on_Ubuntu_10.04
pass
# Update the view
self.update_views()
return self.stats
def __set_type(self, stats, sensor_type):
@@ -124,6 +128,19 @@ class Plugin(GlancesPlugin):
i.update({'type': sensor_type})
return stats
def update_views(self):
"""Update stats views"""
# Call the father's method
GlancesPlugin.update_views(self)
# Add specifics informations
# Alert
for i in self.stats:
if i['type'] == 'battery':
self.views[i[self.get_key()]]['value']['decoration'] = self.get_alert(100 - i['value'], header=i['type'])
else:
self.views[i[self.get_key()]]['value']['decoration'] = self.get_alert(i['value'], header=i['type'])
def msg_curse(self, args=None):
"""Return the dict to display in the curse interface."""
# Init the return message
@@ -143,27 +160,25 @@ class Plugin(GlancesPlugin):
msg = '{0:>6}'.format(_("°C"))
ret.append(self.curse_add_line(msg))
for item in self.stats:
if item['value'] is not None and item['value'] != []:
for i in self.stats:
if i['value'] is not None and i['value'] != []:
# New line
ret.append(self.curse_new_line())
# Alias for the lable name ?
label = self.has_alias(item['label'].lower())
label = self.has_alias(i['label'].lower())
if label is None:
label = item['label']
label = i['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'])))
msg = '{0:>5}'.format(i['value'])
try:
ret.append(self.curse_add_line(
msg, self.get_views(item=i[self.get_key()],
key='value',
option='decoration')))
except TypeError:
pass
return ret