Add a connected to / disconnected from server message

This commit is contained in:
Nicolas Hennion 2012-11-06 15:25:11 +01:00
parent ce67fedd01
commit db25171a88

View File

@ -1140,7 +1140,15 @@ class glancesScreen:
curses.curs_set(1) curses.curs_set(1)
curses.endwin() curses.endwin()
def display(self, stats): def display(self, stats, cs_status = "None"):
"""
Display stats on the screen
cs_status:
"None": standalone or server mode
"Connected": Client is connected to the server
"Disconnected": Client is disconnected from the server
"""
# Get stats for processes (used in another functions for logs) # Get stats for processes (used in another functions for logs)
processcount = stats.getProcessCount() processcount = stats.getProcessCount()
processlist = stats.getProcessList(screen.getProcessSortedBy()) processlist = stats.getProcessList(screen.getProcessSortedBy())
@ -1158,7 +1166,7 @@ class glancesScreen:
log_count = self.displayLog(self.network_y + network_count + log_count = self.displayLog(self.network_y + network_count +
diskio_count + fs_count) diskio_count + fs_count)
self.displayProcess(processcount, processlist, log_count) self.displayProcess(processcount, processlist, log_count)
self.displayCaption() self.displayCaption(cs_status = cs_status)
self.displayNow(stats.getNow()) self.displayNow(stats.getNow())
self.displayHelp() self.displayHelp()
@ -1166,14 +1174,29 @@ class glancesScreen:
# Erase the content of the screen # Erase the content of the screen
self.term_window.erase() self.term_window.erase()
def flush(self, stats): def flush(self, stats, cs_status = "None"):
"""
Clear and update screen
cs_status:
"None": standalone or server mode
"Connected": Client is connected to the server
"Disconnected": Client is disconnected from the server
"""
# Flush display # Flush display
self.erase() self.erase()
self.display(stats) self.display(stats, cs_status = cs_status)
def update(self, stats, cs_status = "None"):
"""
Update the screen and wait __refresh_time sec / catch key every 100 ms
cs_status:
"None": standalone or server mode
"Connected": Client is connected to the server
"Disconnected": Client is disconnected from the server
"""
def update(self, stats):
# flush display # flush display
self.flush(stats) self.flush(stats, cs_status = cs_status)
# Wait # Wait
countdown = Timer(self.__refresh_time) countdown = Timer(self.__refresh_time)
@ -1181,7 +1204,7 @@ class glancesScreen:
# Getkey # Getkey
if self.__catchKey() > -1: if self.__catchKey() > -1:
# flush display # flush display
self.flush(stats) self.flush(stats, cs_status = cs_status)
# Wait 100ms... # Wait 100ms...
curses.napms(100) curses.napms(100)
@ -1824,20 +1847,32 @@ class glancesScreen:
process_x + process_name_x, process_x + process_name_x,
command, max_process_name) command, max_process_name)
def displayCaption(self): def displayCaption(self, cs_status = "None"):
"""
Display the caption (bottom left)
cs_status:
"None": standalone or server mode
"Connected": Client is connected to the server
"Disconnected": Client is disconnected from the server
"""
# Caption # Caption
screen_x = self.screen.getmaxyx()[1] screen_x = self.screen.getmaxyx()[1]
screen_y = self.screen.getmaxyx()[0] screen_y = self.screen.getmaxyx()[0]
if (client_tag): if (client_tag):
if (cs_status.lower() == "connected"):
msg_client = _("Connected to")+" "+format(server_ip) msg_client = _("Connected to")+" "+format(server_ip)
msg_client_style = self.default_color2 if self.hascolors else curses.A_UNDERLINE
elif (cs_status.lower() == "disconnected"):
msg_client = _("Disconnected from")+" "+format(server_ip)
msg_client_style = self.ifCRITICAL_color2 if self.hascolors else curses.A_UNDERLINE
msg_help = _("Press 'h' for help") msg_help = _("Press 'h' for help")
if (client_tag): if (client_tag):
if (screen_y > self.caption_y and if (screen_y > self.caption_y and
screen_x > self.caption_x + len(msg_client)): screen_x > self.caption_x + len(msg_client)):
self.term_window.addnstr(max(self.caption_y, screen_y - 1), self.term_window.addnstr(max(self.caption_y, screen_y - 1),
self.caption_x, msg_client, len(msg_client), self.caption_x, msg_client, len(msg_client),
self.title_color if self.hascolors else msg_client_style)
curses.A_UNDERLINE)
if (screen_x > self.caption_x + len(msg_client)+3+len(msg_help)): if (screen_x > self.caption_x + len(msg_client)+3+len(msg_help)):
self.term_window.addnstr(max(self.caption_y, screen_y - 1), self.term_window.addnstr(max(self.caption_y, screen_y - 1),
self.caption_x+len(msg_client), " | "+msg_help, 3+len(msg_help)) self.caption_x+len(msg_client), " | "+msg_help, 3+len(msg_help))
@ -2229,7 +2264,7 @@ class GlancesClient():
try: try:
client_version = self.client.init()[:3] client_version = self.client.init()[:3]
except: except:
print _("Error: Init / Connection to server failed") print _("Error: Connection to server failed")
sys.exit(-1) sys.exit(-1)
else: else:
return __version__[:3] == client_version return __version__[:3] == client_version
@ -2613,10 +2648,15 @@ if __name__ == "__main__":
# Start the client (CLI) loop # Start the client (CLI) loop
while True: while True:
# Get server system informations # Get server system informations
stats.update(client.client_get()) server_stats = client.client_get()
if server_stats == {}:
server_status = "Disconnected"
else:
server_status = "Connected"
stats.update(server_stats)
# Update the screen # Update the screen
screen.update(stats) screen.update(stats, cs_status = server_status)
else: else:
# Start the standalone (CLI) loop # Start the standalone (CLI) loop
while True: while True: