mirror of
https://github.com/nicolargo/glances.git
synced 2024-09-11 12:47:14 +03:00
chg: ruff - flake8-comprehensions
This commit is contained in:
parent
108ffcdfb6
commit
28e7e5b74a
@ -115,7 +115,7 @@ class Export(GlancesExport):
|
|||||||
sensor_values = dict(zip(columns, points))
|
sensor_values = dict(zip(columns, points))
|
||||||
|
|
||||||
# Build the value to output
|
# Build the value to output
|
||||||
output_value = dict()
|
output_value = {}
|
||||||
for key in sensor_values:
|
for key in sensor_values:
|
||||||
split_key = key.split('.')
|
split_key = key.split('.')
|
||||||
|
|
||||||
@ -123,7 +123,7 @@ class Export(GlancesExport):
|
|||||||
current_level = output_value
|
current_level = output_value
|
||||||
for depth in range(len(split_key) - 1):
|
for depth in range(len(split_key) - 1):
|
||||||
if split_key[depth] not in current_level:
|
if split_key[depth] not in current_level:
|
||||||
current_level[split_key[depth]] = dict()
|
current_level[split_key[depth]] = {}
|
||||||
current_level = current_level[split_key[depth]]
|
current_level = current_level[split_key[depth]]
|
||||||
|
|
||||||
# Add the value
|
# Add the value
|
||||||
|
@ -299,7 +299,7 @@ class PluginModel(GlancesPluginModel):
|
|||||||
show_pod_name = True
|
show_pod_name = True
|
||||||
self.views['show_pod_name'] = show_pod_name
|
self.views['show_pod_name'] = show_pod_name
|
||||||
show_engine_name = False
|
show_engine_name = False
|
||||||
if len(set(ct["engine"] for ct in self.stats)) > 1:
|
if len({ct["engine"] for ct in self.stats}) > 1:
|
||||||
show_engine_name = True
|
show_engine_name = True
|
||||||
self.views['show_engine_name'] = show_engine_name
|
self.views['show_engine_name'] = show_engine_name
|
||||||
|
|
||||||
|
@ -267,7 +267,7 @@ class DockerContainersExtension:
|
|||||||
self.stats_fetchers[container.id] = DockerStatsFetcher(container)
|
self.stats_fetchers[container.id] = DockerStatsFetcher(container)
|
||||||
|
|
||||||
# Stop threads for non-existing containers
|
# Stop threads for non-existing containers
|
||||||
absent_containers = set(iterkeys(self.stats_fetchers)) - set(c.id for c in containers)
|
absent_containers = set(iterkeys(self.stats_fetchers)) - {c.id for c in containers}
|
||||||
for container_id in absent_containers:
|
for container_id in absent_containers:
|
||||||
# Stop the StatsFetcher
|
# Stop the StatsFetcher
|
||||||
logger.debug(f"{self.ext_name} plugin - Stop thread for old container {container_id[:12]}")
|
logger.debug(f"{self.ext_name} plugin - Stop thread for old container {container_id[:12]}")
|
||||||
|
@ -278,7 +278,7 @@ class PodmanContainersExtension:
|
|||||||
self.container_stats_fetchers[container.id] = PodmanContainerStatsFetcher(container)
|
self.container_stats_fetchers[container.id] = PodmanContainerStatsFetcher(container)
|
||||||
|
|
||||||
# Stop threads for non-existing containers
|
# Stop threads for non-existing containers
|
||||||
absent_containers = set(iterkeys(self.container_stats_fetchers)) - set(c.id for c in containers)
|
absent_containers = set(iterkeys(self.container_stats_fetchers)) - {c.id for c in containers}
|
||||||
for container_id in absent_containers:
|
for container_id in absent_containers:
|
||||||
# Stop the StatsFetcher
|
# Stop the StatsFetcher
|
||||||
logger.debug(f"{self.ext_name} plugin - Stop thread for old container {container_id[:12]}")
|
logger.debug(f"{self.ext_name} plugin - Stop thread for old container {container_id[:12]}")
|
||||||
|
@ -188,7 +188,7 @@ class PluginModel(GlancesPluginModel):
|
|||||||
# Disk list (sorted by name)
|
# Disk list (sorted by name)
|
||||||
for i in self.sorted_stats():
|
for i in self.sorted_stats():
|
||||||
# Hide stats if never be different from 0 (issue #1787)
|
# Hide stats if never be different from 0 (issue #1787)
|
||||||
if all([self.get_views(item=i[self.get_key()], key=f, option='hidden') for f in self.hide_zero_fields]):
|
if all(self.get_views(item=i[self.get_key()], key=f, option='hidden') for f in self.hide_zero_fields):
|
||||||
continue
|
continue
|
||||||
# Is there an alias for the disk name ?
|
# Is there an alias for the disk name ?
|
||||||
disk_name = i['alias'] if 'alias' in i else i['disk_name']
|
disk_name = i['alias'] if 'alias' in i else i['disk_name']
|
||||||
|
@ -139,7 +139,7 @@ class PluginModel(GlancesPluginModel):
|
|||||||
logger.debug("Plugin - fs: PsUtil extended fetch failed")
|
logger.debug("Plugin - fs: PsUtil extended fetch failed")
|
||||||
else:
|
else:
|
||||||
# Discard duplicates (#2299) and add entries matching allowed fs types
|
# Discard duplicates (#2299) and add entries matching allowed fs types
|
||||||
tracked_mnt_points = set(f.mountpoint for f in fs_stat)
|
tracked_mnt_points = {f.mountpoint for f in fs_stat}
|
||||||
for f in all_mounted_fs:
|
for f in all_mounted_fs:
|
||||||
if (
|
if (
|
||||||
any(f.fstype.find(fs_type) >= 0 for fs_type in allowed_fs_types)
|
any(f.fstype.find(fs_type) >= 0 for fs_type in allowed_fs_types)
|
||||||
|
@ -64,7 +64,7 @@ class AmdGPU:
|
|||||||
stats = []
|
stats = []
|
||||||
|
|
||||||
for index, device in enumerate(self.device_folders):
|
for index, device in enumerate(self.device_folders):
|
||||||
device_stats = dict()
|
device_stats = {}
|
||||||
# Dictionary key is the GPU_ID
|
# Dictionary key is the GPU_ID
|
||||||
device_stats['key'] = 'gpu_id'
|
device_stats['key'] = 'gpu_id'
|
||||||
# GPU id (for multiple GPU, start at 0)
|
# GPU id (for multiple GPU, start at 0)
|
||||||
|
@ -49,7 +49,7 @@ class NvidiaGPU:
|
|||||||
stats = []
|
stats = []
|
||||||
|
|
||||||
for index, device_handle in enumerate(self.device_handles):
|
for index, device_handle in enumerate(self.device_handles):
|
||||||
device_stats = dict()
|
device_stats = {}
|
||||||
# Dictionary key is the GPU_ID
|
# Dictionary key is the GPU_ID
|
||||||
device_stats['key'] = 'gpu_id'
|
device_stats['key'] = 'gpu_id'
|
||||||
# GPU id (for multiple GPU, start at 0)
|
# GPU id (for multiple GPU, start at 0)
|
||||||
|
@ -259,7 +259,7 @@ class PluginModel(GlancesPluginModel):
|
|||||||
if ('is_up' in i) and (i['is_up'] is False):
|
if ('is_up' in i) and (i['is_up'] is False):
|
||||||
continue
|
continue
|
||||||
# Hide stats if never be different from 0 (issue #1787)
|
# Hide stats if never be different from 0 (issue #1787)
|
||||||
if all([self.get_views(item=i[self.get_key()], key=f, option='hidden') for f in self.hide_zero_fields]):
|
if all(self.get_views(item=i[self.get_key()], key=f, option='hidden') for f in self.hide_zero_fields):
|
||||||
continue
|
continue
|
||||||
# Format stats
|
# Format stats
|
||||||
# Is there an alias for the interface name ?
|
# Is there an alias for the interface name ?
|
||||||
|
@ -93,7 +93,7 @@ class GlancesPluginModel:
|
|||||||
self.stats_history = self.init_stats_history()
|
self.stats_history = self.init_stats_history()
|
||||||
|
|
||||||
# Init the limits (configuration keys) dictionary
|
# Init the limits (configuration keys) dictionary
|
||||||
self._limits = dict()
|
self._limits = {}
|
||||||
if config is not None:
|
if config is not None:
|
||||||
logger.debug(f'Load section {self.plugin_name} in {config.config_file_paths()}')
|
logger.debug(f'Load section {self.plugin_name} in {config.config_file_paths()}')
|
||||||
self.load_limits(config=config)
|
self.load_limits(config=config)
|
||||||
@ -105,7 +105,7 @@ class GlancesPluginModel:
|
|||||||
self.actions = GlancesActions(args=args)
|
self.actions = GlancesActions(args=args)
|
||||||
|
|
||||||
# Init the views
|
# Init the views
|
||||||
self.views = dict()
|
self.views = {}
|
||||||
|
|
||||||
# Hide stats if all the hide_zero_fields has never been != 0
|
# Hide stats if all the hide_zero_fields has never been != 0
|
||||||
# Default is False, always display stats
|
# Default is False, always display stats
|
||||||
@ -284,10 +284,8 @@ class GlancesPluginModel:
|
|||||||
return sorted(
|
return sorted(
|
||||||
self.stats,
|
self.stats,
|
||||||
key=lambda stat: tuple(
|
key=lambda stat: tuple(
|
||||||
map(
|
int(part) if part.isdigit() else part.lower()
|
||||||
lambda part: int(part) if part.isdigit() else part.lower(),
|
for part in re.split(r"(\d+|\D+)", self.has_alias(stat[key]) or stat[key])
|
||||||
re.split(r"(\d+|\D+)", self.has_alias(stat[key]) or stat[key]),
|
|
||||||
)
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
@ -295,7 +293,7 @@ class GlancesPluginModel:
|
|||||||
return sorted(
|
return sorted(
|
||||||
self.stats,
|
self.stats,
|
||||||
key=lambda stat: tuple(
|
key=lambda stat: tuple(
|
||||||
map(lambda part: part.lower(), re.split(r"(\d+|\D+)", self.has_alias(stat[key]) or stat[key]))
|
part.lower() for part in re.split(r"(\d+|\D+)", self.has_alias(stat[key]) or stat[key])
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -453,7 +451,7 @@ class GlancesPluginModel:
|
|||||||
if isinstance(self.get_raw(), list) and self.get_raw() is not None and self.get_key() is not None:
|
if isinstance(self.get_raw(), list) and self.get_raw() is not None and self.get_key() is not None:
|
||||||
# Stats are stored in a list of dict (ex: NETWORK, FS...)
|
# Stats are stored in a list of dict (ex: NETWORK, FS...)
|
||||||
for i in self.get_raw():
|
for i in self.get_raw():
|
||||||
if any([i[f] for f in self.hide_zero_fields]):
|
if any(i[f] for f in self.hide_zero_fields):
|
||||||
for f in self.hide_zero_fields:
|
for f in self.hide_zero_fields:
|
||||||
self.views[i[self.get_key()]][f]['_zero'] = self.views[i[self.get_key()]][f]['hidden']
|
self.views[i[self.get_key()]][f]['_zero'] = self.views[i[self.get_key()]][f]['hidden']
|
||||||
for f in self.hide_zero_fields:
|
for f in self.hide_zero_fields:
|
||||||
@ -465,7 +463,7 @@ class GlancesPluginModel:
|
|||||||
#
|
#
|
||||||
# Stats are stored in a dict (ex: CPU, LOAD...)
|
# Stats are stored in a dict (ex: CPU, LOAD...)
|
||||||
for key in listkeys(self.get_raw()):
|
for key in listkeys(self.get_raw()):
|
||||||
if any([self.get_raw()[f] for f in self.hide_zero_fields]):
|
if any(self.get_raw()[f] for f in self.hide_zero_fields):
|
||||||
for f in self.hide_zero_fields:
|
for f in self.hide_zero_fields:
|
||||||
self.views[f]['_zero'] = self.views[f]['hidden']
|
self.views[f]['_zero'] = self.views[f]['hidden']
|
||||||
for f in self.hide_zero_fields:
|
for f in self.hide_zero_fields:
|
||||||
@ -530,7 +528,7 @@ class GlancesPluginModel:
|
|||||||
|
|
||||||
def reset_views(self):
|
def reset_views(self):
|
||||||
"""Reset the views to input_views."""
|
"""Reset the views to input_views."""
|
||||||
self.views = dict()
|
self.views = {}
|
||||||
|
|
||||||
def get_views(self, item=None, key=None, option=None):
|
def get_views(self, item=None, key=None, option=None):
|
||||||
"""Return the views object.
|
"""Return the views object.
|
||||||
@ -888,7 +886,7 @@ class GlancesPluginModel:
|
|||||||
def read_alias(self):
|
def read_alias(self):
|
||||||
if self.plugin_name + '_' + 'alias' in self._limits:
|
if self.plugin_name + '_' + 'alias' in self._limits:
|
||||||
return {i.split(':')[0].lower(): i.split(':')[1] for i in self._limits[self.plugin_name + '_' + 'alias']}
|
return {i.split(':')[0].lower(): i.split(':')[1] for i in self._limits[self.plugin_name + '_' + 'alias']}
|
||||||
return dict()
|
return {}
|
||||||
|
|
||||||
def has_alias(self, header):
|
def has_alias(self, header):
|
||||||
"""Return the alias name for the relative header it it exists otherwise None."""
|
"""Return the alias name for the relative header it it exists otherwise None."""
|
||||||
|
@ -179,7 +179,7 @@ class PluginModel(GlancesPluginModel):
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
# Define the data: Bar (default behavior) or Sparkline
|
# Define the data: Bar (default behavior) or Sparkline
|
||||||
data = dict()
|
data = {}
|
||||||
for key in self.stats_list:
|
for key in self.stats_list:
|
||||||
if self.args.sparkline and self.history_enable() and not self.args.client:
|
if self.args.sparkline and self.history_enable() and not self.args.client:
|
||||||
data[key] = Sparkline(max_width)
|
data[key] = Sparkline(max_width)
|
||||||
|
@ -233,7 +233,7 @@ class GlancesStats:
|
|||||||
"""
|
"""
|
||||||
if enable:
|
if enable:
|
||||||
return [p for p in self._plugins if self._plugins[p].is_enabled()]
|
return [p for p in self._plugins if self._plugins[p].is_enabled()]
|
||||||
return [p for p in self._plugins]
|
return list(self._plugins)
|
||||||
|
|
||||||
def getExportsList(self, enable=True):
|
def getExportsList(self, enable=True):
|
||||||
"""Return the exports list.
|
"""Return the exports list.
|
||||||
@ -244,8 +244,8 @@ class GlancesStats:
|
|||||||
:return: list of export module names
|
:return: list of export module names
|
||||||
"""
|
"""
|
||||||
if enable:
|
if enable:
|
||||||
return [e for e in self._exports]
|
return list(self._exports)
|
||||||
return [e for e in self._exports_all]
|
return list(self._exports_all)
|
||||||
|
|
||||||
def load_limits(self, config=None):
|
def load_limits(self, config=None):
|
||||||
"""Load the stats limits (except the one in the exclude list)."""
|
"""Load the stats limits (except the one in the exclude list)."""
|
||||||
|
@ -20,7 +20,7 @@ select = [
|
|||||||
# "N", # pep8-naming
|
# "N", # pep8-naming
|
||||||
"W", # pycodestyle
|
"W", # pycodestyle
|
||||||
"UP", # pyupgrde
|
"UP", # pyupgrde
|
||||||
# "C4", # flake8-comprehensions
|
"C4", # flake8-comprehensions
|
||||||
"RET", # flake8-return
|
"RET", # flake8-return
|
||||||
# "FBT", # flake8-boolean-trap
|
# "FBT", # flake8-boolean-trap
|
||||||
# "RUF", # Ruff-specific rules
|
# "RUF", # Ruff-specific rules
|
||||||
|
@ -74,10 +74,8 @@ class TestGlances(unittest.TestCase):
|
|||||||
self.assertEqual(plugin_instance.get_key(), None)
|
self.assertEqual(plugin_instance.get_key(), None)
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
all(
|
all(
|
||||||
[
|
f in [h['name'] for h in plugin_instance.items_history_list]
|
||||||
f in [h['name'] for h in plugin_instance.items_history_list]
|
for f in plugin_instance.get_raw_history()
|
||||||
for f in plugin_instance.get_raw_history()
|
|
||||||
]
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
elif plugin_instance.history_enable() and isinstance(plugin_instance.get_raw(), list):
|
elif plugin_instance.history_enable() and isinstance(plugin_instance.get_raw(), list):
|
||||||
|
Loading…
Reference in New Issue
Block a user