Completed
Push — master ( 2b80fa...6ea077 )
by Nicolas
01:22
created

Plugin.generate_view_data()   A

Complexity

Conditions 2

Size

Total Lines 48

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
c 1
b 0
f 1
dl 0
loc 48
rs 9.125
1
# -*- coding: utf-8 -*-
2
#
3
# This file is part of Glances.
4
#
5
# Copyright (C) 2017 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
32
    """Glances help plugin."""
33
34
    def __init__(self, args=None, config=None):
35
        """Init the plugin."""
36
        super(Plugin, self).__init__(args=args)
37
38
        # Set the config instance
39
        self.config = config
40
41
        # We want to display the stat in the curse interface
42
        self.display_curse = True
43
44
        # init data dictionary
45
        self.view_data = {}
46
        self.generate_view_data()
47
48
    def update(self):
49
        """No stats. It is just a plugin to display the help."""
50
        pass
51
52
    def generate_view_data(self):
53
        self.view_data['version'] = '{} {}'.format('Glances', __version__)
54
        self.view_data['psutil_version'] = ' with PSutil {}'.format(psutil_version)
55
56
        try:
57
            self.view_data['configuration_file'] = 'Configuration file: {}'.format(self.config.loaded_config_file)
58
        except AttributeError:
59
            pass
60
61
        msg_col = ' {0:1}  {1:35}'
62
        msg_col2 = '   {0:1}  {1:35}'
63
        self.view_data['sort_auto'] = msg_col.format('a', 'Sort processes automatically')
64
        self.view_data['sort_network'] = msg_col2.format('b', 'Bytes or bits for network I/O')
65
        self.view_data['sort_cpu'] = msg_col.format('c', 'Sort processes by CPU%')
66
        self.view_data['show_hide_alert'] = msg_col2.format('l', 'Show/hide alert logs')
67
        self.view_data['sort_mem'] = msg_col.format('m', 'Sort processes by MEM%')
68
        self.view_data['sort_user'] = msg_col.format('u', 'Sort processes by USER')
69
        self.view_data['delete_warning_alerts'] = msg_col2.format('w', 'Delete warning alerts')
70
        self.view_data['sort_proc'] = msg_col.format('p', 'Sort processes by name')
71
        self.view_data['delete_warning_critical_alerts'] = msg_col2.format('x', 'Delete warning and critical alerts')
72
        self.view_data['sort_io'] = msg_col.format('i', 'Sort processes by I/O rate')
73
        self.view_data['percpu'] = msg_col2.format('1', 'Global CPU or per-CPU stats')
74
        self.view_data['sort_cpu_times'] = msg_col.format('t', 'Sort processes by TIME')
75
        self.view_data['show_hide_help'] = msg_col2.format('h', 'Show/hide this help screen')
76
        self.view_data['show_hide_diskio'] = msg_col.format('d', 'Show/hide disk I/O stats')
77
        self.view_data['show_hide_irq'] = msg_col2.format('Q', 'Show/hide IRQ stats')
78
        self.view_data['view_network_io_combination'] = msg_col2.format('T', 'View network I/O as combination')
79
        self.view_data['show_hide_filesystem'] = msg_col.format('f', 'Show/hide filesystem stats')
80
        self.view_data['view_cumulative_network'] = msg_col2.format('U', 'View cumulative network I/O')
81
        self.view_data['show_hide_network'] = msg_col.format('n', 'Show/hide network stats')
82
        self.view_data['show_hide_filesytem_freespace'] = msg_col2.format('F', 'Show filesystem free space')
83
        self.view_data['show_hide_sensors'] = msg_col.format('s', 'Show/hide sensors stats')
84
        self.view_data['generate_graphs'] = msg_col2.format('g', 'Generate graphs for current history')
85
        self.view_data['show_hide_left_sidebar'] = msg_col.format('2', 'Show/hide left sidebar')
86
        self.view_data['reset_history'] = msg_col2.format('r', 'Reset history')
87
        self.view_data['enable_disable_process_stats'] = msg_col.format('z', 'Enable/disable processes stats')
88
        self.view_data['quit'] = msg_col2.format('q', 'Quit (Esc and Ctrl-C also work)')
89
        self.view_data['enable_disable_top_extends_stats'] = msg_col.format('e', 'Enable/disable top extended stats')
90
        self.view_data['enable_disable_short_processname'] = msg_col.format('/', 'Enable/disable short processes name')
91
        self.view_data['enable_disable_irix'] = msg_col.format('0', 'Enable/disable Irix process CPU')
92
        self.view_data['enable_disable_docker'] = msg_col2.format('D', 'Enable/disable Docker stats')
93
        self.view_data['enable_disable_quick_look'] = msg_col.format('3', 'Enable/disable quick look plugin')
94
        self.view_data['show_hide_ip'] = msg_col2.format('I', 'Show/hide IP module')
95
        self.view_data['diskio_iops'] = msg_col2.format('B', 'Count/rate for Disk I/O')
96
        self.view_data['show_hide_top_menu'] = msg_col2.format('5', 'Show/hide top menu (QL, CPU, MEM, SWAP and LOAD)')
