mirror of
https://github.com/nicolargo/glances.git
synced 2026-06-21 12:08:40 -04:00
FR: Sort Sensors my name in proper number order #3132
This commit is contained in:
@@ -508,3 +508,12 @@ def replace_special_chars(input_string, by=' '):
|
||||
"""Replace some special char by another in the input_string
|
||||
Return: the string with the chars replaced"""
|
||||
return input_string.replace('\r\n', by).replace('\n', by).replace('\t', by)
|
||||
|
||||
|
||||
def atoi(text):
|
||||
return int(text) if text.isdigit() else text
|
||||
|
||||
|
||||
def natural_keys(text):
|
||||
"""Return a text in a natural/human readable format."""
|
||||
return [atoi(c) for c in re.split(r'(\d+)', text)]
|
||||
|
||||
@@ -14,7 +14,7 @@ from typing import Any
|
||||
|
||||
import psutil
|
||||
|
||||
from glances.globals import to_fahrenheit
|
||||
from glances.globals import natural_keys, to_fahrenheit
|
||||
from glances.logger import logger
|
||||
from glances.outputs.glances_unicode import unicode_message
|
||||
from glances.plugins.plugin.model import GlancesPluginModel
|
||||
@@ -144,7 +144,7 @@ class PluginModel(GlancesPluginModel):
|
||||
# Remove duplicates thanks to https://stackoverflow.com/a/9427216/1919431
|
||||
stats_transformed = [dict(t) for t in {tuple(d.items()) for d in stats_transformed}]
|
||||
# Sort by label
|
||||
return sorted(stats_transformed, key=lambda d: d['label'])
|
||||
return sorted(stats_transformed, key=lambda d: natural_keys(d['label']))
|
||||
|
||||
@GlancesPluginModel._check_decorator
|
||||
@GlancesPluginModel._log_result_decorator
|
||||
|
||||
Reference in New Issue
Block a user