Title: [132423] trunk/Tools
Revision
132423
Author
[email protected]
Date
2012-10-24 16:46:23 -0700 (Wed, 24 Oct 2012)

Log Message

nrwt: truncate meter lines properly on windows
https://bugs.webkit.org/show_bug.cgi?id=100062

Reviewed by Tony Chang.

This change adds the code to figure out the terminal width
on windows (it was already there for Unixen) and moves it
to a platform-specific object.

* Scripts/webkitpy/common/system/platforminfo.py:
(PlatformInfo.terminal_width):
* Scripts/webkitpy/common/system/platforminfo_mock.py:
(MockPlatformInfo.total_bytes_memory):
(MockPlatformInfo):
(MockPlatformInfo.terminal_width):
* Scripts/webkitpy/layout_tests/views/metered_stream.py:
(MeteredStream.__init__):
(MeteredStream.number_of_columns):
(MeteredStream.flush):
* Scripts/webkitpy/layout_tests/views/printing.py:
(Printer.__init__):
(Printer._test_status_line):

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (132422 => 132423)


--- trunk/Tools/ChangeLog	2012-10-24 23:40:28 UTC (rev 132422)
+++ trunk/Tools/ChangeLog	2012-10-24 23:46:23 UTC (rev 132423)
@@ -1,5 +1,30 @@
 2012-10-24  Dirk Pranke  <[email protected]>
 
+        nrwt: truncate meter lines properly on windows
+        https://bugs.webkit.org/show_bug.cgi?id=100062
+
+        Reviewed by Tony Chang.
+
+        This change adds the code to figure out the terminal width
+        on windows (it was already there for Unixen) and moves it
+        to a platform-specific object.
+
+        * Scripts/webkitpy/common/system/platforminfo.py:
+        (PlatformInfo.terminal_width):
+        * Scripts/webkitpy/common/system/platforminfo_mock.py:
+        (MockPlatformInfo.total_bytes_memory):
+        (MockPlatformInfo):
+        (MockPlatformInfo.terminal_width):
+        * Scripts/webkitpy/layout_tests/views/metered_stream.py:
+        (MeteredStream.__init__):
+        (MeteredStream.number_of_columns):
+        (MeteredStream.flush):
+        * Scripts/webkitpy/layout_tests/views/printing.py:
+        (Printer.__init__):
+        (Printer._test_status_line):
+
+2012-10-24  Dirk Pranke  <[email protected]>
+
         tweak debug logging in webkit-patch optimize-baselines
         https://bugs.webkit.org/show_bug.cgi?id=100294
 

Modified: trunk/Tools/Scripts/webkitpy/common/system/platforminfo.py (132422 => 132423)


--- trunk/Tools/Scripts/webkitpy/common/system/platforminfo.py	2012-10-24 23:40:28 UTC (rev 132422)
+++ trunk/Tools/Scripts/webkitpy/common/system/platforminfo.py	2012-10-24 23:46:23 UTC (rev 132423)
@@ -27,6 +27,7 @@
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 import re
+import sys
 
 
 class PlatformInfo(object):
@@ -86,6 +87,31 @@
             return long(self._executive.run_command(["sysctl", "-n", "hw.memsize"]))
         return None
 
+    def terminal_width(self):
+        """Returns sys.maxint if the width cannot be determined."""
+        try:
+            if self.is_win():
+                # From http://code.activestate.com/recipes/440694-determine-size-of-console-window-on-windows/
+                from ctypes import windll, create_string_buffer
+                handle = windll.kernel32.GetStdHandle(-12)  # -12 == stderr
+                console_screen_buffer_info = create_string_buffer(22)  # 22 == sizeof(console_screen_buffer_info)
+                if windll.kernel32.GetConsoleScreenBufferInfo(handle, console_screen_buffer_info):
+                    import struct
+                    _, _, _, _, _, left, _, right, _, _, _ = struct.unpack("hhhhHhhhhhh", console_screen_buffer_info.raw)
+                    # Note that we return 1 less than the width since writing into the rightmost column
+                    # automatically performs a line feed.
+                    return right - left
+                return sys.maxint
+            else:
+                import fcntl
+                import struct
+                import termios
+                packed = fcntl.ioctl(sys.stderr.fileno(), termios.TIOCGWINSZ, '\0' * 8)
+                _, columns, _, _ = struct.unpack('HHHH', packed)
+                return columns
+        except:
+            return sys.maxint
+
     def _determine_os_name(self, sys_platform):
         if sys_platform == 'darwin':
             return 'mac'

