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

glances/stats_client.py (9 issues)

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
0 ignored issues
show
import missing from __future__ import absolute_import
Loading history...
23
24
from glances.stats import GlancesStats
0 ignored issues
show
import missing from __future__ import absolute_import
Loading history...
25
from glances.globals import sys_path
0 ignored issues
show
import missing from __future__ import absolute_import
Loading history...
26
from glances.logger import logger
0 ignored issues
show
import missing from __future__ import absolute_import
Loading history...
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))
0 ignored issues
show
This line is too long as per the coding-style (121/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
Use formatting in logging functions and pass the parameters as arguments
Loading history...
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))
0 ignored issues
show
Use formatting in logging functions and pass the parameters as arguments
Loading history...
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:
0 ignored issues
show
Coding Style Naming introduced by
The name p does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
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