refactor: Outputs cleanup

This commit is contained in:
RazCrimson 2021-11-28 16:32:50 +05:30
parent 2eae445e4d
commit 88816ae785
8 changed files with 78 additions and 83 deletions

View File

@ -26,7 +26,7 @@ from math import modf
class Bar(object):
r"""Manage bar (progression or status).
"""Manage bar (progression or status).
import sys
import time

View File

@ -324,7 +324,7 @@ class _GlancesCurses(object):
}
def set_cursor(self, value):
"""Configure the curse cursor apparence.
"""Configure the curse cursor appearance.
0: invisible
1: visible
@ -527,8 +527,10 @@ class _GlancesCurses(object):
def __get_stat_display(self, stats, layer):
"""Return a dict of dict with all the stats display.
stats: Global stats dict
layer: ~ cs_status
# TODO: Drop extra parameter
:param stats: Global stats dict
:param layer: ~ cs_status
"None": standalone or server mode
"Connected": Client is connected to a Glances server
"SNMP": Client is connected to a SNMP server
@ -563,16 +565,14 @@ class _GlancesCurses(object):
def display(self, stats, cs_status=None):
"""Display stats on the screen.
stats: Stats database to display
cs_status:
:param stats: Stats database to display
:param cs_status:
"None": standalone or server mode
"Connected": Client is connected to a Glances server
"SNMP": Client is connected to a SNMP server
"Disconnected": Client is disconnected from the server
Return:
True if the stats have been displayed
False if the help have been displayed
:return True if the stats have been displayed else False if the help have been displayed
"""
# Init the internal line/column for Glances Curses
self.init_line_column()
@ -580,7 +580,7 @@ class _GlancesCurses(object):
# Update the stats messages
###########################
# Get all the plugins but quicklook and proceslist
# Get all the plugins but quicklook and process list
self.args.cs_status = cs_status
__stat_display = self.__get_stat_display(stats, layer=cs_status)
@ -625,7 +625,7 @@ class _GlancesCurses(object):
# =====================================
# Display first line (system+ip+uptime)
# Optionnaly: Cloud on second line
# Optionally: Cloud on second line
# =====================================
self.__display_header(__stat_display)
@ -854,8 +854,8 @@ class _GlancesCurses(object):
"""
Display a centered popup.
popup_type='info'
Just an infotmation popup, no user interaction
popup_type: ='info'
Just an information popup, no user interaction
Display a centered popup with the given message during duration seconds
If size_x and size_y: set the popup size
else set it automatically
@ -906,19 +906,19 @@ class _GlancesCurses(object):
self.wait(duration * 1000)
return True
elif popup_type == 'input':
# Create a subwindow for the text field
subpop = popup.derwin(1, input_size, 2, 2 + len(m))
subpop.attron(self.colors_list['FILTER'])
# Create a sub-window for the text field
sub_pop = popup.derwin(1, input_size, 2, 2 + len(m))
sub_pop.attron(self.colors_list['FILTER'])
# Init the field with the current value
if input_value is not None:
subpop.addnstr(0, 0, input_value, len(input_value))
sub_pop.addnstr(0, 0, input_value, len(input_value))
# Display the popup
popup.refresh()
subpop.refresh()
# Create the textbox inside the subwindows
sub_pop.refresh()
# Create the textbox inside the sub-windows
self.set_cursor(2)
self.term_window.keypad(1)
textbox = GlancesTextbox(subpop, insert_mode=True)
textbox = GlancesTextbox(sub_pop, insert_mode=True)
textbox.edit()
self.set_cursor(0)
# self.term_window.keypad(0)
@ -930,18 +930,18 @@ class _GlancesCurses(object):
logger.debug("User centers an empty string")
return None
elif popup_type == 'yesno':
# # Create a subwindow for the text field
subpop = popup.derwin(1, 2, len(sentence_list) + 1, len(m) + 2)
subpop.attron(self.colors_list['FILTER'])
# # Create a sub-window for the text field
sub_pop = popup.derwin(1, 2, len(sentence_list) + 1, len(m) + 2)
sub_pop.attron(self.colors_list['FILTER'])
# Init the field with the current value
subpop.addnstr(0, 0, '', 0)
sub_pop.addnstr(0, 0, '', 0)
# Display the popup
popup.refresh()
subpop.refresh()
# Create the textbox inside the subwindows
sub_pop.refresh()
# Create the textbox inside the sub-windows
self.set_cursor(2)
self.term_window.keypad(1)
textbox = GlancesTextboxYesNo(subpop, insert_mode=False)
textbox = GlancesTextboxYesNo(sub_pop, insert_mode=False)
textbox.edit()
self.set_cursor(0)
# self.term_window.keypad(0)
@ -954,10 +954,11 @@ class _GlancesCurses(object):
add_space=0):
"""Display the plugin_stats on the screen.
If display_optional=True display the optional stats
If display_additional=True display additionnal stats
max_y: do not display line > max_y
add_space: add x space (line) after the plugin
:param plugin_stats:
:param display_optional: display the optional stats if True
:param display_additional: display additional stats if True
:param max_y: do not display line > max_y
:param add_space: add x space (line) after the plugin
"""
# Exit if:
# - the plugin_stats message is empty
@ -1012,11 +1013,11 @@ class _GlancesCurses(object):
if not display_additional and m['additional']:
continue
# Is it possible to display the stat with the current screen size
# !!! Crach if not try/except... Why ???
# !!! Crash if not try/except... Why ???
try:
self.term_window.addnstr(y, x,
m['msg'],
# Do not disply outside the screen
# Do not display outside the screen
screen_x - x,
self.colors_list[m['decoration']])
except Exception:
@ -1050,8 +1051,8 @@ class _GlancesCurses(object):
def flush(self, stats, cs_status=None):
"""Clear and update the screen.
stats: Stats database to display
cs_status:
:param stats: Stats database to display
:param cs_status:
"None": standalone or server mode
"Connected": Client is connected to the server
"Disconnected": Client is disconnected from the server
@ -1066,20 +1067,17 @@ class _GlancesCurses(object):
return_to_browser=False):
"""Update the screen.
INPUT
stats: Stats database to display
duration: duration of the loop
cs_status:
:param stats: Stats database to display
:param duration: duration of the loop
:param cs_status:
"None": standalone or server mode
"Connected": Client is connected to the server
"Disconnected": Client is disconnected from the server
return_to_browser:
:param return_to_browser:
True: Do not exist, return to the browser list
False: Exit and return to the shell
OUTPUT
True: Exit key has been pressed
False: Others cases...
:return: True if exit key has been pressed else False
"""
# Flush display
self.flush(stats, cs_status=cs_status)
@ -1140,7 +1138,7 @@ class _GlancesCurses(object):
return c
def get_stats_display_height(self, curse_msg):
r"""Return the height of the formatted curses message.
"""Return the height of the formatted curses message.
The height is defined by the number of '\n' (new line).
"""

