mirror of https://github.com/nicolargo/glances.git
Merge pull request #3252 from ariel-anieli/fix-python2-iterators
Remove iterator helpers
This commit is contained in:
commit
cba28407cb
|
|
@ -127,18 +127,6 @@ def listvalues(d):
|
|||
return list(d.values())
|
||||
|
||||
|
||||
def iteritems(d):
|
||||
return iter(d.items())
|
||||
|
||||
|
||||
def iterkeys(d):
|
||||
return iter(d.keys())
|
||||
|
||||
|
||||
def itervalues(d):
|
||||
return iter(d.values())
|
||||
|
||||
|
||||
def u(s, errors='replace'):
|
||||
if isinstance(s, text_type):
|
||||
return s
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ import time
|
|||
from pprint import pformat
|
||||
|
||||
from glances import __apiversion__
|
||||
from glances.globals import iteritems
|
||||
from glances.logger import logger
|
||||
|
||||
API_URL = f"http://localhost:61208/api/{__apiversion__}"
|
||||
|
|
@ -136,7 +135,7 @@ def print_plugin_description(plugin, stat):
|
|||
print('Fields descriptions:')
|
||||
print('')
|
||||
time_since_update = False
|
||||
for field, description in iteritems(stat.fields_description):
|
||||
for field, description in stat.fields_description.items():
|
||||
print(
|
||||
'* **{}**: {} (unit is *{}*)'.format(
|
||||
field,
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ Supported Cloud API:
|
|||
|
||||
import threading
|
||||
|
||||
from glances.globals import iteritems, to_ascii
|
||||
from glances.globals import to_ascii
|
||||
from glances.logger import logger
|
||||
from glances.plugins.plugin.model import GlancesPluginModel
|
||||
|
||||
|
|
@ -159,7 +159,7 @@ class ThreadOpenStack(threading.Thread):
|
|||
self.stop()
|
||||
return False
|
||||
|
||||
for k, v in iteritems(self.OPENSTACK_API_METADATA):
|
||||
for k, v in self.OPENSTACK_API_METADATA.items():
|
||||
r_url = f'{self.OPENSTACK_API_URL}/{v}'
|
||||
try:
|
||||
# Local request, a timeout of 3 seconds is OK
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
import psutil
|
||||
|
||||
from glances.cpu_percent import cpu_percent
|
||||
from glances.globals import LINUX, SUNOS, WINDOWS, iterkeys
|
||||
from glances.globals import LINUX, SUNOS, WINDOWS
|
||||
from glances.plugins.core import CorePlugin
|
||||
from glances.plugins.plugin.model import GlancesPluginModel
|
||||
|
||||
|
|
@ -271,7 +271,7 @@ class CpuPlugin(GlancesPluginModel):
|
|||
return self.stats
|
||||
|
||||
# Convert SNMP stats to float
|
||||
for key in iterkeys(stats):
|
||||
for key in stats:
|
||||
stats[key] = float(stats[key])
|
||||
stats['total'] = 100 - stats['idle']
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ Just a stupid plugin to display the help screen.
|
|||
from itertools import chain
|
||||
|
||||
from glances import __version__, psutil_version
|
||||
from glances.globals import iteritems
|
||||
from glances.plugins.plugin.model import GlancesPluginModel
|
||||
|
||||
|
||||
|
|
@ -172,7 +171,7 @@ class HelpPlugin(GlancesPluginModel):
|
|||
#
|
||||
shortcuts = []
|
||||
collecting = False
|
||||
for k, v in iteritems(self.view_data):
|
||||
for k, v in self.view_data.items():
|
||||
if collecting:
|
||||
pass
|
||||
elif k == 'header_sort':
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ import os
|
|||
|
||||
import psutil
|
||||
|
||||
from glances.globals import iteritems
|
||||
from glances.logger import logger
|
||||
from glances.plugins.core import CorePlugin
|
||||
from glances.plugins.plugin.model import GlancesPluginModel
|
||||
|
|
@ -114,7 +113,7 @@ class LoadPlugin(GlancesPluginModel):
|
|||
|
||||
# Python 3 return a dict like:
|
||||
# {'min1': "b'0.08'", 'min5': "b'0.12'", 'min15': "b'0.15'"}
|
||||
for k, v in iteritems(stats):
|
||||
for k, v in stats.items():
|
||||
stats[k] = float(v)
|
||||
|
||||
stats['cpucore'] = get_nb_log_core()
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@
|
|||
|
||||
import psutil
|
||||
|
||||
from glances.globals import iterkeys
|
||||
from glances.plugins.plugin.model import GlancesPluginModel
|
||||
from glances.timer import getTimeSinceLastUpdate
|
||||
|
||||
|
|
@ -125,7 +124,7 @@ class MemswapPlugin(GlancesPluginModel):
|
|||
self.reset()
|
||||
return stats
|
||||
|
||||
for key in iterkeys(stats):
|
||||
for key in stats:
|
||||
if stats[key] != '':
|
||||
stats[key] = float(stats[key]) * 1024
|
||||
|
||||
|
|
|
|||
|
|
@ -20,8 +20,6 @@ from glances.events_list import glances_events
|
|||
from glances.globals import (
|
||||
dictlist,
|
||||
dictlist_json_dumps,
|
||||
iterkeys,
|
||||
itervalues,
|
||||
json_dumps,
|
||||
list_to_dict,
|
||||
listkeys,
|
||||
|
|
@ -370,16 +368,14 @@ class GlancesPluginModel:
|
|||
ret = {}
|
||||
if bulk:
|
||||
# Bulk request
|
||||
snmp_result = snmp_client.getbulk_by_oid(0, 10, *list(itervalues(snmp_oid)))
|
||||
snmp_result = snmp_client.getbulk_by_oid(0, 10, *list(snmp_oid.values()))
|
||||
logger.info(snmp_result)
|
||||
if len(snmp_oid) == 1:
|
||||
# Bulk command for only one OID
|
||||
# Note: key is the item indexed but the OID result
|
||||
for item in snmp_result:
|
||||
if iterkeys(item)[0].startswith(itervalues(snmp_oid)[0]):
|
||||
ret[iterkeys(snmp_oid)[0] + iterkeys(item)[0].split(itervalues(snmp_oid)[0])[1]] = itervalues(
|
||||
item
|
||||
)[0]
|
||||
if item.keys()[0].startswith(snmp_oid.values()[0]):
|
||||
ret[snmp_oid.keys()[0] + item.keys()[0].split(snmp_oid.values()[0])[1]] = item.values()[0]
|
||||
else:
|
||||
# Build the internal dict with the SNMP result
|
||||
# Note: key is the first item in the snmp_oid
|
||||
|
|
@ -387,7 +383,7 @@ class GlancesPluginModel:
|
|||
for item in snmp_result:
|
||||
item_stats = {}
|
||||
item_key = None
|
||||
for key in iterkeys(snmp_oid):
|
||||
for key in snmp_oid:
|
||||
oid = snmp_oid[key] + '.' + str(index)
|
||||
if oid in item:
|
||||
if item_key is None:
|
||||
|
|
@ -399,10 +395,10 @@ class GlancesPluginModel:
|
|||
index += 1
|
||||
else:
|
||||
# Simple get request
|
||||
snmp_result = snmp_client.get_by_oid(*list(itervalues(snmp_oid)))
|
||||
snmp_result = snmp_client.get_by_oid(*list(snmp_oid.values()))
|
||||
|
||||
# Build the internal dict with the SNMP result
|
||||
for key in iterkeys(snmp_oid):
|
||||
for key in snmp_oid:
|
||||
ret[key] = snmp_result[snmp_oid[key]]
|
||||
|
||||
return ret
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@
|
|||
|
||||
"""RAID plugin."""
|
||||
|
||||
from glances.globals import iterkeys
|
||||
from glances.logger import logger
|
||||
from glances.plugins.plugin.model import GlancesPluginModel
|
||||
|
||||
|
|
@ -91,7 +90,7 @@ class RaidPlugin(GlancesPluginModel):
|
|||
msg = '{:>7}'.format('Avail')
|
||||
ret.append(self.curse_add_line(msg))
|
||||
# Data
|
||||
arrays = sorted(iterkeys(self.stats))
|
||||
arrays = sorted(self.stats.keys())
|
||||
for array in arrays:
|
||||
array_stats = self.stats[array]
|
||||
|
||||
|
|
@ -128,7 +127,7 @@ class RaidPlugin(GlancesPluginModel):
|
|||
ret.append(self.curse_new_line())
|
||||
msg = '└─ Status {}'.format(array_stats['status'])
|
||||
ret.append(self.curse_add_line(msg, status))
|
||||
components = sorted(iterkeys(array_stats['components']))
|
||||
components = sorted(array_stats['components'].keys())
|
||||
for i, component in enumerate(components):
|
||||
if i == len(components) - 1:
|
||||
tree_char = '└─'
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ import os
|
|||
import platform
|
||||
import re
|
||||
|
||||
from glances.globals import iteritems
|
||||
from glances.logger import logger
|
||||
from glances.plugins.plugin.model import GlancesPluginModel
|
||||
|
||||
|
|
@ -139,7 +138,7 @@ class SystemPlugin(GlancesPluginModel):
|
|||
|
||||
# Windows OS tips
|
||||
if self.short_system_name == 'windows':
|
||||
for key, value in iteritems(snmp_to_human['windows']):
|
||||
for key, value in snmp_to_human['windows'].items():
|
||||
if re.search(key, stats['system_name']):
|
||||
stats['os_name'] = value
|
||||
break
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@
|
|||
from copy import deepcopy
|
||||
from typing import Any, Optional
|
||||
|
||||
from glances.globals import iteritems
|
||||
from glances.logger import logger
|
||||
from glances.plugins.plugin.model import GlancesPluginModel
|
||||
from glances.plugins.vms.engines import VmsExtension
|
||||
|
|
@ -178,7 +177,7 @@ class VmsPlugin(GlancesPluginModel):
|
|||
def update_local(self):
|
||||
"""Update stats localy"""
|
||||
stats = []
|
||||
for engine, watcher in iteritems(self.watchers):
|
||||
for engine, watcher in self.watchers.items():
|
||||
version, vms = watcher.update(all_tag=self._all_tag())
|
||||
for vm in vms:
|
||||
vm["engine"] = engine
|
||||
|
|
|
|||
Loading…
Reference in New Issue