Merge pull request #1232 from Thomaash/develop

Use alias aware sorting also for network devices
This commit is contained in:
Nicolas Hennion 2018-02-13 21:27:42 +01:00 committed by GitHub
commit 85f5e6c8d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 5 deletions

View File

@ -180,10 +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 sorted(self.stats, key=lambda stat: tuple(map(
lambda part: int(part) if part.isdigit() else part.lower(),
re.split(r"(\d+|\D+)", stat.get('alias') or stat['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 sorted(self.stats, key=operator.itemgetter(self.get_key())):
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,6 +286,14 @@ class GlancesPlugin(object):
"""Get the short detected OS name (SNMP)."""
return self._short_system_name
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])
)))
@short_system_name.setter
def short_system_name(self, short_name):
"""Set the short detected OS name (SNMP)."""