You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by rh...@apache.org on 2009/06/02 19:28:12 UTC

svn commit: r781087 - /qpid/trunk/qpid/python/qpid-python-test

Author: rhs
Date: Tue Jun  2 17:28:12 2009
New Revision: 781087

URL: http://svn.apache.org/viewvc?rev=781087&view=rev
Log:
detect the terminal width when possible

Modified:
    qpid/trunk/qpid/python/qpid-python-test

Modified: qpid/trunk/qpid/python/qpid-python-test
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/python/qpid-python-test?rev=781087&r1=781086&r2=781087&view=diff
==============================================================================
--- qpid/trunk/qpid/python/qpid-python-test (original)
+++ qpid/trunk/qpid/python/qpid-python-test Tue Jun  2 17:28:12 2009
@@ -18,7 +18,7 @@
 # under the License.
 #
 
-import optparse, os, sys, logging, traceback, types
+import fcntl, logging, optparse, os, struct, sys, termios, traceback, types
 from fnmatch import fnmatchcase as match
 from getopt import GetoptError
 from logging import getLogger, StreamHandler, Formatter, Filter, \
@@ -98,6 +98,18 @@
       return True
   return False
 
+def width():
+  if sys.stdout.isatty():
+    s = struct.pack("HHHH", 0, 0, 0, 0)
+    fd_stdout = sys.stdout.fileno()
+    x = fcntl.ioctl(fd_stdout, termios.TIOCGWINSZ, s)
+    rows, cols, xpx, ypx = struct.unpack("HHHH", x)
+    return cols
+  else:
+    return 80
+
+WIDTH = width()
+
 def vt100_attrs(*attrs):
   return "\x1B[%sm" % ";".join(map(str, attrs))
 
@@ -156,6 +168,9 @@
     self.stream = stream
     self.prefix = prefix
 
+  def fileno(self):
+    return self.stream.fileno()
+
   def isatty(self):
     return self.stream.isatty()
 
@@ -251,6 +266,8 @@
       print "Error during %s:" % name
       print indent("".join(traceback.format_exception(*info))).rstrip()
 
+ST_WIDTH = 8
+
 def run_test(name, test, config):
   patterns = filter.patterns
   level = root.level
@@ -262,7 +279,7 @@
   output = ""
   for part in parts:
     if line:
-      if len(line) + len(part) >= 71:
+      if len(line) + len(part) >= (WIDTH - ST_WIDTH - 1):
         output += "%s. \\\n" % line
         line = "    %s" % part
       else:
@@ -271,7 +288,7 @@
       line = part
 
   if line:
-    output += "%s %s" % (line, ((72 - len(line))*"."))
+    output += "%s %s" % (line, (((WIDTH - ST_WIDTH) - len(line))*"."))
   sys.stdout.write(output)
   sys.stdout.flush()
   interceptor.begin()



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org