glances: Refactor

Instead of a loop, used a generator for the search.

Part-of: #2801
Signed-off-by: Ariel Otilibili <otilibil@eurecom.fr>
This commit is contained in:
Ariel Otilibili 2025-05-29 13:39:51 +02:00 committed by nicolargo
parent 81150246e5
commit 239d5f7db6
1 changed files with 5 additions and 12 deletions

View File

@ -74,18 +74,11 @@ class GlancesStatsClientSNMP(GlancesStats):
def get_system_name(self, oid_system_name):
"""Get the short os name from the OS name OID string."""
short_system_name = None
if oid_system_name == '':
return short_system_name
# Find the short name in the oid_to_short_os_name dict
for r, v in oid_to_short_system_name.items():
if re.search(r, oid_system_name):
short_system_name = v
break
return short_system_name
return (
next((v for r, v in oid_to_short_system_name.items() if re.search(r, oid_system_name)), None)
if oid_system_name
else None
)
def update(self):
"""Update the stats using SNMP."""