|
1
|
|
|
# |
|
2
|
|
|
# This file is part of Glances. |
|
3
|
|
|
# |
|
4
|
|
|
# SPDX-FileCopyrightText: 2025 Nicolas Hennion <[email protected]> |
|
5
|
|
|
# |
|
6
|
|
|
# SPDX-License-Identifier: LGPL-3.0-only |
|
7
|
|
|
# |
|
8
|
|
|
|
|
9
|
|
|
# Glances DAG (direct acyclic graph) for plugins dependencies. |
|
10
|
|
|
# It allows to define DAG dependencies between plugins |
|
11
|
|
|
# For the moment, it will be used only for Restful API interface |
|
12
|
|
|
|
|
13
|
|
|
_plugins_graph = { |
|
14
|
|
|
'*': ['alert'], # All plugins depend on alert plugin |
|
15
|
|
|
'cpu': ['core'], |
|
16
|
|
|
'load': ['core'], |
|
17
|
|
|
'processlist': ['core', 'processcount'], |
|
18
|
|
|
'programlist': ['processcount'], |
|
19
|
|
|
'quicklook': ['fs', 'load'], |
|
20
|
|
|
'vms': ['processcount'], |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
def get_plugin_dependencies(plugin_name, _graph=_plugins_graph): |
|
25
|
|
|
"""Return all transitive dependencies for a given plugin (including global ones).""" |
|
26
|
|
|
seen = set() |
|
27
|
|
|
|
|
28
|
|
|
def _resolve(plugin): |
|
29
|
|
|
if plugin in seen: |
|
30
|
|
|
return |
|
31
|
|
|
seen.add(plugin) |
|
32
|
|
|
|
|
33
|
|
|
# Get direct dependencies of this plugin |
|
34
|
|
|
deps = _graph.get(plugin, []) |
|
35
|
|
|
for dep in deps: |
|
36
|
|
|
_resolve(dep) |
|
37
|
|
|
|
|
38
|
|
|
# Resolve dependencies for this plugin |
|
39
|
|
|
_resolve(plugin_name) |
|
40
|
|
|
|
|
41
|
|
|
# Add global ("*") dependencies |
|
42
|
|
|
for dep in _graph.get('*', []): |
|
43
|
|
|
_resolve(dep) |
|
44
|
|
|
|
|
45
|
|
|
# Remove the plugin itself if present |
|
46
|
|
|
seen.discard(plugin_name) |
|
47
|
|
|
|
|
48
|
|
|
# Preserve order of discovery (optional, for deterministic results) |
|
49
|
|
|
result = [] |
|
50
|
|
|
added = set() |
|
51
|
|
|
for dep in _graph.get(plugin_name, []) + _graph.get('*', []): |
|
52
|
|
|
for d in _dfs_order(dep, _graph, set()): |
|
53
|
|
|
if d not in added and d != plugin_name: |
|
54
|
|
|
result.append(d) |
|
55
|
|
|
added.add(d) |
|
56
|
|
|
return [plugin_name] + result |
|
57
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
def _dfs_order(plugin, graph, seen): |
|
60
|
|
|
"""Helper to preserve depth-first order.""" |
|
61
|
|
|
if plugin in seen: |
|
62
|
|
|
return [] |
|
63
|
|
|
seen.add(plugin) |
|
64
|
|
|
order = [] |
|
65
|
|
|
for dep in graph.get(plugin, []): |
|
66
|
|
|
order.extend(_dfs_order(dep, graph, seen)) |
|
67
|
|
|
order.append(plugin) |
|
68
|
|
|
return order |
|
69
|
|
|
|