<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[12895] CalendarServer/trunk/calendarserver/tools/dashboard.py</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.calendarserver.org//changeset/12895">12895</a></dd>
<dt>Author</dt> <dd>wsanchez@apple.com</dd>
<dt>Date</dt> <dd>2014-03-13 12:13:36 -0700 (Thu, 13 Mar 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>lint</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunkcalendarservertoolsdashboardpy">CalendarServer/trunk/calendarserver/tools/dashboard.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunkcalendarservertoolsdashboardpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/calendarserver/tools/dashboard.py (12894 => 12895)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/calendarserver/tools/dashboard.py        2014-03-13 18:59:21 UTC (rev 12894)
+++ CalendarServer/trunk/calendarserver/tools/dashboard.py        2014-03-13 19:13:36 UTC (rev 12895)
</span><span class="lines">@@ -15,8 +15,8 @@
</span><span class="cx"> ##
</span><span class="cx"> 
</span><span class="cx"> &quot;&quot;&quot;
</span><del>-A curses (or plain text) based dashboard for viewing various aspects of the server as exposed by
-the L{DashboardProtocol} stats socket.
</del><ins>+A curses (or plain text) based dashboard for viewing various aspects of the
+server as exposed by the L{DashboardProtocol} stats socket.
</ins><span class="cx"> &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx"> from getopt import getopt, GetoptError
</span><span class="lines">@@ -30,8 +30,9 @@
</span><span class="cx"> import socket
</span><span class="cx"> import errno
</span><span class="cx"> 
</span><ins>+
+
</ins><span class="cx"> def usage(e=None):
</span><del>-
</del><span class="cx">     name = os.path.basename(sys.argv[0])
</span><span class="cx">     print(&quot;usage: %s [options]&quot; % (name,))
</span><span class="cx">     print(&quot;&quot;)
</span><span class="lines">@@ -50,8 +51,8 @@
</span><span class="cx"> 
</span><span class="cx"> BOX_WIDTH = 52
</span><span class="cx"> 
</span><ins>+
</ins><span class="cx"> def main():
</span><del>-
</del><span class="cx">     try:
</span><span class="cx">         (optargs, _ignore_args) = getopt(
</span><span class="cx">             sys.argv[1:], &quot;ht&quot;, [
</span><span class="lines">@@ -91,7 +92,8 @@
</span><span class="cx"> 
</span><span class="cx"> class Dashboard(object):
</span><span class="cx">     &quot;&quot;&quot;
</span><del>-    Main dashboard controller. Use Python's L{sched} feature to schedule updates.
</del><ins>+    Main dashboard controller. Use Python's L{sched} feature to schedule
+    updates.
</ins><span class="cx">     &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx">     screen = None
</span><span class="lines">@@ -108,9 +110,10 @@
</span><span class="cx">     @classmethod
</span><span class="cx">     def registerWindow(cls, wtype, keypress):
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        Register a window type along with a key press action. This allows the controller to
-        select the appropriate window when its key is pressed, and also provides help information
-        to the L{HelpWindow} for each available window type.
</del><ins>+        Register a window type along with a key press action. This allows the
+        controller to select the appropriate window when its key is pressed,
+        and also provides help information to the L{HelpWindow} for each
+        available window type.
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         cls.registered_windows[keypress] = wtype
</span><span class="cx"> 
</span><span class="lines">@@ -139,7 +142,9 @@
</span><span class="cx">             self.windows[-1].update()
</span><span class="cx">         else:
</span><span class="cx">             top = 0
</span><del>-            for wtype in filter(lambda x: x.all, self.registered_windows.values()):
</del><ins>+            for wtype in filter(
+                lambda x: x.all, self.registered_windows.values()
+            ):
</ins><span class="cx">                 self.windows.append(wtype(self.usesCurses).makeWindow(top=top))
</span><span class="cx">                 self.windows[-1].update()
</span><span class="cx">                 top += self.windows[-1].nlines
</span><span class="lines">@@ -151,7 +156,9 @@
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         try:
</span><span class="cx">             if not self.paused:
</span><del>-                for window in filter(lambda x: x.requiresUpdate(), self.windows):
</del><ins>+                for window in filter(
+                    lambda x: x.requiresUpdate(), self.windows
+                ):
</ins><span class="cx">                     window.update()
</span><span class="cx">         except Exception as e:
</span><span class="cx">             print(str(e))
</span><span class="lines">@@ -195,7 +202,9 @@
</span><span class="cx">         raise NotImplementedError
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def _createWindow(self, title, nlines, ncols=BOX_WIDTH, begin_y=0, begin_x=0):
</del><ins>+    def _createWindow(
+        self, title, nlines, ncols=BOX_WIDTH, begin_y=0, begin_x=0
+    ):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Initialize a curses window based on the sizes required.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="lines">@@ -213,8 +222,9 @@
</span><span class="cx"> 
</span><span class="cx">     def requiresUpdate(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        Indicates whether a window type has dynamic data that should be refreshed on each update,
-        or whether it is static data (e.g., L{HelpWindow}) that only needs to be drawn once.
</del><ins>+        Indicates whether a window type has dynamic data that should be
+        refreshed on each update, or whether it is static data (e.g.,
+        L{HelpWindow}) that only needs to be drawn once.
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         return True
</span><span class="cx"> 
</span><span class="lines">@@ -250,11 +260,17 @@
</span><span class="cx"> 
</span><span class="cx">     def readSock(self, item):
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        Open a socket, send the specified request, and retrieve the response. Keep the socket open.
</del><ins>+        Open a socket, send the specified request, and retrieve the response.
+        Keep the socket open.
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         try:
</span><span class="cx">             if self.socket is None:
</span><del>-                self.socket = socket.socket(socket.AF_INET if self.useTCP else socket.AF_UNIX, socket.SOCK_STREAM)
</del><ins>+                if self.useTCP:
+                    self.socket = socket.socket(socket.AF_INET)
+                else:
+                    self.socket = socket.socket(
+                        socket.AF_UNIX, socket.SOCK_STREAM
+                    )
</ins><span class="cx">                 self.socket.connect(self.sockname)
</span><span class="cx">                 self.socket.setblocking(0)
</span><span class="cx">             self.socket.sendall(json.dumps([item]) + &quot;\r\n&quot;)
</span><span class="lines">@@ -272,7 +288,10 @@
</span><span class="cx">                     break
</span><span class="cx">             data = json.loads(data)[item]
</span><span class="cx">         except socket.error as e:
</span><del>-            data = {&quot;Failed&quot;: &quot;Unable to read statistics from server: %s %s&quot; % (self.sockname, e)}
</del><ins>+            data = {
+                &quot;Failed&quot;: &quot;Unable to read statistics from server: {} {}&quot;
+                .format(self.sockname, e)
+            }
</ins><span class="cx">             self.socket = None
</span><span class="cx">         return data
</span><span class="cx"> 
</span><span class="lines">@@ -299,7 +318,11 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def makeWindow(self, top=0, left=0):
</span><del>-        self._createWindow(&quot;Help&quot;, len(self.help) + len(Dashboard.registered_windows) + 2, begin_y=top, begin_x=left)
</del><ins>+        self._createWindow(
+            &quot;Help&quot;,
+            len(self.help) + len(Dashboard.registered_windows) + 2,
+            begin_y=top, begin_x=left
+        )
</ins><span class="cx">         return self
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -318,7 +341,9 @@
</span><span class="cx">         y = 1
</span><span class="cx"> 
</span><span class="cx">         items = []
</span><del>-        for keypress, wtype in sorted(Dashboard.registered_windows.items(), key=lambda x: x[0]):
</del><ins>+        for keypress, wtype in sorted(
+            Dashboard.registered_windows.items(), key=lambda x: x[0]
+        ):
</ins><span class="cx">             items.append(&quot;{} - {}&quot;.format(keypress, wtype.help))
</span><span class="cx">         items.extend(self.help)
</span><span class="cx">         for item in items:
</span><span class="lines">@@ -353,7 +378,10 @@
</span><span class="cx">         if self.usesCurses:
</span><span class="cx">             self.window.erase()
</span><span class="cx">             self.window.border()
</span><del>-            self.window.addstr(0, 2, self.title + &quot; {} ({})&quot;.format(len(records), self.iter,))
</del><ins>+            self.window.addstr(
+                0, 2,
+                self.title + &quot; {} ({})&quot;.format(len(records), self.iter)
+            )
</ins><span class="cx"> 
</span><span class="cx">         x = 1
</span><span class="cx">         y = 1
</span><span class="lines">@@ -364,11 +392,21 @@
</span><span class="cx">             print(s)
</span><span class="cx">         y += 1
</span><span class="cx">         for work_type, count in sorted(records.items(), key=lambda x: x[0]):
</span><del>-            changed = work_type in self.lastResult and self.lastResult[work_type] != count
-            s = &quot;{}{:&lt;40}{:&gt;8} &quot;.format(&quot;&gt;&quot; if count else &quot; &quot;, work_type, count)
</del><ins>+            changed = (
+                work_type in self.lastResult and
+                self.lastResult[work_type] != count
+            )
+            s = &quot;{}{:&lt;40}{:&gt;8} &quot;.format(
+                &quot;&gt;&quot; if count else &quot; &quot;, work_type, count
+            )
</ins><span class="cx">             try:
</span><span class="cx">                 if self.usesCurses:
</span><del>-                    self.window.addstr(y, x, s, curses.A_REVERSE if changed else (curses.A_BOLD if count else curses.A_NORMAL))
</del><ins>+                    self.window.addstr(
+                        y, x, s,
+                        curses.A_REVERSE if changed else (
+                            curses.A_BOLD if count else curses.A_NORMAL
+                        )
+                    )
</ins><span class="cx">                 else:
</span><span class="cx">                     print(s)
</span><span class="cx">             except curses.error:
</span><span class="lines">@@ -401,7 +439,10 @@
</span><span class="cx"> 
</span><span class="cx">     def makeWindow(self, top=0, left=0):
</span><span class="cx">         slots = self.readSock(&quot;slots&quot;)[&quot;slots&quot;]
</span><del>-        self._createWindow(&quot;Slots&quot;, len(slots) + 5, self.FORMAT_WIDTH, begin_y=top, begin_x=left)
</del><ins>+        self._createWindow(
+            &quot;Slots&quot;, len(slots) + 5, self.FORMAT_WIDTH,
+            begin_y=top, begin_x=left
+        )
</ins><span class="cx">         return self
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -413,18 +454,27 @@
</span><span class="cx">         if self.usesCurses:
</span><span class="cx">             self.window.erase()
</span><span class="cx">             self.window.border()
</span><del>-            self.window.addstr(0, 2, self.title + &quot; {} ({})&quot;.format(len(records), self.iter,))
</del><ins>+            self.window.addstr(
+                0, 2,
+                self.title + &quot; {} ({})&quot;.format(len(records), self.iter)
+            )
</ins><span class="cx"> 
</span><span class="cx">         x = 1
</span><span class="cx">         y = 1
</span><del>-        s = &quot; {:&gt;4}{:&gt;8}{:&gt;8}{:&gt;8}{:&gt;8}{:&gt;8}{:&gt;8}{:&gt;8}{:&gt;8} &quot;.format(&quot;Slot&quot;, &quot;unack&quot;, &quot;ack&quot;, &quot;uncls&quot;, &quot;total&quot;, &quot;start&quot;, &quot;strting&quot;, &quot;stopped&quot;, &quot;abd&quot;)
</del><ins>+        s = &quot; {:&gt;4}{:&gt;8}{:&gt;8}{:&gt;8}{:&gt;8}{:&gt;8}{:&gt;8}{:&gt;8}{:&gt;8} &quot;.format(
+            &quot;Slot&quot;, &quot;unack&quot;, &quot;ack&quot;, &quot;uncls&quot;, &quot;total&quot;,
+            &quot;start&quot;, &quot;strting&quot;, &quot;stopped&quot;, &quot;abd&quot;
+        )
</ins><span class="cx">         if self.usesCurses:
</span><span class="cx">             self.window.addstr(y, x, s, curses.A_REVERSE)
</span><span class="cx">         else:
</span><span class="cx">             print(s)
</span><span class="cx">         y += 1
</span><span class="cx">         for record in sorted(records, key=lambda x: x[&quot;slot&quot;]):
</span><del>-            changed = record[&quot;slot&quot;] in self.lastResult and self.lastResult[record[&quot;slot&quot;]] != record
</del><ins>+            changed = (
+                record[&quot;slot&quot;] in self.lastResult and
+                self.lastResult[record[&quot;slot&quot;]] != record
+            )
</ins><span class="cx">             s = &quot; {:&gt;4}{:&gt;8}{:&gt;8}{:&gt;8}{:&gt;8}{:&gt;8}{:&gt;8}{:&gt;8}{:&gt;8} &quot;.format(
</span><span class="cx">                 record[&quot;slot&quot;],
</span><span class="cx">                 record[&quot;unacknowledged&quot;],
</span><span class="lines">@@ -439,7 +489,12 @@
</span><span class="cx">             try:
</span><span class="cx">                 count = record[&quot;unacknowledged&quot;] + record[&quot;acknowledged&quot;]
</span><span class="cx">                 if self.usesCurses:
</span><del>-                    self.window.addstr(y, x, s, curses.A_REVERSE if changed else (curses.A_BOLD if count else curses.A_NORMAL))
</del><ins>+                    self.window.addstr(
+                        y, x, s,
+                        curses.A_REVERSE if changed else (
+                            curses.A_BOLD if count else curses.A_NORMAL
+                        )
+                    )
</ins><span class="cx">                 else:
</span><span class="cx">                     print(s)
</span><span class="cx">             except curses.error:
</span><span class="lines">@@ -448,7 +503,10 @@
</span><span class="cx"> 
</span><span class="cx">         s = &quot; {:&lt;12}{:&gt;8}{:&gt;16}&quot;.format(
</span><span class="cx">             &quot;Total:&quot;,
</span><del>-            sum([record[&quot;unacknowledged&quot;] + record[&quot;acknowledged&quot;] for record in records]),
</del><ins>+            sum([
+                record[&quot;unacknowledged&quot;] + record[&quot;acknowledged&quot;]
+                for record in records
+            ]),
</ins><span class="cx">             sum([record[&quot;total&quot;] for record in records]),
</span><span class="cx">         )
</span><span class="cx">         if self.usesCurses:
</span><span class="lines">@@ -457,7 +515,10 @@
</span><span class="cx">             self.window.addstr(y, x, s)
</span><span class="cx">             x += len(s) + 4
</span><span class="cx">             s = &quot;{:&gt;10}&quot;.format(&quot;OVERLOADED&quot; if data[&quot;overloaded&quot;] else &quot;&quot;)
</span><del>-            self.window.addstr(y, x, s, curses.A_REVERSE if data[&quot;overloaded&quot;] else curses.A_NORMAL)
</del><ins>+            self.window.addstr(
+                y, x, s,
+                curses.A_REVERSE if data[&quot;overloaded&quot;] else curses.A_NORMAL
+            )
</ins><span class="cx">         else:
</span><span class="cx">             if data[&quot;overloaded&quot;]:
</span><span class="cx">                 s += &quot;    OVERLOADED&quot;
</span><span class="lines">@@ -491,7 +552,10 @@
</span><span class="cx">         if self.usesCurses:
</span><span class="cx">             self.window.erase()
</span><span class="cx">             self.window.border()
</span><del>-            self.window.addstr(0, 2, self.title + &quot; {} ({})&quot;.format(len(records), self.iter,))
</del><ins>+            self.window.addstr(
+                0, 2,
+                self.title + &quot; {} ({})&quot;.format(len(records), self.iter)
+            )
</ins><span class="cx"> 
</span><span class="cx">         x = 1
</span><span class="cx">         y = 1
</span><span class="lines">@@ -504,18 +568,25 @@
</span><span class="cx"> 
</span><span class="cx">         records[&quot;cpu use&quot;] = &quot;{:.2f}&quot;.format(records[&quot;cpu use&quot;])
</span><span class="cx">         records[&quot;memory percent&quot;] = &quot;{:.1f}&quot;.format(records[&quot;memory percent&quot;])
</span><del>-        records[&quot;memory used&quot;] = &quot;{:.2f} GB&quot;.format(records[&quot;memory used&quot;] / (1000.0 * 1000.0 * 1000.0))
</del><ins>+        records[&quot;memory used&quot;] = &quot;{:.2f} GB&quot;.format(
+            records[&quot;memory used&quot;] / (1000.0 * 1000.0 * 1000.0)
+        )
</ins><span class="cx">         records[&quot;uptime&quot;] = int(time.time() - records[&quot;start time&quot;])
</span><span class="cx">         hours, mins = divmod(records[&quot;uptime&quot;] / 60, 60)
</span><span class="cx">         records[&quot;uptime&quot;] = &quot;{}:{:02d} hours&quot;.format(hours, mins)
</span><span class="cx">         del records[&quot;start time&quot;]
</span><span class="cx"> 
</span><span class="cx">         for item, value in sorted(records.items(), key=lambda x: x[0]):
</span><del>-            changed = item in self.lastResult and self.lastResult[item] != value
</del><ins>+            changed = (
+                item in self.lastResult and self.lastResult[item] != value
+            )
</ins><span class="cx">             s = &quot; {:&lt;30}{:&gt;18} &quot;.format(item, value)
</span><span class="cx">             try:
</span><span class="cx">                 if self.usesCurses:
</span><del>-                    self.window.addstr(y, x, s, curses.A_REVERSE if changed else curses.A_NORMAL)
</del><ins>+                    self.window.addstr(
+                        y, x, s,
+                        curses.A_REVERSE if changed else curses.A_NORMAL
+                    )
</ins><span class="cx">                 else:
</span><span class="cx">                     print(s)
</span><span class="cx">             except curses.error:
</span></span></pre>
</div>
</div>

</body>
</html>