diff options
author | RazCrimson <52282402+RazCrimson@users.noreply.github.com> | 2021-11-28 16:32:50 +0530 |
---|---|---|
committer | RazCrimson <52282402+RazCrimson@users.noreply.github.com> | 2021-11-28 16:37:37 +0530 |
commit | 88816ae785fd56b557348f1be294c6bc2f7002ce (patch) | |
tree | c559af4628b501a2a66e7baf63a62ef317203c32 /glances | |
parent | 2eae445e4de9e0d7022159c3b57cb5b1c9ab34e4 (diff) |
refactor: Outputs cleanup
Diffstat (limited to 'glances')
-rw-r--r-- | glances/outputs/glances_bars.py | 2 | ||||
-rw-r--r-- | glances/outputs/glances_curses.py | 84 | ||||
-rw-r--r-- | glances/outputs/glances_curses_browser.py | 39 | ||||
-rw-r--r-- | glances/outputs/glances_sparklines.py | 4 | ||||
-rw-r--r-- | glances/outputs/glances_stdout.py | 9 | ||||
-rw-r--r-- | glances/outputs/glances_stdout_apidoc.py | 7 | ||||
-rw-r--r-- | glances/outputs/glances_stdout_csv.py | 9 | ||||
-rw-r--r-- | glances/outputs/glances_stdout_issue.py | 7 |
8 files changed, 78 insertions, 83 deletions
diff --git a/glances/outputs/glances_bars.py b/glances/outputs/glances_bars.py index fda2039f..e663ac84 100644 --- a/glances/outputs/glances_bars.py +++ b/glances/outputs/glances_bars.py @@ -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 diff --git a/glances/outputs/glances_curses.py b/glances/outputs/glances_curses.py index 9b3b5278..da6dd920 100644 --- a/glances/outputs/glances_curses.py +++ b/glances/outputs/glances_curses.py @@ -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). """ diff --git a/glances/outputs/glances_curses_browser.py b/glances/outputs/glances_curses_browser.py index 9539f8d5..640b3b4d 100644 --- a/glances/outputs/glances_curses_browser.py +++ b/glances/outputs/glances_curses_browser.py @@ -97,18 +97,18 @@ class GlancesCursesBrowser(_GlancesCurses): for item in stats: color = item['status'] counts[color] = counts.get(color, 0) + 1 - + result = '' for key in counts.keys(): result += key + ': ' + str(counts[key]) + ' ' - + return result def _get_stats(self, stats): stats_list = None if self._stats_list is not None: stats_list = self._stats_list - stats_list.sort(reverse = self._revesed_sorting, + stats_list.sort(reverse = self._revesed_sorting, key = lambda x: { 'UNKNOWN' : 0, 'OFFLINE' : 1, 'PROTECTED' : 2, @@ -116,9 +116,9 @@ class GlancesCursesBrowser(_GlancesCurses): 'ONLINE': 4 }.get(x['status'], 99)) else: stats_list = stats - + return stats_list - + def cursor_up(self, stats): """Set the cursor to position N-1 in the list.""" if 0 <= self.cursor_position - 1: @@ -126,14 +126,14 @@ class GlancesCursesBrowser(_GlancesCurses): else: if self._current_page - 1 < 0 : self._current_page = self._page_max - 1 - self.cursor_position = (len(stats) - 1) % self._page_max_lines + self.cursor_position = (len(stats) - 1) % self._page_max_lines else: self._current_page -= 1 self.cursor_position = self._page_max_lines - 1 def cursor_down(self, stats): """Set the cursor to position N-1 in the list.""" - + if self.cursor_position + 1 < self.get_pagelines(stats): self.cursor_position += 1 else: @@ -186,7 +186,7 @@ class GlancesCursesBrowser(_GlancesCurses): self.cursor_down(stats) logger.debug("Server {}/{} selected".format(self.cursor + 1, len(stats))) elif self.pressedkey == curses.KEY_PPAGE: - # 'Page UP' > Prev page in the server list + # 'Page UP' > Prev page in the server list self.cursor_pageup(stats) logger.debug("PageUP: Server ({}/{}) pages.".format(self._current_page + 1, self._page_max)) elif self.pressedkey == curses.KEY_NPAGE: @@ -197,7 +197,7 @@ class GlancesCursesBrowser(_GlancesCurses): self._stats_list = None refresh = True elif self.pressedkey == ord('2'): - self._revesed_sorting = False + self._revesed_sorting = False self._stats_list = stats.copy() refresh = True elif self.pressedkey == ord('3'): @@ -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() @@ -301,13 +302,13 @@ class GlancesCursesBrowser(_GlancesCurses): if stats_len > stats_max and screen_y > 2: msg = '{} servers displayed.({}/{}) {}'.format(self.get_pagelines(stats), - self._current_page + 1, - self._page_max, + self._current_page + 1, + self._page_max, self._get_status_count(stats)) self.term_window.addnstr(y + 1, x, msg, screen_x - x) - + if stats_len == 0: return False @@ -347,10 +348,10 @@ class GlancesCursesBrowser(_GlancesCurses): self.cursor = len(stats) - 1 stats_list = self._get_stats(stats) - start_line = self._page_max_lines * self._current_page + start_line = self._page_max_lines * self._current_page end_line = start_line + self.get_pagelines(stats_list) current_page = stats_list[start_line:end_line] - + # Display table line = 0 for v in current_page: diff --git a/glances/outputs/glances_sparklines.py b/glances/outputs/glances_sparklines.py index 5423c953..49531edb 100644 --- a/glances/outputs/glances_sparklines.py +++ b/glances/outputs/glances_sparklines.py @@ -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: diff --git a/glances/outputs/glances_stdout.py b/glances/outputs/glances_stdout.py index 0ea67f6f..b7b8626e 100644 --- a/glances/outputs/glances_stdout.py +++ b/glances/outputs/glances_stdout.py @@ -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: diff --git a/glances/outputs/glances_stdout_apidoc.py b/glances/outputs/glances_stdout_apidoc.py index eb1e4acc..deb6ba4c 100644 --- a/glances/outputs/glances_stdout_apidoc.py +++ b/glances/outputs/glances_stdout_apidoc.py @@ -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) diff --git a/glances/outputs/glances_stdout_csv.py b/glances/outputs/glances_stdout_csv.py index 7ec3eafd..8cc13c35 100644 --- a/glances/outputs/glances_stdout_csv.py +++ b/glances/outputs/glances_stdout_csv.py @@ -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 diff --git a/glances/outputs/glances_stdout_issue.py b/glances/outputs/glances_stdout_issue.py index c8676e4a..4f86322c 100644 --- a/glances/outputs/glances_stdout_issue.py +++ b/glances/outputs/glances_stdout_issue.py @@ -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): |