Use get_key instead of hardcoded names in sorted_stats

pull/1232/head
Tomáš Vyčítal 2018-02-13 21:19:40 +01:00
parent 3a68e85d5b
commit 9e46e4bfaa
No known key found for this signature in database
GPG Key ID: DE75FBFE77EB4768
3 changed files with 4 additions and 3 deletions

View File

@ -180,7 +180,7 @@ class Plugin(GlancesPlugin):
msg = '{:>7}'.format('W/s')
ret.append(self.curse_add_line(msg))
# Disk list (sorted by name)
for i in self.sorted_stats('disk_name'):
for i in self.sorted_stats():
# Is there an alias for the disk name ?
disk_real_name = i['disk_name']
disk_name = self.has_alias(i['disk_name'])

View File

@ -289,7 +289,7 @@ class Plugin(GlancesPlugin):
msg = '{:>7}'.format('Tx/s')
ret.append(self.curse_add_line(msg))
# Interface list (sorted by name)
for i in self.sorted_stats('interface_name'):
for i in self.sorted_stats():
# Do not display interface in down state (issue #765)
if ('is_up' in i) and (i['is_up'] is False):
continue

View File

@ -286,8 +286,9 @@ class GlancesPlugin(object):
"""Get the short detected OS name (SNMP)."""
return self._short_system_name
def sorted_stats(self, key):
def sorted_stats(self):
"""Get the stats sorted by an alias (if present) or key."""
key = self.get_key()
return sorted(self.stats, key=lambda stat: tuple(map(
lambda part: int(part) if part.isdigit() else part.lower(),
re.split(r"(\d+|\D+)", self.has_alias(stat[key]) or stat[key])