summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicolargo <nicolas@nicolargo.com>2022-09-28 19:10:40 +0200
committernicolargo <nicolas@nicolargo.com>2022-09-28 19:10:40 +0200
commit16832111eea3d7b85f5d172b0b627bdc1b18200c (patch)
tree86f835307880bb9269c50e95b9263c9cbb2cc7ba
parent7849b9b991f991a0283e69adbe92ffb317d65aaa (diff)
parent77133b8d9d5b00ebb8caa3146bd7e3c4e71f3a11 (diff)
:Merge branch 'ankostis-help-9' into develop
-rw-r--r--glances/plugins/glances_help.py245
1 files changed, 102 insertions, 143 deletions
diff --git a/glances/plugins/glances_help.py b/glances/plugins/glances_help.py
index 2d3fadf2..ffc374a8 100644
--- a/glances/plugins/glances_help.py
+++ b/glances/plugins/glances_help.py
@@ -12,9 +12,12 @@ Help plugin.
Just a stupid plugin to display the help screen.
"""
-
+import sys
+from glances.compat import iteritems
+from collections import OrderedDict
from glances import __version__, psutil_version
from glances.plugins.glances_plugin import GlancesPlugin
+from itertools import chain
class Plugin(GlancesPlugin):
@@ -30,8 +33,13 @@ class Plugin(GlancesPlugin):
# We want to display the stat in the curse interface
self.display_curse = True
- # init data dictionary
- self.view_data = {}
+ # init data dictionary, to preserve insertion order
+ if sys.version_info < (3, 6):
+ from collections import OrderedDict
+
+ self.view_data = OrderedDict()
+ else:
+ self.view_data = {}
self.generate_view_data()
def reset(self):
@@ -53,68 +61,69 @@ class Plugin(GlancesPlugin):
msg_col = ' {0:1} {1:34}'
msg_header = '{0:39}'
- """First column"""
- self.view_data['header_sort'] = msg_header.format('SORT PROCESSES:')
- self.view_data['sort_auto'] = msg_col.format('a', 'Automatically')
- self.view_data['sort_cpu'] = msg_col.format('c', 'CPU%')
- self.view_data['sort_io_rate'] = msg_col.format('i', 'I/O rate')
- self.view_data['sort_mem'] = msg_col.format('m', 'MEM%')
- self.view_data['sort_process_name'] = msg_col.format('p', 'Process name')
- self.view_data['sort_cpu_times'] = msg_col.format('t', 'TIME')
- self.view_data['sort_user'] = msg_col.format('u', 'USER')
-
- self.view_data['header_show_hide'] = msg_header.format('SHOW/HIDE SECTION:')
- self.view_data['show_hide_application_monitoring'] = msg_col.format('A', 'Application monitoring')
- self.view_data['show_hide_diskio'] = msg_col.format('d', 'Disk I/O')
- self.view_data['show_hide_docker'] = msg_col.format('D', 'Docker')
- self.view_data['show_hide_top_extended_stats'] = msg_col.format('e', 'Top extended stats')
- self.view_data['show_hide_filesystem'] = msg_col.format('f', 'Filesystem')
- self.view_data['show_hide_gpu'] = msg_col.format('G', 'GPU')
- self.view_data['show_hide_ip'] = msg_col.format('I', 'IP')
- self.view_data['show_hide_tcp_connection'] = msg_col.format('K', 'TCP')
- self.view_data['show_hide_alert'] = msg_col.format('l', 'Alert logs')
- self.view_data['show_hide_network'] = msg_col.format('n', 'Network')
- self.view_data['show_hide_current_time'] = msg_col.format('N', 'Time')
- self.view_data['show_hide_irq'] = msg_col.format('Q', 'IRQ')
- self.view_data['show_hide_raid_plugin'] = msg_col.format('R', 'RAID')
- self.view_data['show_hide_sensors'] = msg_col.format('s', 'Sensors')
- self.view_data['show_hide_wifi_module'] = msg_col.format('W', 'Wifi')
- self.view_data['show_hide_processes'] = msg_col.format('z', 'Processes')
- self.view_data['show_hide_left_sidebar'] = msg_col.format('2', 'Left sidebar')
-
- """Second column"""
- self.view_data['show_hide_quick_look'] = msg_col.format('3', 'Quick Look')
- self.view_data['show_hide_cpu_mem_swap'] = msg_col.format('4', 'CPU, MEM, and SWAP')
- self.view_data['show_hide_all'] = msg_col.format('5', 'ALL')
-
- self.view_data['header_toggle'] = msg_header.format('TOGGLE DATA TYPE:')
- self.view_data['toggle_bits_bytes'] = msg_col.format('b', 'Network I/O: bits/bytes')
- self.view_data['toggle_count_rate'] = msg_col.format('B', 'Disk I/O: count/rate')
- self.view_data['toggle_used_free'] = msg_col.format('F', 'Filesystem space: used/free')
- self.view_data['toggle_bar_sparkline'] = msg_col.format('S', 'Quick Look: bar/sparkline')
- self.view_data['toggle_separate_combined'] = msg_col.format('T', 'Network I/O: separate/combined')
- self.view_data['toggle_live_cumulative'] = msg_col.format('U', 'Network I/O: live/cumulative')
- self.view_data['toggle_linux_percentage'] = msg_col.format('0', 'Load: Linux/percentage')
- self.view_data['toggle_cpu_individual_combined'] = msg_col.format('1', 'CPU: individual/combined')
- self.view_data['toggle_gpu_individual_combined'] = msg_col.format('6', 'GPU: individual/combined')
- self.view_data['toggle_short_full'] = msg_col.format('/', 'Process names: short/full')
-
- self.view_data['header_miscellaneous'] = msg_header.format('MISCELLANEOUS:')
- self.view_data['misc_erase_process_filter'] = msg_col.format('E', 'Erase process filter')
- self.view_data['misc_generate_history_graphs'] = msg_col.format('g', 'Generate history graphs')
- self.view_data['misc_help'] = msg_col.format('h', 'HELP')
- self.view_data['misc_accumulate_processes_by_program'] = msg_col.format('j', 'Accumulate processes by program')
- self.view_data['misc_increase_nice_process'] = msg_col.format('+', 'Increase nice process (need admin rights)')
- self.view_data['misc_decrease_nice_process'] = msg_col.format('-', 'Decrease nice process')
- self.view_data['misc_kill_process'] = msg_col.format('k', 'Kill process')
- self.view_data['misc_reset_processes_summary_min_max'] = msg_col.format('M', 'Reset processes summary min/max')
- self.view_data['misc_quit'] = msg_col.format('q', 'QUIT (or Esc or Ctrl-C)')
- self.view_data['misc_reset_history'] = msg_col.format('r', 'Reset history')
- self.view_data['misc_delete_warning_alerts'] = msg_col.format('w', 'Delete warning alerts')
- self.view_data['misc_delete_warning_and_critical_alerts'] = msg_col.format(
- 'x', 'Delete warning & critical alerts'
+ self.view_data.update(
+ [
+ ## First column
+ #
+ ('header_sort', msg_header.format('SORT PROCESSES:')),
+ ('sort_auto', msg_col.format('a', 'Automatically')),
+ ('sort_cpu', msg_col.format('c', 'CPU%')),
+ ('sort_io_rate', msg_col.format('i', 'I/O rate')),
+ ('sort_mem', msg_col.format('m', 'MEM%')),
+ ('sort_process_name', msg_col.format('p', 'Process name')),
+ ('sort_cpu_times', msg_col.format('t', 'TIME')),
+ ('sort_user', msg_col.format('u', 'USER')),
+ ('header_show_hide', msg_header.format('SHOW/HIDE SECTION:')),
+ ('show_hide_application_monitoring', msg_col.format('A', 'Application monitoring')),
+ ('show_hide_diskio', msg_col.format('d', 'Disk I/O')),
+ ('show_hide_docker', msg_col.format('D', 'Docker')),
+ ('show_hide_top_extended_stats', msg_col.format('e', 'Top extended stats')),
+ ('show_hide_filesystem', msg_col.format('f', 'Filesystem')),
+ ('show_hide_gpu', msg_col.format('G', 'GPU')),
+ ('show_hide_ip', msg_col.format('I', 'IP')),
+ ('show_hide_tcp_connection', msg_col.format('K', 'TCP')),
+ ('show_hide_alert', msg_col.format('l', 'Alert logs')),
+ ('show_hide_network', msg_col.format('n', 'Network')),
+ ('show_hide_current_time', msg_col.format('N', 'Time')),
+ ('show_hide_irq', msg_col.format('Q', 'IRQ')),
+ ('show_hide_raid_plugin', msg_col.format('R', 'RAID')),
+ ('show_hide_sensors', msg_col.format('s', 'Sensors')),
+ ('show_hide_wifi_module', msg_col.format('W', 'Wifi')),
+ ('show_hide_processes', msg_col.format('z', 'Processes')),
+ ('show_hide_left_sidebar', msg_col.format('2', 'Left sidebar')),
+ ## Second column
+ #
+ ('show_hide_quick_look', msg_col.format('3', 'Quick Look')),
+ ('show_hide_cpu_mem_swap', msg_col.format('4', 'CPU, MEM, and SWAP')),
+ ('show_hide_all', msg_col.format('5', 'ALL')),
+ ('header_toggle', msg_header.format('TOGGLE DATA TYPE:')),
+ ('toggle_bits_bytes', msg_col.format('b', 'Network I/O, bits/bytes')),
+ ('toggle_count_rate', msg_col.format('B', 'Disk I/O, count/rate')),
+ ('toggle_used_free', msg_col.format('F', 'Filesystem space, used/free')),
+ ('toggle_bar_sparkline', msg_col.format('S', 'Quick Look, bar/sparkline')),
+ ('toggle_separate_combined', msg_col.format('T', 'Network I/O, separate/combined')),
+ ('toggle_live_cumulative', msg_col.format('U', 'Network I/O, live/cumulative')),
+ ('toggle_linux_percentage', msg_col.format('0', 'Load, Linux/percentage')),
+ ('toggle_cpu_individual_combined', msg_col.format('1', 'CPU, individual/combined')),
+ ('toggle_gpu_individual_combined', msg_col.format('6', 'GPU, individual/combined')),
+ ('toggle_short_full', msg_col.format('/', 'Process names, short/full')),
+ ('header_miscellaneous', msg_header.format('MISCELLANEOUS:')),
+ ('misc_erase_process_filter', msg_col.format('E', 'Erase process filter')),
+ ('misc_generate_history_graphs', msg_col.format('g', 'Generate history graphs')),
+ ('misc_help', msg_col.format('h', 'HELP')),
+ ('misc_accumulate_processes_by_program', msg_col.format('j', 'Accumulate processes by program')),
+ ('misc_increase_nice_process', msg_col.format('+', 'Increase nice process')),
+ ('misc_decrease_nice_process', msg_col.format('-', 'Decrease nice process (need admin rights)')),
+ ('misc_kill_process', msg_col.format('k', 'Kill process')),
+ ('misc_reset_processes_summary_min_max', msg_col.format('M', 'Reset processes summary min/max')),
+ ('misc_quit', msg_col.format('q', 'QUIT (or Esc or Ctrl-C)')),
+ ('misc_reset_history', msg_col.format('r', 'Reset history')),
+ ('misc_delete_warning_alerts', msg_col.format('w', 'Delete warning alerts')),
+ ('misc_delete_warning_and_critical_alerts', msg_col.format('x', 'Delete warning & critical alerts')),
+ ('misc_theme_white', msg_col.format('9', 'Optimize colors for white background')),
+ ('misc_edit_process_filter_pattern', ' ENTER: Edit process filter pattern'),
+ ]
)
- self.view_data['misc_edit_process_filter_pattern'] = ' ENTER: Edit process filter pattern'
def get_view_data(self, args=None):
"""Return the view."""
@@ -137,87 +146,37 @@ class Plugin(GlancesPlugin):
ret.append(self.curse_new_line())
- # Keys
- ret.append(self.curse_add_line(self.view_data['header_sort']))
- ret.append(self.curse_add_line(self.view_data['show_hide_quick_look']))
- ret.append(self.curse_new_line())
- ret.append(self.curse_add_line(self.view_data['sort_auto']))
- ret.append(self.curse_add_line(self.view_data['show_hide_cpu_mem_swap']))
- ret.append(self.curse_new_line())
- ret.append(self.curse_add_line(self.view_data['sort_cpu']))
- ret.append(self.curse_add_line(self.view_data['show_hide_all']))
- ret.append(self.curse_new_line())
- ret.append(self.curse_add_line(self.view_data['sort_io_rate']))
- ret.append(self.curse_add_line(self.view_data['header_toggle']))
- ret.append(self.curse_new_line())
- ret.append(self.curse_add_line(self.view_data['sort_mem']))
- ret.append(self.curse_add_line(self.view_data['toggle_bits_bytes']))
- ret.append(self.curse_new_line())
- ret.append(self.curse_add_line(self.view_data['sort_process_name']))
- ret.append(self.curse_add_line(self.view_data['toggle_count_rate']))
- ret.append(self.curse_new_line())
- ret.append(self.curse_add_line(self.view_data['sort_cpu_times']))
- ret.append(self.curse_add_line(self.view_data['toggle_used_free']))
- ret.append(self.curse_new_line())
- ret.append(self.curse_add_line(self.view_data['sort_user']))
- ret.append(self.curse_add_line(self.view_data['toggle_bar_sparkline']))
- ret.append(self.curse_new_line())
- ret.append(self.curse_add_line(self.view_data['header_show_hide']))
- ret.append(self.curse_add_line(self.view_data['toggle_separate_combined']))
- ret.append(self.curse_new_line())
- ret.append(self.curse_add_line(self.view_data['show_hide_application_monitoring']))
- ret.append(self.curse_add_line(self.view_data['toggle_live_cumulative']))
- ret.append(self.curse_new_line())
- ret.append(self.curse_add_line(self.view_data['show_hide_diskio']))
- ret.append(self.curse_add_line(self.view_data['toggle_linux_percentage']))
- ret.append(self.curse_new_line())
- ret.append(self.curse_add_line(self.view_data['show_hide_docker']))
- ret.append(self.curse_add_line(self.view_data['toggle_cpu_individual_combined']))
- ret.append(self.curse_new_line())
- ret.append(self.curse_add_line(self.view_data['show_hide_top_extended_stats']))
- ret.append(self.curse_add_line(self.view_data['toggle_gpu_individual_combined']))
- ret.append(self.curse_new_line())
- ret.append(self.curse_add_line(self.view_data['show_hide_filesystem']))
- ret.append(self.curse_add_line(self.view_data['toggle_short_full']))
- ret.append(self.curse_new_line())
- ret.append(self.curse_add_line(self.view_data['show_hide_gpu']))
- ret.append(self.curse_add_line(self.view_data['header_miscellaneous']))
- ret.append(self.curse_new_line())
- ret.append(self.curse_add_line(self.view_data['show_hide_ip']))
- ret.append(self.curse_add_line(self.view_data['misc_erase_process_filter']))
- ret.append(self.curse_new_line())
- ret.append(self.curse_add_line(self.view_data['show_hide_tcp_connection']))
- ret.append(self.curse_add_line(self.view_data['misc_generate_history_graphs']))
- ret.append(self.curse_new_line())
- ret.append(self.curse_add_line(self.view_data['show_hide_alert']))
- ret.append(self.curse_add_line(self.view_data['misc_help']))
- ret.append(self.curse_new_line())
- ret.append(self.curse_add_line(self.view_data['show_hide_network']))
- ret.append(self.curse_add_line(self.view_data['misc_accumulate_processes_by_program']))
- ret.append(self.curse_new_line())
- ret.append(self.curse_add_line(self.view_data['show_hide_current_time']))
- ret.append(self.curse_add_line(self.view_data['misc_kill_process']))
- ret.append(self.curse_new_line())
- ret.append(self.curse_add_line(self.view_data['show_hide_irq']))
- ret.append(self.curse_add_line(self.view_data['misc_reset_processes_summary_min_max']))
- ret.append(self.curse_new_line())
- ret.append(self.curse_add_line(self.view_data['show_hide_raid_plugin']))
- ret.append(self.curse_add_line(self.view_data['misc_quit']))
- ret.append(self.curse_new_line())
- ret.append(self.curse_add_line(self.view_data['show_hide_sensors']))
- ret.append(self.curse_add_line(self.view_data['misc_reset_history']))
- ret.append(self.curse_new_line())
- ret.append(self.curse_add_line(self.view_data['show_hide_wifi_module']))
- ret.append(self.curse_add_line(self.view_data['misc_delete_warning_alerts']))
- ret.append(self.curse_new_line())
- ret.append(self.curse_add_line(self.view_data['show_hide_processes']))
- ret.append(self.curse_add_line(self.view_data['misc_delete_warning_and_critical_alerts']))
- ret.append(self.curse_new_line())
- ret.append(self.curse_add_line(self.view_data['show_hide_left_sidebar']))
- ret.append(self.curse_add_line(self.view_data['misc_edit_process_filter_pattern']))
+ ## key-shortcuts
+ #
+ # Collect all values after the 1st key-msg
+ # in a list of curse-lines.
+ #
+ shortcuts = []
+ collecting = False
+ for k, v in iteritems(self.view_data):
+ if collecting:
+ pass
+ elif k == 'header_sort':
+ collecting = True
+ else:
+ continue
+ shortcuts.append(self.curse_add_line(v))
+ # Divide shortcuts into 2 columns
+ # and if number of schortcuts is even,
+ # make the 1st column taller (len+1).
+ #
+ nlines = (len(shortcuts) + 1) // 2
+ ret.extend(
+ msg
+ for triplet in zip(
+ iter(shortcuts[:nlines]),
+ chain(shortcuts[nlines:], iter(lambda: self.curse_add_line(''), None)),
+ iter(self.curse_new_line, None),
+ )
+ for msg in triplet
+ )
ret.append(self.curse_new_line())
- ret.append(self.curse_new_line())
ret.append(self.curse_add_line('For an exhaustive list of key bindings:'))
ret.append(self.curse_new_line())
ret.append(self.curse_add_line('https://glances.readthedocs.io/en/latest/cmds.html#interactive-commands'))