提交 d4f06b3e 编写于 作者: S sangoh.hong

improved server list sorting.

上级 61dbe609
...@@ -62,7 +62,7 @@ class GlancesCursesBrowser(_GlancesCurses): ...@@ -62,7 +62,7 @@ class GlancesCursesBrowser(_GlancesCurses):
self._page_max_lines = 0 self._page_max_lines = 0
self.is_end = False self.is_end = False
self._sort_order_list = None self._revesed_sorting = False
self._stats_list = None self._stats_list = None
@property @property
...@@ -104,19 +104,21 @@ class GlancesCursesBrowser(_GlancesCurses): ...@@ -104,19 +104,21 @@ class GlancesCursesBrowser(_GlancesCurses):
return result return result
def _sort_by_status(self, item): def _get_stats(self, stats):
key = item['status'] stats_list = None
if key == 'ONLINE': if self._stats_list is not None:
return self._sort_order_list[0] stats_list = self._stats_list
elif key == 'SNMP': stats_list.sort(reverse = self._revesed_sorting,
return self._sort_order_list[1] key = lambda x: { 'UNKNOWN' : 0,
elif key == 'PROTECTED': 'OFFLINE' : 1,
return self._sort_order_list[2] 'PROTECTED' : 2,
elif key == 'OFFLINE': 'SNMP' : 3,
return self._sort_order_list[3] 'ONLINE': 4 }.get(x['status'], 99))
elif key == 'UNKNOWN': else:
return self._sort_order_list[4] stats_list = stats
return stats_list
def cursor_up(self, stats): def cursor_up(self, stats):
"""Set the cursor to position N-1 in the list.""" """Set the cursor to position N-1 in the list."""
if 0 <= self.cursor_position - 1: if 0 <= self.cursor_position - 1:
...@@ -192,15 +194,14 @@ class GlancesCursesBrowser(_GlancesCurses): ...@@ -192,15 +194,14 @@ class GlancesCursesBrowser(_GlancesCurses):
self.cursor_pagedown(stats) self.cursor_pagedown(stats)
logger.debug("PageDown: Server {}/{} pages".format(self._current_page + 1, self._page_max)) logger.debug("PageDown: Server {}/{} pages".format(self._current_page + 1, self._page_max))
elif self.pressedkey == ord('1'): elif self.pressedkey == ord('1'):
self._sort_order_list = None
self._stats_list = None self._stats_list = None
refresh = True refresh = True
elif self.pressedkey == ord('2'): elif self.pressedkey == ord('2'):
self._sort_order_list = [0,1,2,3,4] self._revesed_sorting = False
self._stats_list = stats.copy() self._stats_list = stats.copy()
refresh = True refresh = True
elif self.pressedkey == ord('3'): elif self.pressedkey == ord('3'):
self._sort_order_list = [4,3,2,1,0] self._revesed_sorting = True
self._stats_list = stats.copy() self._stats_list = stats.copy()
refresh = True refresh = True
...@@ -292,6 +293,12 @@ class GlancesCursesBrowser(_GlancesCurses): ...@@ -292,6 +293,12 @@ class GlancesCursesBrowser(_GlancesCurses):
msg, msg,
screen_x - x, screen_x - x,
self.colors_list['TITLE']) self.colors_list['TITLE'])
msg = '{}'.format(self._get_status_count(stats))
self.term_window.addnstr(y + 1, x,
msg,
screen_x - x)
if stats_len > stats_max and screen_y > 2: if stats_len > stats_max and screen_y > 2:
msg = '{} servers displayed.({}/{}) {}'.format(self.get_pagelines(stats), msg = '{} servers displayed.({}/{}) {}'.format(self.get_pagelines(stats),
self._current_page + 1, self._current_page + 1,
...@@ -339,13 +346,7 @@ class GlancesCursesBrowser(_GlancesCurses): ...@@ -339,13 +346,7 @@ class GlancesCursesBrowser(_GlancesCurses):
# Set the cursor position to the latest item # Set the cursor position to the latest item
self.cursor = len(stats) - 1 self.cursor = len(stats) - 1
stats_list = None stats_list = self._get_stats(stats)
if self._sort_order_list is not None and self._stats_list is not None:
stats_list = self._stats_list
stats_list.sort(key=self._sort_by_status)
else:
stats_list = 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) end_line = start_line + self.get_pagelines(stats_list)
current_page = stats_list[start_line:end_line] current_page = stats_list[start_line:end_line]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册