[CalendarServer-changes] [14102] CalendarServer/trunk/calendarserver/tools/dashboard.py
source_changes at macosforge.org
source_changes at macosforge.org
Fri Oct 24 10:34:33 PDT 2014
Revision: 14102
http://trac.calendarserver.org//changeset/14102
Author: dre at apple.com
Date: 2014-10-24 10:34:33 -0700 (Fri, 24 Oct 2014)
Log Message:
-----------
Add ability to toggle panels individually. Float the help panel on the top right. Show the help panel at start time if it would fit. Add a 'no windows' hotkey (n) to clear everything but the help panel.
Modified Paths:
--------------
CalendarServer/trunk/calendarserver/tools/dashboard.py
Modified: CalendarServer/trunk/calendarserver/tools/dashboard.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/dashboard.py 2014-10-23 22:41:05 UTC (rev 14101)
+++ CalendarServer/trunk/calendarserver/tools/dashboard.py 2014-10-24 17:34:33 UTC (rev 14102)
@@ -22,6 +22,7 @@
from getopt import getopt, GetoptError
import curses
+import curses.panel
import json
import os
import sched
@@ -29,6 +30,9 @@
import time
import socket
import errno
+import logging
+LOG_FILENAME = 'db.log'
+#logging.basicConfig(filename=LOG_FILENAME,level=logging.DEBUG)
@@ -152,27 +156,55 @@
self.sched.enter(self.seconds, 0, self.updateDisplay, ())
self.sched.run()
+ def terminal_size(self):
+ import fcntl, termios, struct
+ h, w, hp, wp = struct.unpack('HHHH',
+ fcntl.ioctl(0, termios.TIOCGWINSZ,
+ struct.pack('HHHH', 0, 0, 0, 0)))
+ return w, h
def displayWindow(self, wtype):
"""
- Display a new window type, clearing out the old one first.
+ Toggle the specified window, or reset to launch state if None.
"""
- if self.windows:
- for window in self.windows:
- window.deactivate()
- self.windows = []
+ # Toggle a specific window on or off
if wtype is not None:
- self.windows.append(wtype(self.usesCurses, self.client).makeWindow())
- self.windows[-1].activate()
+ if wtype not in [type(w) for w in self.windows]:
+ self.windows.append(wtype(self.usesCurses, self.client).makeWindow())
+ self.windows[-1].activate()
+ else:
+ for window in self.windows:
+ if type(window) == wtype:
+ window.deactivate()
+ self.windows.remove(window)
+ if len(self.windows) == 0:
+ self.displayWindow(self.registered_windows["h"])
+
+ self.resetWindows()
+ # Reset the screen to the default config
else:
+ if self.windows:
+ for window in self.windows:
+ window.deactivate()
+ self.windows = []
top = 0
ordered_windows = [self.registered_windows[i] for i in self.registered_order]
for wtype in filter(lambda x: x.all, ordered_windows):
+ new_win = wtype(self.usesCurses, self.client).makeWindow(top=top)
+ logging.debug('created %r at panel level %r' % (new_win,new_win.z_order))
self.windows.append(wtype(self.usesCurses, self.client).makeWindow(top=top))
self.windows[-1].activate()
top += self.windows[-1].nlines + 1
+ # Don't display help panel if the window is too narrow
+ term_w, term_h = self.terminal_size()
+ logging.debug("logger displayWindow: rows: %s cols: %s" % (term_h, term_w))
+ if int(term_w) > 100:
+ logging.debug('term_w > 100, making window with top at %d' % (top))
+ self.windows.append(HelpWindow(self.usesCurses, self.client).makeWindow(top=top))
+ self.windows[-1].activate()
+ curses.panel.update_panels()
self.updateDisplay(True)
@@ -181,15 +213,19 @@
Reset the current set of windows.
"""
if self.windows:
+ logging.debug('resetting windows: %r' % (self.windows))
for window in self.windows:
window.deactivate()
old_windows = self.windows
self.windows = []
top = 0
for old in old_windows:
+ logging.debug('processing window of type %r' % (type(old)))
self.windows.append(old.__class__(self.usesCurses, self.client).makeWindow(top=top))
self.windows[-1].activate()
- top += self.windows[-1].nlines + 1
+ # Allow the help window to float on the right edge
+ if old.__class__.__name__ != "HelpWindow":
+ top += self.windows[-1].nlines + 1
def updateDisplay(self, initialUpdate=False):
@@ -231,6 +267,12 @@
self.seconds = 1.0 if self.seconds == 0.1 else 0.1
elif c == "a":
self.displayWindow(None)
+ elif c == "n":
+ if self.windows:
+ for window in self.windows:
+ window.deactivate()
+ self.windows = []
+ self.displayWindow(self.registered_windows["h"])
elif c in self.registered_windows:
self.displayWindow(self.registered_windows[c])
@@ -331,8 +373,17 @@
self.client = client
self.rowCount = 0
self.needsReset = False
+ self.z_order = 'bottom'
+ def terminal_size(self):
+ import fcntl, termios, struct
+ h, w, hp, wp = struct.unpack('HHHH',
+ fcntl.ioctl(0, termios.TIOCGWINSZ,
+ struct.pack('HHHH', 0, 0, 0, 0)))
+ return w, h
+
+
def makeWindow(self, top=0, left=0):
raise NotImplementedError()
@@ -346,6 +397,8 @@
if self.usesCurses:
self.window = curses.newwin(nlines, ncols, begin_y, begin_x)
self.window.nodelay(1)
+ self.panel = curses.panel.new_panel(self.window)
+ eval("self.panel.%s()" % (self.z_order,))
else:
self.window = None
self.title = title
@@ -412,11 +465,12 @@
Display help for the dashboard.
"""
- help = "display dashboard help"
+ help = "dashboard help"
all = False
helpItems = (
"",
"a - all windows",
+ "n - no windows",
" - (space) pause dashboard polling",
"t - toggle update between 0.1 and 1.0 seconds",
"",
@@ -424,10 +478,14 @@
)
def makeWindow(self, top=0, left=0):
+ term_w, term_h = self.terminal_size()
+ help_x_offset = term_w - BOX_WIDTH + 4
self._createWindow(
"Help",
len(self.helpItems) + len(Dashboard.registered_windows) + 2,
- begin_y=top, begin_x=left
+ ncols=BOX_WIDTH-4,
+ begin_y=0,
+ begin_x=help_x_offset,
)
return self
@@ -441,7 +499,7 @@
if self.usesCurses:
self.window.erase()
self.window.border()
- self.window.addstr(0, 2, "Help for Dashboard")
+ self.window.addstr(0, 2, "Hotkeys")
x = 1
y = 1
@@ -469,7 +527,7 @@
Display the status of the server's job queue.
"""
- help = "display server jobs"
+ help = "server jobs"
clientItem = "jobs"
FORMAT_WIDTH = 98
@@ -580,7 +638,7 @@
Displays the status of the server's master process worker slave slots.
"""
- help = "display server child job assignments"
+ help = "server child job assignments"
clientItem = "job_assignments"
FORMAT_WIDTH = 40
@@ -674,7 +732,7 @@
Displays the status of the server's master process worker slave slots.
"""
- help = "display server child slots"
+ help = "server child slots"
clientItem = "slots"
FORMAT_WIDTH = 72
@@ -784,7 +842,7 @@
Displays the system information provided by the server.
"""
- help = "display system details"
+ help = "system details"
clientItem = "stats_system"
def makeWindow(self, top=0, left=0):
@@ -862,7 +920,7 @@
Displays the status of the server's master process worker slave slots.
"""
- help = "display server request stats"
+ help = "server request stats"
clientItem = "stats"
FORMAT_WIDTH = 84
@@ -937,7 +995,7 @@
Displays the status of the server's directory service calls
"""
- help = "display directory service stats"
+ help = "directory service stats"
clientItem = "directory"
FORMAT_WIDTH = 89
@@ -1051,13 +1109,13 @@
+Dashboard.registerWindow(HelpWindow, "h")
Dashboard.registerWindow(SystemWindow, "s")
+Dashboard.registerWindow(AssignmentsWindow, "w")
Dashboard.registerWindow(RequestStatsWindow, "r")
Dashboard.registerWindow(JobsWindow, "j")
-Dashboard.registerWindow(AssignmentsWindow, "w")
Dashboard.registerWindow(HTTPSlotsWindow, "c")
Dashboard.registerWindow(DirectoryStatsWindow, "d")
-Dashboard.registerWindow(HelpWindow, "h")
if __name__ == "__main__":
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20141024/89d3cde9/attachment-0001.html>
More information about the calendarserver-changes
mailing list