mirror of
https://github.com/nicolargo/glances.git
synced 2024-08-17 00:10:48 +03:00
Improve code
This commit is contained in:
parent
4ddff48c70
commit
ada7f248ba
@ -188,33 +188,31 @@ class GlancesPluginModel(object):
|
||||
def update_stats_history(self):
|
||||
"""Update stats history."""
|
||||
# Build the history
|
||||
if self.get_export() and self.history_enable():
|
||||
# If the plugin data is a dict, the dict's key should be used
|
||||
if self.get_key() is None:
|
||||
item_name = ''
|
||||
if not (self.get_export() and self.history_enable()):
|
||||
return
|
||||
# Itern through items history
|
||||
item_name = '' if self.get_key() is None else self.get_key()
|
||||
for i in self.get_items_history_list():
|
||||
if isinstance(self.get_export(), list):
|
||||
# Stats is a list of data
|
||||
# Iter through stats (for example, iter through network interface)
|
||||
for l_export in self.get_export():
|
||||
if i['name'] in l_export:
|
||||
self.stats_history.add(
|
||||
nativestr(l_export[item_name]) + '_' + nativestr(i['name']),
|
||||
l_export[i['name']],
|
||||
description=i['description'],
|
||||
history_max_size=self._limits['history_size'],
|
||||
)
|
||||
else:
|
||||
item_name = self.get_key()
|
||||
for i in self.get_items_history_list():
|
||||
if isinstance(self.get_export(), list):
|
||||
# Stats is a list of data
|
||||
# Iter through it (for example, iter through network interface)
|
||||
for l_export in self.get_export():
|
||||
if i['name'] in l_export:
|
||||
self.stats_history.add(
|
||||
nativestr(l_export[item_name]) + '_' + nativestr(i['name']),
|
||||
l_export[i['name']],
|
||||
description=i['description'],
|
||||
history_max_size=self._limits['history_size'],
|
||||
)
|
||||
else:
|
||||
# Stats is not a list
|
||||
# Add the item to the history directly
|
||||
self.stats_history.add(
|
||||
nativestr(i['name']),
|
||||
self.get_export()[i['name']],
|
||||
description=i['description'],
|
||||
history_max_size=self._limits['history_size'],
|
||||
)
|
||||
# Stats is not a list
|
||||
# Add the item to the history directly
|
||||
self.stats_history.add(
|
||||
nativestr(i['name']),
|
||||
self.get_export()[i['name']],
|
||||
description=i['description'],
|
||||
history_max_size=self._limits['history_size'],
|
||||
)
|
||||
|
||||
def get_items_history_list(self):
|
||||
"""Return the items history list."""
|
||||
|
@ -90,18 +90,16 @@ class TestGlances(unittest.TestCase):
|
||||
# Check stats
|
||||
self.assertIsInstance(plugin_instance.get_raw(), (dict, list))
|
||||
if isinstance(plugin_instance.get_raw(), dict):
|
||||
# self.assertTrue(any([f in plugin_instance.get_raw() for f in plugin_instance.fields_description]))
|
||||
res = False
|
||||
for f in plugin_instance.fields_description:
|
||||
if f not in plugin_instance.get_raw():
|
||||
print(f"WARNING: {f} not found in {plugin} plugin fields_description")
|
||||
print(f"WARNING: {f} field not found in {plugin} plugin stats")
|
||||
else:
|
||||
res = True
|
||||
self.assertTrue(res)
|
||||
elif isinstance(plugin_instance.get_raw(), list):
|
||||
res = False
|
||||
for i in plugin_instance.get_raw():
|
||||
# self.assertTrue(all([f in plugin_instance.fields_description for f in i]))
|
||||
for f in i:
|
||||
if f in plugin_instance.fields_description:
|
||||
res = True
|
||||
|
Loading…
Reference in New Issue
Block a user