mirror of https://github.com/nicolargo/glances.git
Merge pull request #3253 from Boris-Okassa/Dictkeys
remove `.keys()` from loops over dicts
This commit is contained in:
commit
6ffcaf4a94
|
|
@ -266,7 +266,7 @@ class GlancesExport:
|
|||
if isinstance(stats, dict):
|
||||
# Stats is a dict
|
||||
# Is there a key ?
|
||||
if "key" in stats.keys() and stats["key"] in stats.keys():
|
||||
if "key" in stats and stats["key"] in stats:
|
||||
pre_key = "{}.".format(stats[stats["key"]])
|
||||
else:
|
||||
pre_key = ""
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ class GlancesCursesBrowser(_GlancesCurses):
|
|||
counts[color] = counts.get(color, 0) + 1
|
||||
|
||||
result = ''
|
||||
for key in counts.keys():
|
||||
for key in counts:
|
||||
result += key + ': ' + str(counts[key]) + ' '
|
||||
|
||||
return result
|
||||
|
|
|
|||
|
|
@ -55,12 +55,12 @@ class GlancesStdoutCsv:
|
|||
line += f'{plugin}.{attribute}{self.separator}'
|
||||
else:
|
||||
if isinstance(stat, dict):
|
||||
for k in stat.keys():
|
||||
for k in stat:
|
||||
line += f'{plugin}.{str(k)}{self.separator}'
|
||||
elif isinstance(stat, list):
|
||||
for i in stat:
|
||||
if isinstance(i, dict) and 'key' in i:
|
||||
for k in i.keys():
|
||||
for k in i:
|
||||
line += '{}.{}.{}{}'.format(plugin, str(i[i['key']]), str(k), self.separator)
|
||||
else:
|
||||
line += f'{plugin}{self.separator}'
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ class GlancesStdoutIssue:
|
|||
stat = stats.get_plugin(plugin).get_export()
|
||||
# Hide private information
|
||||
if plugin == 'ip':
|
||||
for key in stat.keys():
|
||||
for key in stat:
|
||||
stat[key] = '***'
|
||||
except Exception as e:
|
||||
stat_error = e
|
||||
|
|
|
|||
|
|
@ -156,7 +156,7 @@ class SensorsPlugin(GlancesPluginModel):
|
|||
if self.input_method == 'local':
|
||||
with ThreadPoolExecutor(max_workers=len(self.sensors_grab_map)) as executor:
|
||||
logger.debug(f"Sensors enabled sub plugins: {list(self.sensors_grab_map.keys())}")
|
||||
futures = {t: executor.submit(self.__get_sensor_data, t) for t in self.sensors_grab_map.keys()}
|
||||
futures = {t: executor.submit(self.__get_sensor_data, t) for t in self.sensors_grab_map}
|
||||
|
||||
# Merge the results
|
||||
for sensor_type, future in futures.items():
|
||||
|
|
|
|||
|
|
@ -185,10 +185,10 @@ class SmartPlugin(GlancesPluginModel):
|
|||
msg = '{:{width}}'.format(device_stat['DeviceName'][:max_width], width=max_width)
|
||||
ret.append(self.curse_add_line(msg))
|
||||
try:
|
||||
device_stat_sorted = sorted([i for i in device_stat.keys() if i != 'DeviceName'], key=int)
|
||||
device_stat_sorted = sorted([i for i in device_stat if i != 'DeviceName'], key=int)
|
||||
except ValueError:
|
||||
# Catch ValueError, see #2904
|
||||
device_stat_sorted = [i for i in device_stat.keys() if i != 'DeviceName']
|
||||
device_stat_sorted = [i for i in device_stat if i != 'DeviceName']
|
||||
for smart_stat in device_stat_sorted:
|
||||
ret.append(self.curse_new_line())
|
||||
msg = ' {:{width}}'.format(
|
||||
|
|
|
|||
|
|
@ -404,7 +404,7 @@ class TestGlances(unittest.TestCase):
|
|||
assert len(stats_grab) == 0
|
||||
else:
|
||||
print(stats_grab)
|
||||
self.assertTrue(stat in stats_grab[0].keys(), msg=f'Cannot find key: {stat}')
|
||||
self.assertTrue(stat in stats_grab[0], msg=f'Cannot find key: {stat}')
|
||||
|
||||
print(f'INFO: SMART stats: {stats_grab}')
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue