Test Failed
Push — develop ( 66c9ff...e21229 )
by Nicolas
05:06
created

glances/plugins/glances_help.py (4 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
"""
21
Help plugin.
22
23
Just a stupid plugin to display the help screen.
24
"""
25
26
from glances import __version__, psutil_version
27
from glances.plugins.glances_plugin import GlancesPlugin
28
29
30
class Plugin(GlancesPlugin):
31
    """Glances help plugin."""
32
33
    def __init__(self, args=None, config=None):
34
        """Init the plugin."""
35
        super(Plugin, self).__init__(args=args, config=config)
36
37
        # Set the config instance
38
        self.config = config
39
40
        # We want to display the stat in the curse interface
41
        self.display_curse = True
42
43
        # init data dictionary
44
        self.view_data = {}
45
        self.generate_view_data()
46
47
    def reset(self):
48
        """No stats. It is just a plugin to display the help."""
49
        pass
50
51
    def update(self):
52
        """No stats. It is just a plugin to display the help."""
53
        pass
54
55
    def generate_view_data(self):
56
        """Generate the views."""
57
        self.view_data['version'] = '{} {}'.format('Glances', __version__)
58
        self.view_data['psutil_version'] = ' with psutil {}'.format(psutil_version)
59
60
        try:
61
            self.view_data['configuration_file'] = 'Configuration file: {}'.format(self.config.loaded_config_file)
62
        except AttributeError:
63
            pass
64
65
        msg_col = ' {0:1}  {1:35}'
66
        msg_col2 = '   {0:1}  {1:35}'
67
        self.view_data['sort_auto'] = msg_col.format('a', 'Sort processes automatically')
68
        self.view_data['sort_network'] = msg_col2.format('b', 'Bytes or bits for network I/O')
69
        self.view_data['sort_cpu'] = msg_col.format('c', 'Sort processes by CPU%')
70
        self.view_data['show_hide_alert'] = msg_col2.format('l', 'Show/hide alert logs')
71
        self.view_data['sort_mem'] = msg_col.format('m', 'Sort processes by MEM%')
72
        self.view_data['sort_user'] = msg_col.format('u', 'Sort processes by USER')
73
        self.view_data['delete_warning_alerts'] = msg_col2.format('w', 'Delete warning alerts')
74
        self.view_data['sort_proc'] = msg_col.format('p', 'Sort processes by name')
75
        self.view_data['delete_warning_critical_alerts'] = msg_col2.format('x', 'Delete warning and critical alerts')
76
        self.view_data['sort_io'] = msg_col.format('i', 'Sort processes by I/O rate')
77
        self.view_data['percpu'] = msg_col2.format('1', 'Global CPU or per-CPU stats')
78
        self.view_data['sort_cpu_times'] = msg_col.format('t', 'Sort processes by TIME')
79
        self.view_data['show_hide_help'] = msg_col2.format('h', 'Show/hide this help screen')
80
        self.view_data['show_hide_diskio'] = msg_col.format('d', 'Show/hide disk I/O stats')
81
        self.view_data['show_hide_irq'] = msg_col2.format('Q', 'Show/hide IRQ stats')
82
        self.view_data['view_network_io_combination'] = msg_col2.format('T', 'View network I/O as combination')
83
        self.view_data['show_hide_filesystem'] = msg_col.format('f', 'Show/hide filesystem stats')
84
        self.view_data['view_cumulative_network'] = msg_col2.format('U', 'View cumulative network I/O')
85
        self.view_data['show_hide_network'] = msg_col.format('n', 'Show/hide network stats')
86
        self.view_data['show_hide_filesytem_freespace'] = msg_col2.format('F', 'Show filesystem free space')
87
        self.view_data['show_hide_sensors'] = msg_col.format('s', 'Show/hide sensors stats')
88
        self.view_data['generate_graphs'] = msg_col2.format('g', 'Generate graphs for current history')
89
        self.view_data['show_hide_left_sidebar'] = msg_col.format('2', 'Show/hide left sidebar')
90
        self.view_data['reset_history'] = msg_col2.format('r', 'Reset history')
91
        self.view_data['enable_disable_process_stats'] = msg_col.format('z', 'Enable/disable processes stats')
92
        self.view_data['quit'] = msg_col2.format('q', 'Quit (Esc and Ctrl-C also work)')
93
        self.view_data['enable_disable_top_extends_stats'] = msg_col.format('e', 'Enable/disable top extended stats')
94
        self.view_data['enable_disable_short_processname'] = msg_col.format('/', 'Enable/disable short processes name')
95
        self.view_data['enable_disable_irix'] = msg_col.format('0', 'Enable/disable Irix process CPU')
96
        self.view_data['enable_disable_docker'] = msg_col2.format('D', 'Enable/disable Docker stats')
97
        self.view_data['enable_disable_quick_look'] = msg_col.format('3', 'Enable/disable quick look plugin')
98
        self.view_data['show_hide_ip'] = msg_col2.format('I', 'Show/hide IP module')
99
        self.view_data['diskio_iops'] = msg_col2.format('B', 'Count/rate for Disk I/O')
100
        self.view_data['show_hide_top_menu'] = msg_col2.format('5', 'Show/hide top menu (QL, CPU, MEM, SWAP and LOAD)')
101
        self.view_data['enable_disable_gpu'] = msg_col.format('G', 'Enable/disable gpu plugin')
0 ignored issues
show
This line is too long as per the coding-style (95/80).

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

Loading history...
102
        self.view_data['enable_disable_mean_gpu'] = msg_col2.format('6', 'Enable/disable mean gpu')
0 ignored issues
show
This line is too long as per the coding-style (99/80).

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

Loading history...
103
        self.view_data['edit_pattern_filter'] = 'ENTER: Edit the process filter pattern'
104
105
    def get_view_data(self, args=None):
0 ignored issues
show
The argument args seems to be unused.
Loading history...
106
        """Return the view."""
107
        return self.view_data
108
109
    def msg_curse(self, args=None, max_width=None):
110
        """Return the list to display in the curse interface."""
111
        # Init the return message
112
        ret = []
113
114
        # Build the string message
115
        # Header
116
        ret.append(self.curse_add_line(self.view_data['version'], 'TITLE'))
117
        ret.append(self.curse_add_line(self.view_data['psutil_version']))
118
        ret.append(self.curse_new_line())
119
120
        # Configuration file path
121
        if 'configuration_file' in self.view_data:
122
            ret.append(self.curse_new_line())
123
            ret.append(self.curse_add_line(self.view_data['configuration_file']))
124
            ret.append(self.curse_new_line())
125
126
        # Keys
127
        ret.append(self.curse_new_line())
128
        ret.append(self.curse_add_line(self.view_data['sort_auto']))
129
        ret.append(self.curse_add_line(self.view_data['sort_network']))
130
        ret.append(self.curse_new_line())
131
        ret.append(self.curse_add_line(self.view_data['sort_cpu']))
132
        ret.append(self.curse_add_line(self.view_data['show_hide_alert']))
133
        ret.append(self.curse_new_line())
134
135
        ret.append(self.curse_add_line(self.view_data['sort_mem']))
136
        ret.append(self.curse_add_line(self.view_data['delete_warning_alerts']))
137
        ret.append(self.curse_new_line())
138
        ret.append(self.curse_add_line(self.view_data['sort_user']))
139
        ret.append(self.curse_add_line(self.view_data['delete_warning_critical_alerts']))
140
        ret.append(self.curse_new_line())
141
        ret.append(self.curse_add_line(self.view_data['sort_proc']))
142
        ret.append(self.curse_add_line(self.view_data['percpu']))
143
        ret.append(self.curse_new_line())
144
        ret.append(self.curse_add_line(self.view_data['sort_io']))
145
        ret.append(self.curse_add_line(self.view_data['show_hide_ip']))
146
        ret.append(self.curse_new_line())
147
        ret.append(self.curse_add_line(self.view_data['sort_cpu_times']))
148
        ret.append(self.curse_add_line(self.view_data['enable_disable_docker']))
149
        ret.append(self.curse_new_line())
150
        ret.append(self.curse_add_line(self.view_data['show_hide_diskio']))
151
        ret.append(self.curse_add_line(self.view_data['view_network_io_combination']))
152
        ret.append(self.curse_new_line())
153
        ret.append(self.curse_add_line(self.view_data['show_hide_filesystem']))
154
        ret.append(self.curse_add_line(self.view_data['view_cumulative_network']))
155
        ret.append(self.curse_new_line())
156
        ret.append(self.curse_add_line(self.view_data['show_hide_network']))
157
        ret.append(self.curse_add_line(self.view_data['show_hide_filesytem_freespace']))
158
        ret.append(self.curse_new_line())
159
        ret.append(self.curse_add_line(self.view_data['show_hide_sensors']))
160
        ret.append(self.curse_add_line(self.view_data['generate_graphs']))
161
        ret.append(self.curse_new_line())
162
        ret.append(self.curse_add_line(self.view_data['show_hide_left_sidebar']))
163
        ret.append(self.curse_add_line(self.view_data['reset_history']))
164
        ret.append(self.curse_new_line())
165
        ret.append(self.curse_add_line(self.view_data['enable_disable_process_stats']))
166
        ret.append(self.curse_add_line(self.view_data['show_hide_help']))
167
        ret.append(self.curse_new_line())
168
        ret.append(self.curse_add_line(self.view_data['enable_disable_quick_look']))
169
        ret.append(self.curse_add_line(self.view_data['diskio_iops']))
170
        ret.append(self.curse_new_line())
171
        ret.append(self.curse_add_line(self.view_data['enable_disable_top_extends_stats']))
172
        ret.append(self.curse_add_line(self.view_data['show_hide_top_menu']))
173
        ret.append(self.curse_new_line())
174
        ret.append(self.curse_add_line(self.view_data['enable_disable_short_processname']))
175
        ret.append(self.curse_add_line(self.view_data['show_hide_irq']))
176
        ret.append(self.curse_new_line())
177
        ret.append(self.curse_add_line(self.view_data['enable_disable_gpu']))
178
        ret.append(self.curse_add_line(self.view_data['enable_disable_mean_gpu']))
0 ignored issues
show
This line is too long as per the coding-style (82/80).

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

Loading history...
179
        ret.append(self.curse_new_line())
180
        ret.append(self.curse_add_line(self.view_data['enable_disable_irix']))
181
        ret.append(self.curse_add_line(self.view_data['quit']))
182
        ret.append(self.curse_new_line())
183
184
        ret.append(self.curse_new_line())
185
186
        ret.append(self.curse_add_line(self.view_data['edit_pattern_filter']))
187
188
        # Return the message with decoration
189
        return ret
190