View File

@ -222,7 +222,10 @@ class GlancesCursesBrowser(_GlancesCurses):
Wait for __refresh_time sec / catch key every 100 ms.
stats: Dict of dict with servers stats
:param stats: Dict of dict with servers stats
:param cs_status:
:param duration:
:param return_to_browser:
"""
# Flush display
logger.debug('Servers list: {}'.format(stats))
@ -248,7 +251,7 @@ class GlancesCursesBrowser(_GlancesCurses):
def flush(self, stats):
"""Update the servers' list screen.
stats: List of dict with servers stats
:param stats: List of dict with servers stats
"""
self.erase()
self.display(stats)
@ -256,9 +259,7 @@ class GlancesCursesBrowser(_GlancesCurses):
def display(self, stats, cs_status=None):
"""Display the servers list.
Return:
True if the stats have been displayed
False if the stats have not been displayed (no server available)
:return: True if the stats have been displayed else False (no server available)
"""
# Init the internal line/column for Glances Curses
self.init_line_column()

View File

@ -43,7 +43,7 @@ except (UnicodeEncodeError, TypeError) as e:
class Sparkline(object):
r"""Manage sparklines (see https://pypi.org/project/sparklines/)."""
"""Manage sparklines (see https://pypi.org/project/sparklines/)."""
def __init__(self, size, pre_char='[', post_char=']', empty_char=' ', with_text=True):
# If the sparklines python module available ?
@ -64,7 +64,7 @@ class Sparkline(object):
@property
def size(self, with_decoration=False):
# Return the sparkine size, with or without decoration
# Return the sparkline size, with or without decoration
if with_decoration:
return self.__size
if self.__with_text:

View File

@ -27,9 +27,7 @@ from glances.compat import printandflush
class GlancesStdout(object):
"""
This class manages the Stdout display.
"""
"""This class manages the Stdout display."""
def __init__(self, config=None, args=None):
# Init
@ -41,7 +39,9 @@ class GlancesStdout(object):
def build_list(self):
"""Return a list of tuples taken from self.args.stdout
[(plugin, attribute), ... ]"""
:return: A list of tuples. Example -[(plugin, attribute), ... ]
"""
ret = []
for p in self.args.stdout.split(','):
if '.' in p:
@ -58,6 +58,7 @@ class GlancesStdout(object):
stats,
duration=3):
"""Display stats to stdout.
Refresh every duration second.
"""
for plugin, attribute in self.plugins_list:

View File

@ -184,9 +184,7 @@ def print_limits(stats):
class GlancesStdoutApiDoc(object):
"""
This class manages the fields description display.
"""
"""This class manages the fields description display."""
def __init__(self, config=None, args=None):
# Init
@ -199,8 +197,7 @@ class GlancesStdoutApiDoc(object):
def update(self,
stats,
duration=1):
"""Display issue
"""
"""Display issue"""
# Display header
print(APIDOC_HEADER)

View File

@ -27,9 +27,7 @@ from glances.compat import printandflush
class GlancesStdoutCsv(object):
"""
This class manages the StdoutCsv display.
"""
"""This class manages the StdoutCsv display."""
separator = ','
na = 'N/A'
@ -47,7 +45,9 @@ class GlancesStdoutCsv(object):
def build_list(self):
"""Return a list of tuples taken from self.args.stdout
[(plugin, attribute), ... ]"""
:return: A list of tuples. Example -[(plugin, attribute), ... ]
"""
ret = []
for p in self.args.stdout_csv.split(','):
if '.' in p:
@ -110,6 +110,7 @@ class GlancesStdoutCsv(object):
stats,
duration=3):
"""Display stats to stdout.
Refresh every duration second.
"""
# Build the stats list

View File

@ -54,9 +54,7 @@ class colors:
class GlancesStdoutIssue(object):
"""
This class manages the Issue display.
"""
"""This class manages the Issue display."""
def __init__(self, config=None, args=None):
# Init
@ -89,8 +87,7 @@ class GlancesStdoutIssue(object):
def update(self,
stats,
duration=3):
"""Display issue
"""
"""Display issue"""
self.print_version()
for plugin in sorted(stats._plugins):