97
        self.view_data['enable_disable_gpu'] = msg_col.format('G', 'Enable/disable gpu plugin')
98
        self.view_data['enable_disable_mean_gpu'] = msg_col2.format('6', 'Enable/disable mean gpu')
99
        self.view_data['edit_pattern_filter'] = 'ENTER: Edit the process filter pattern'
100
101
    def get_view_data(self, args=None):
102
        return self.view_data
103
104
    def msg_curse(self, args=None):
105
        """Return the list to display in the curse interface."""
106
        # Init the return message
107
        ret = []
108
109
        # Build the string message
110
        # Header
111
        ret.append(self.curse_add_line(self.view_data['version'], 'TITLE'))
112
        ret.append(self.curse_add_line(self.view_data['psutil_version']))
113
        ret.append(self.curse_new_line())
114
115
        # Configuration file path
116
        if 'configuration_file' in self.view_data:
117
            ret.append(self.curse_new_line())
118
            ret.append(self.curse_add_line(self.view_data['configuration_file']))
119
            ret.append(self.curse_new_line())
120
121
        # Keys
122
        ret.append(self.curse_new_line())
123
        ret.append(self.curse_add_line(self.view_data['sort_auto']))
124
        ret.append(self.curse_add_line(self.view_data['sort_network']))
125
        ret.append(self.curse_new_line())
126
        ret.append(self.curse_add_line(self.view_data['sort_cpu']))
127
        ret.append(self.curse_add_line(self.view_data['show_hide_alert']))
128
        ret.append(self.curse_new_line())
129
130
        ret.append(self.curse_add_line(self.view_data['sort_mem']))
131
        ret.append(self.curse_add_line(self.view_data['delete_warning_alerts']))
132
        ret.append(self.curse_new_line())
133
        ret.append(self.curse_add_line(self.view_data['sort_user']))
134
        ret.append(self.curse_add_line(self.view_data['delete_warning_critical_alerts']))
135
        ret.append(self.curse_new_line())
136
        ret.append(self.curse_add_line(self.view_data['sort_proc']))
137
        ret.append(self.curse_add_line(self.view_data['percpu']))
138
        ret.append(self.curse_new_line())
139
        ret.append(self.curse_add_line(self.view_data['sort_io']))
140
        ret.append(self.curse_add_line(self.view_data['show_hide_ip']))
141
        ret.append(self.curse_new_line())
142
        ret.append(self.curse_add_line(self.view_data['sort_cpu_times']))
143
        ret.append(self.curse_add_line(self.view_data['enable_disable_docker']))
144
        ret.append(self.curse_new_line())
145
        ret.append(self.curse_add_line(self.view_data['show_hide_diskio']))
146
        ret.append(self.curse_add_line(self.view_data['view_network_io_combination']))
147
        ret.append(self.curse_new_line())
148
        ret.append(self.curse_add_line(self.view_data['show_hide_filesystem']))
149
        ret.append(self.curse_add_line(self.view_data['view_cumulative_network']))
150
        ret.append(self.curse_new_line())
151
        ret.append(self.curse_add_line(self.view_data['show_hide_network']))
152
        ret.append(self.curse_add_line(self.view_data['show_hide_filesytem_freespace']))
153
        ret.append(self.curse_new_line())
154
        ret.append(self.curse_add_line(self.view_data['show_hide_sensors']))
155
        ret.append(self.curse_add_line(self.view_data['generate_graphs']))
156
        ret.append(self.curse_new_line())
157
        ret.append(self.curse_add_line(self.view_data['show_hide_left_sidebar']))
158
        ret.append(self.curse_add_line(self.view_data['reset_history']))
159
        ret.append(self.curse_new_line())
160
        ret.append(self.curse_add_line(self.view_data['enable_disable_process_stats']))
161
        ret.append(self.curse_add_line(self.view_data['show_hide_help']))
162
        ret.append(self.curse_new_line())
163
        ret.append(self.curse_add_line(self.view_data['enable_disable_quick_look']))
164
        ret.append(self.curse_add_line(self.view_data['diskio_iops']))
165
        ret.append(self.curse_new_line())
166
        ret.append(self.curse_add_line(self.view_data['enable_disable_top_extends_stats']))
167
        ret.append(self.curse_add_line(self.view_data['show_hide_top_menu']))
168
        ret.append(self.curse_new_line())
169
        ret.append(self.curse_add_line(self.view_data['enable_disable_short_processname']))
170
        ret.append(self.curse_add_line(self.view_data['show_hide_irq']))
171
        ret.append(self.curse_new_line())
172
        ret.append(self.curse_add_line(self.view_data['enable_disable_gpu']))
173
        ret.append(self.curse_add_line(self.view_data['enable_disable_mean_gpu']))
174
        ret.append(self.curse_new_line())
175
        ret.append(self.curse_add_line(self.view_data['enable_disable_irix']))
176
        ret.append(self.curse_add_line(self.view_data['quit']))
177
        ret.append(self.curse_new_line())
178
179
        ret.append(self.curse_new_line())
180
181
        ret.append(self.curse_add_line(self.view_data['edit_pattern_filter']))
182
183
        # Return the message with decoration
184
        return ret
185