Test Failed
Push — develop ( d7cf39...faa4bd )
by Nicolas
04:34 queued 10s
created

glances/stats_client.py (1 issue)

Checks congruence of parent and child method arguments

Bug Minor
1
# -*- coding: utf-8 -*-
2
#
3
# This file is part of Glances.
4
#
5
# Copyright (C) 2019 Nicolargo <[email protected]>
6
#
7
# Glances is free software; you can redistribute it and/or modify
8
# it under the terms of the GNU Lesser General Public License as published by
9
# the Free Software Foundation, either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Glances is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU Lesser General Public License for more details.
16
#
17
# You should have received a copy of the GNU Lesser General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20
"""The stats server manager."""
21
22
import sys
23
24
from glances.stats import GlancesStats
25
from glances.globals import sys_path
26
from glances.logger import logger
27
28
29
class GlancesStatsClient(GlancesStats):
30
31
    """This class stores, updates and gives stats for the client."""
32
33
    def __init__(self, config=None, args=None):
34
        """Init the GlancesStatsClient class."""
35
        super(GlancesStatsClient, self).__init__(config=config, args=args)
36
37
        # Init the configuration
38
        self.config = config
39
40
        # Init the arguments
41
        self.args = args
42
43
    def set_plugins(self, input_plugins):
44
        """Set the plugin list according to the Glances server."""
45
        header = "glances_"
46
        for item in input_plugins:
47
            # Import the plugin
48
            try:
49
                plugin = __import__(header + item)
50
            except ImportError:
51
                # Server plugin can not be imported from the client side
52
                logger.error("Can not import {} plugin. Please upgrade your Glances client/server version.".format(item))
53
            else:
54
                # Add the plugin to the dictionary
55
                # The key is the plugin name
56
                # for example, the file glances_xxx.py
57
                # generate self._plugins_list["xxx"] = ...
58
                logger.debug("Server uses {} plugin".format(item))
59
                self._plugins[item] = plugin.Plugin(args=self.args)
60
        # Restoring system path
61
        sys.path = sys_path
62
63
    def update(self, input_stats):
0 ignored issues
show
Parameters differ from overridden 'update' method
Loading history...
64
        """Update all the stats."""
65
        # For Glances client mode
66
        for p in input_stats:
67
            # Update plugin stats with items sent by the server
68
            self._plugins[p].set_stats(input_stats[p])
69
            # Update the views for the updated stats
70
            self._plugins[p].update_views()
71