Move alias aware sorting to glances_plugin

This commit is contained in:
Tomáš Vyčítal 2018-02-12 23:08:12 +01:00
parent 56229d238a
commit 7a47c32341
No known key found for this signature in database
GPG Key ID: DE75FBFE77EB4768
2 changed files with 8 additions and 4 deletions

View File

@ -180,10 +180,7 @@ class Plugin(GlancesPlugin):
msg = '{:>7}'.format('W/s') msg = '{:>7}'.format('W/s')
ret.append(self.curse_add_line(msg)) ret.append(self.curse_add_line(msg))
# Disk list (sorted by name) # Disk list (sorted by name)
for i in sorted(self.stats, key=lambda stat: tuple(map( for i in self.sorted_stats('disk_name'):
lambda part: int(part) if part.isdigit() else part.lower(),
re.split(r"(\d+|\D+)", stat.get('alias') or stat['disk_name'])
))):
# Is there an alias for the disk name ? # Is there an alias for the disk name ?
disk_real_name = i['disk_name'] disk_real_name = i['disk_name']
disk_name = self.has_alias(i['disk_name']) disk_name = self.has_alias(i['disk_name'])

View File

@ -286,6 +286,13 @@ class GlancesPlugin(object):
"""Get the short detected OS name (SNMP).""" """Get the short detected OS name (SNMP)."""
return self._short_system_name return self._short_system_name
def sorted_stats(self, key):
"""Get the stats sorted by an alias (if present) or 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])
)))
@short_system_name.setter @short_system_name.setter
def short_system_name(self, short_name): def short_system_name(self, short_name):
"""Set the short detected OS name (SNMP).""" """Set the short detected OS name (SNMP)."""