[CalendarServer-changes] [8446] CalendarServer/trunk/calendarserver/tools/shell.py

source_changes at macosforge.org source_changes at macosforge.org
Wed Dec 14 10:42:33 PST 2011


Revision: 8446
          http://trac.macosforge.org/projects/calendarserver/changeset/8446
Author:   wsanchez at apple.com
Date:     2011-12-14 10:42:33 -0800 (Wed, 14 Dec 2011)
Log Message:
-----------
Use tables module.

Modified Paths:
--------------
    CalendarServer/trunk/calendarserver/tools/shell.py

Modified: CalendarServer/trunk/calendarserver/tools/shell.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/shell.py	2011-12-14 04:29:59 UTC (rev 8445)
+++ CalendarServer/trunk/calendarserver/tools/shell.py	2011-12-14 18:42:33 UTC (rev 8446)
@@ -24,6 +24,7 @@
 import tty
 import termios
 from shlex import shlex
+from cStringIO import StringIO
 
 from twisted.python import log
 from twisted.python.log import startLogging
@@ -42,6 +43,7 @@
 
 from calendarserver.tools.cmdline import utilityMain
 from calendarserver.tools.util import getDirectory
+from calendarserver.tools.tables import Table
 
 
 def usage(e=None):
@@ -771,19 +773,29 @@
 
         result = []
         result.append("Calendar home for UID: %s" % (uid,))
+
+        rows = []
         if created is not None:
-            # FIXME: convert to string
-            result.append("Created: %s" % (created,))
+            # FIXME: convert to formatted string
+            rows.append(("Created", str(created)))
         if modified is not None:
-            # FIXME: convert to string
-            result.append("Last modified: %s" % (modified,))
+            # FIXME: convert to formatted string
+            rows.append(("Last modified", str(modified)))
         if quotaUsed is not None:
-            result.append("Quota: %s of %s (%.2s%%)"
-                          % (quotaUsed, quotaAllowed, quotaUsed / quotaAllowed))
+            rows.append((
+                "Quota",
+                "%s of %s (%.2s%%)"
+                % (quotaUsed, quotaAllowed, quotaUsed / quotaAllowed)
+            ))
 
+        if len(rows):
+            result.append("\nAttributes:")
+            rows[0:0] = (("Name", "Value"),)
+            result.append(tableString(rows))
+
         if properties:
-            for name in sorted(properties):
-                result.append("%s: %s" % (name, properties[name]))
+            result.append("\Properties:")
+            result.append(tableString((name, properties[name]) for name in sorted(properties)))
 
         returnValue("\n".join(result))
 
@@ -900,6 +912,20 @@
     # FIXME
 
 
+def tableString(rows):
+    if not rows:
+        return ""
+
+    table = Table()
+    table.addHeader(rows.pop(0))
+    for row in rows:
+        table.addRow(row)
+
+    output = StringIO()
+    table.printTable(os=output)
+    return output.getvalue()
+
+
 def main(argv=sys.argv, stderr=sys.stderr, reactor=None):
     if reactor is None:
         from twisted.internet import reactor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20111214/3cab1698/attachment.html>


More information about the calendarserver-changes mailing list