Modified: trunk/Tools/Scripts/webkitpy/common/system/platforminfo_mock.py (132422 => 132423)


--- trunk/Tools/Scripts/webkitpy/common/system/platforminfo_mock.py	2012-10-24 23:40:28 UTC (rev 132422)
+++ trunk/Tools/Scripts/webkitpy/common/system/platforminfo_mock.py	2012-10-24 23:46:23 UTC (rev 132423)
@@ -52,3 +52,6 @@
 
     def total_bytes_memory(self):
         return 3 * 1024 * 1024 * 1024  # 3GB is a reasonable amount of ram to mock.
+
+    def terminal_width(self):
+        return 80

Modified: trunk/Tools/Scripts/webkitpy/common/system/platforminfo_unittest.py (132422 => 132423)


--- trunk/Tools/Scripts/webkitpy/common/system/platforminfo_unittest.py	2012-10-24 23:40:28 UTC (rev 132422)
+++ trunk/Tools/Scripts/webkitpy/common/system/platforminfo_unittest.py	2012-10-24 23:46:23 UTC (rev 132423)
@@ -79,6 +79,7 @@
         self.assertNotEquals(info.os_version, '')
         self.assertNotEquals(info.display_name(), '')
         self.assertTrue(info.is_mac() or info.is_win() or info.is_linux() or info.is_freebsd())
+        self.assertNotEquals(info.terminal_width(), None)
 
         if info.is_mac():
             self.assertTrue(info.total_bytes_memory() > 0)

Modified: trunk/Tools/Scripts/webkitpy/layout_tests/views/metered_stream.py (132422 => 132423)


--- trunk/Tools/Scripts/webkitpy/layout_tests/views/metered_stream.py	2012-10-24 23:40:28 UTC (rev 132422)
+++ trunk/Tools/Scripts/webkitpy/layout_tests/views/metered_stream.py	2012-10-24 23:46:23 UTC (rev 132423)
@@ -32,9 +32,6 @@
 import sys
 import time
 
-from webkitpy.common.memoized import memoized
-
-
 LOG_HANDLER_NAME = 'MeteredStreamLogHandler'
 
 
@@ -55,7 +52,7 @@
     def _ensure_newline(txt):
         return txt if txt.endswith('\n') else txt + '\n'
 
-    def __init__(self, stream=None, verbose=False, logger=None, time_fn=None, pid=None):
+    def __init__(self, stream=None, verbose=False, logger=None, time_fn=None, pid=None, number_of_columns=None):
         self._stream = stream or sys.stderr
         self._verbose = verbose
         self._time_fn = time_fn or time.time
@@ -65,6 +62,9 @@
         self._last_partial_line = ''
         self._last_write_time = 0.0
         self._throttle_delay_in_secs = 0.066 if self._erasing else 10.0
+        self._number_of_columns = sys.maxint
+        if self._isatty and number_of_columns:
+            self._number_of_columns = number_of_columns
 
         self._logger = logger
         self._log_handler = None
@@ -122,19 +122,8 @@
             self._last_partial_line = ''
             self._stream.flush()
 
-    @memoized
     def number_of_columns(self):
-        if not self._isatty:
-            return sys.maxint
-        try:
-            import fcntl
-            import struct
-            import termios
-            packed = fcntl.ioctl(self._stream.fileno(), termios.TIOCGWINSZ, '\0' * 8)
-            _, columns, _, _ = struct.unpack('HHHH', packed)
-            return columns
-        except:
-            return sys.maxint
+        return self._number_of_columns
 
 
 class _LogHandler(logging.Handler):

Modified: trunk/Tools/Scripts/webkitpy/layout_tests/views/printing.py (132422 => 132423)


--- trunk/Tools/Scripts/webkitpy/layout_tests/views/printing.py	2012-10-24 23:40:28 UTC (rev 132422)
+++ trunk/Tools/Scripts/webkitpy/layout_tests/views/printing.py	2012-10-24 23:46:23 UTC (rev 132423)
@@ -73,7 +73,8 @@
         self._port = port
         self._options = options
         self._buildbot_stream = buildbot_output
-        self._meter = MeteredStream(regular_output, options.debug_rwt_logging, logger=logger)
+        self._meter = MeteredStream(regular_output, options.debug_rwt_logging, logger=logger,
+                                    number_of_columns=self._port.host.platform.terminal_width())
         self._running_tests = []
         self._completed_tests = []
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to